From: Michael Wagner Date: Mon, 22 Sep 2025 21:10:55 +0000 (+0200) Subject: Korrektur webssh executable X-Git-Tag: v_0.0-11 X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/projects.git/commitdiff_plain/9e6fd74b79b27c48bfa9ea61c4c4070abcdd0d29?ds=sidebyside Korrektur webssh executable --- diff --git a/debian/mdjango.postinst b/debian/mdjango.postinst index ff4893d..28982ba 100755 --- a/debian/mdjango.postinst +++ b/debian/mdjango.postinst @@ -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 diff --git a/debian/webssh.control b/debian/webssh.control index c51f8e2..6116697 100644 --- a/debian/webssh.control +++ b/debian/webssh.control @@ -2,9 +2,9 @@ Source: webssh Section: main Priority: optional Maintainer: Michael Wagner -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 diff --git a/debian/webssh.cp b/debian/webssh.cp index aa6c95b..8819dcd 100755 --- a/debian/webssh.cp +++ b/debian/webssh.cp @@ -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 index d3563ff..0000000 --- a/etc/webssh.service +++ /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 diff --git a/mdjango/etc/mysite.conf b/mdjango/etc/mysite.conf index 81eb48f..ee352ef 100644 --- a/mdjango/etc/mysite.conf +++ b/mdjango/etc/mysite.conf @@ -1,8 +1,15 @@ +Alias /static/ /var/mysite/static + + + Require all granted + + WSGIScriptAlias / /opt/mysite/mysite/wsgi.py #WSGIPythonHome /path/to/venv WSGIPythonPath /opt/mysite + - -Require all granted - + + Require all granted + diff --git a/webssh/webssh b/webssh/webssh new file mode 100755 index 0000000..f779a3c --- /dev/null +++ b/webssh/webssh @@ -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 index 0000000..d3563ff --- /dev/null +++ b/webssh/webssh.service @@ -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