]> wagnertech.de Git - projects.git/commitdiff
Korrektur webssh executable master v_0.0-11
authorMichael Wagner <mail@wagnertech.de>
Mon, 22 Sep 2025 21:10:55 +0000 (23:10 +0200)
committerMichael Wagner <mail@wagnertech.de>
Mon, 22 Sep 2025 21:10:55 +0000 (23:10 +0200)
debian/mdjango.postinst
debian/webssh.control
debian/webssh.cp
etc/webssh.service [deleted file]
mdjango/etc/mysite.conf
webssh/webssh [new file with mode: 0755]
webssh/webssh.service [new file with mode: 0644]

index ff4893d1ba575b89473f5f64b03057435053345e..28982ba0c59dd22f9c3c2494f4e8999a4a33fe68 100755 (executable)
@@ -11,17 +11,90 @@ then
        cat << EOF >> /opt/mysite/mysite/settings.py
 ### MDJANGO ###
 DATABASES = {
-    'default': {},
-    'tbd': {
+    'default': {
         'ENGINE': 'django.db.backends.postgresql',
-        'NAME': 'mydatabase',
-        'USER': 'myuser',
-        'PASSWORD': 'mypassword',
+        'NAME': 'mdjango',
+        'USER': 'mdjango',
+        'PASSWORD': 'MdjangO',
         'HOST': 'localhost',
         'PORT': '5432',
-    }
+    },
 }
+STATIC_ROOT = '/var/mysite/static'
 DEBUG = False
 ### MDJANGO-END ###
 EOF
 fi
+
+# check existence of /var/mysite
+if [ ! -d /var/mysite ]
+then
+       mkdir -p /var/mysite
+       chmod 777 /var/mysite
+       
+fi
+
+# collect statics
+/opt/mysite/manage.py collectstatic --noinput
+
+# check postgres user
+if ! su postgres -c "psql -c '\du'" | grep mdjango >/dev/null
+then
+       echo "No user named 'mdjango' found. It is now created."
+       su postgres -c "createuser -ds mdjango ; psql -c \"ALTER USER mdjango WITH PASSWORD 'MdjangO';\""
+fi
+main=$(ls -d /etc/postgresql/*/main/)
+if ! grep mdjango $main/pg_hba.conf >/dev/null
+then
+       echo "adding mdjango user access to $main/pg_hba.conf"
+       awk 'BEGIN {
+                       found=0; }
+               /# "local/ {
+                       if (found == 0) {
+                               print;
+                               print "local   all   mdjango   md5";
+                               found=1;
+                               next;
+                       }}
+               /^local.*all.*all/ {
+                       if (found == 0) {
+                               print "local   all   mdjango   md5";
+                               print;
+                               found=1;
+                               next;
+                       }}
+               /^host/ {
+                       if (found == 0) {
+                               print "local   all   mdjango   md5";
+                               print;
+                               found=1;
+                               next;
+                       }}
+               {print;}
+               ' $main/pg_hba.conf > /tmp/pg_hba.conf
+       mv /tmp/pg_hba.conf $main/pg_hba.conf
+       chown postgres:postgres $main/pg_hba.conf
+       systemctl reload postgresql
+fi
+
+# check mdjango database
+if ! su postgres -c "psql -c '\l'" | grep mdjango >/dev/null
+then
+       echo "Create database mdjango."
+       su postgres -c "createdb mdjango -O mdjango"
+fi
+
+# migrate default db
+/opt/mysite/manage.py migrate
+
+# check existence of superuser
+#if [ $(sqlite3 /var/mysite/default.sqlite3 'SELECT id FROM auth_user WHERE is_staff=1;' |wc -l) -eq 0 ]
+if [ $(su postgres -c "psql mdjango -c 'SELECT id FROM auth_user WHERE is_staff=1;' " |wc -l) -eq 0 ]
+then
+       echo "There is no django superuser in the system. Install one? (Y/n)"
+       read a
+       if [ "$a" != "n" ]
+       then
+               /opt/mysite/manage.py createsuperuser
+       fi
+fi
index c51f8e2d0afa96dcb24cb5f0889bd78bd2b9983c..61166970a62d597596445fb4fe74bfac83020d83 100644 (file)
@@ -2,9 +2,9 @@ Source: webssh
 Section: main
 Priority: optional
 Maintainer: Michael Wagner <michael@wagnertech.de>
-Build-Depends: git, mbuild
+Build-Depends: git, mbuild, python3-venv
  
 Package: webssh
 Architecture: all
 Depends: python3-paramiko(>=2.3.1), python3-tornado(>=4.5.0), python3-cryptography(>=3.3), python3-pycparser
-Description: WebSSH
+Description: WebSSH https://github.com/huashengdun/webssh
index aa6c95bf880a75b5e7b5f4064de5d6085a911374..8819dcd5dc0e2ddc6981ab780035013545fe3348 100755 (executable)
@@ -7,7 +7,7 @@ mkdir -p $1/usr/lib/python3.9/
 cp -a $BUILD_DIR/.venv/lib/python3.9/site-packages/webssh $1/usr/lib/python3.9/
 
 mkdir -p $1/usr/bin
-cp $BUILD_DIR/.venv/bin/wssh $1/usr/bin/webssh
+cp $BUILD_DIR/webssh/webssh $1/usr/bin/
 
 mkdir -p $1/lib/systemd/system
-cp etc/webssh.service $1/lib/systemd/system/
+cp webssh/webssh.service $1/lib/systemd/system/
diff --git a/etc/webssh.service b/etc/webssh.service
deleted file mode 100644 (file)
index d3563ff..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-[Unit]
-Description=WebSSH
-After=network.target
-
-[Service]
-ExecStart=/usr/bin/webssh
-KillMode=process
-Restart=on-failure
-RestartSec=3
-Type=simple
-
-[Install]
-WantedBy=multi-user.target
-Alias=frps.service
index 81eb48f58ff8cbe92363700a3be937d46d04c1c3..ee352ef4f13f521a13901c06183b920397d5881c 100644 (file)
@@ -1,8 +1,15 @@
+Alias /static/ /var/mysite/static
+
+<Directory /var/mysite/static>
+       Require all granted
+</Directory>
+
 WSGIScriptAlias / /opt/mysite/mysite/wsgi.py
 #WSGIPythonHome /path/to/venv
 WSGIPythonPath /opt/mysite
+
 <Directory /opt/mysite>
-<Files wsgi.py>
-Require all granted
-</Files>
+       <Files wsgi.py>
+       Require all granted
+       </Files>
 </Directory>
diff --git a/webssh/webssh b/webssh/webssh
new file mode 100755 (executable)
index 0000000..f779a3c
--- /dev/null
@@ -0,0 +1,4 @@
+#!/usr/bin/python3
+
+from webssh import main
+main.main()
diff --git a/webssh/webssh.service b/webssh/webssh.service
new file mode 100644 (file)
index 0000000..d3563ff
--- /dev/null
@@ -0,0 +1,14 @@
+[Unit]
+Description=WebSSH
+After=network.target
+
+[Service]
+ExecStart=/usr/bin/webssh
+KillMode=process
+Restart=on-failure
+RestartSec=3
+Type=simple
+
+[Install]
+WantedBy=multi-user.target
+Alias=frps.service