[Git][java-team/biglybt][master] Add biglybtd package (for biglybt as system service)

Emmanuel Bourg (@ebourg) gitlab at salsa.debian.org
Sun Nov 21 20:05:37 GMT 2021



Emmanuel Bourg pushed to branch master at Debian Java Maintainers / biglybt


Commits:
f190a371 by Fabien Steinmetz at 2021-11-21T21:04:36+01:00
Add biglybtd package (for biglybt as system service)

- - - - -


15 changed files:

- debian/biglybt.sh
- + debian/biglybtd-files/biglybtd-gui
- + debian/biglybtd-files/biglybtd-gui-xauth
- + debian/biglybtd-files/env_display.conf
- + debian/biglybtd-files/sysusers/biglybtd.conf
- + debian/biglybtd.README.Debian
- + debian/biglybtd.dirs
- + debian/biglybtd.install
- + debian/biglybtd.links
- + debian/biglybtd.postinst
- + debian/biglybtd.postrm
- + debian/biglybtd.service
- debian/changelog
- debian/control
- debian/rules


Changes:

=====================================
debian/biglybt.sh
=====================================
@@ -2,7 +2,22 @@
 
 JAVA_ARGS=$(grep -o '^[^#]*' ~/.biglybt/java.vmoptions 2>/dev/null | tr '\n' ' ')
 
+# if command is invoked as "biglybtd", then set the config path
+# to the one for the user defined in the systemd service
+if [ "$0" = "/usr/bin/biglybtd" ]; then
+  BIGLYBTD_USER=$(systemctl show -p User --value biglybtd.service)
+  BIGLYBTD_USER_HOME=$( getent passwd "$BIGLYBTD_USER" | cut -d: -f6 )
+  BIGLYBTD_USER_CONFIG_PATH=$BIGLYBTD_USER_HOME/config
+
+  PARAMS=" -Dazureus.config.path=$BIGLYBTD_USER_CONFIG_PATH -Dazureus.instance.port=6879 "
+  if [ ! "$USER" = "$BIGLYBTD_USER" ]; then
+    echo "only $BIGLYBTD_USER is allowed to run as daemon"
+    exit
+  fi
+fi
+
 java -cp /usr/share/java/biglybt-core.jar:/usr/share/java/biglybt-ui.jar:/usr/share/java/commons-cli.jar:/usr/share/java/swt4.jar:/usr/share/java/bcprov.jar \
      ${JAVA_ARGS} \
+     ${PARAMS} \
      -Dazureus.install.path=/usr/share/biglybt \
      com.biglybt.ui.Main "$@"


=====================================
debian/biglybtd-files/biglybtd-gui
=====================================
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+# if biglybt is running as daemon,
+# and if the user is allowed to display the UI,
+# then start the UI
+#
+# Authorization to display the UI is set in the sudoers file :
+#   /etc/sudoers.d/biglybtd-gui-xauth
+#
+if [ "$(systemctl is-active biglybtd.service)" = "active" ]; then
+  # Biglybt is running as a daemon
+
+  # Check if current DISPLAY is the one used by biglybtd
+  BIGLYBTD_DISPLAY=$(systemctl show -p Environment --value biglybtd.service | cut -d = -f 2)
+  if [ ! "$DISPLAY" = "$BIGLYBTD_DISPLAY" ]; then
+    echo "biglybtd DISPLAY [$BIGLYBTD_DISPLAY] and currrent DISPLAY [$DISPLAY] differ."
+    echo "The UI may not show up. Adapt biglybtd's DISPLAY to match the display you use."
+    echo "See /usr/share/doc/biglybtd/README.Debian for more information."
+  fi
+
+  # Check if current user is allowed to update .Xauthority file for biglybt user
+  BIGLYBTD_USER=$(systemctl show -p User --value biglybtd.service)
+  if [ ! "$USER" = "$BIGLYBTD_USER" ]; then
+    # Check if current user is allowed in sudoers file
+    if sudo -l -u $BIGLYBTD_USER /usr/bin/xauth merge ->/dev/null; then
+      xauth extract - $DISPLAY | sudo XAUTHORITY=$( getent passwd "$BIGLYBTD_USER" | cut -d: -f6 )/.Xauthority -u $BIGLYBTD_USER /usr/bin/xauth merge -
+    else
+      echo "Not allowed to run swt UI on bibybt deamon."
+      echo "Please check /etc/sudoers.d/biglybtd-gui-xauth or read /usr/share/doc/biglybtd/README.Debian"
+      exit 64
+    fi
+  fi
+
+  # start swt UI
+  echo "ui swt\nlogout" | nc 127.0.0.1 57006 > /dev/null
+
+else
+  echo "biglybt deamon is not running"
+fi


=====================================
debian/biglybtd-files/biglybtd-gui-xauth
=====================================
@@ -0,0 +1,10 @@
+# This defines the usernames that are allowed to show the JWT ui of BiglyBT when run as a deamon
+User_Alias      BIGLYBTD_GUI = put_username_here
+
+# This defines the username set in the systemd service biglybtd.service
+Runas_Alias      BIGLYBTD_USER = biglybt
+
+# Commands allowed
+BIGLYBTD_GUI  ALL=(BIGLYBTD_USER) NOPASSWD: /bin/bash -c /usr/bin/xauth -f $HOME/.Xauthority merge -
+BIGLYBTD_GUI  ALL=(BIGLYBTD_USER) NOPASSWD: /usr/bin/xauth merge -
+#BIGLYBTD_GUI  ALL=(biglybt) NOPASSWD: /usr/bin/xauth -f $HOME/.Xauthority merge -


=====================================
debian/biglybtd-files/env_display.conf
=====================================
@@ -0,0 +1,2 @@
+[Service]
+Environment=DISPLAY=:0


=====================================
debian/biglybtd-files/sysusers/biglybtd.conf
=====================================
@@ -0,0 +1,7 @@
+#
+# sysusers.d snippet for creating the biglybt user automatically
+# at install time. See sysusers.d(5) for details.
+#
+
+#Type Name     ID             GECOS                 Home directory   Shell
+u     biglybt  -              "BiglyBT deamon user" /var/lib/biglybt /usr/sbin/nologin


=====================================
debian/biglybtd.README.Debian
=====================================
@@ -0,0 +1,121 @@
+BiglyBT system service
+----------------------
+
+BiglyBTd is BiglyBT wrapped into a system service.
+
+It uses the "telnet" or "console" UI and therefore doesn't need a display
+to work.
+
+The "telnet" UI permits to interact with BiglyBTd. Through it you can launch
+another UI, for example the "swt" UI (which is the one displayed when using
+BiglyBT the standard way)
+
+Provided you install and configure the plugin "BiglyBT Web Remote" (see
+BigltBT plugin page), you could also interact with BiglyBTd through your
+browser.
+
+To access the command line of BiglyBTd through telnet, run:
+
+  $ telnet 127.0.0.1 57006
+
+Available commands will be displayed to you.
+
+To launch the "swt" UI of BiglyBTd, launch:
+
+  $ /usr/bin/biglybtd-gui
+
+So that the "swt" UI gets displayed in your desktop environment, you need to
+finish the configuration as below.
+
+
+Configuration
+-------------
+
+ * The biglybtd package:
+
+   - installs the systemd service
+
+   - creates system user "biglybt" whose HOME is located at /var/lib/biglybt.
+
+ * You have in addition to:
+
+   - Edit file /etc/sudoers.d/biglybtd-gui-xauth and set your username on
+     the User_Alias line
+
+     # visudo /etc/sudoers.d/biglybtd-gui-xauth
+
+     Rationale: From a technical point of view, displaying the SWT UI on the
+     screen of the current user requires the biglybt user to have access to
+     your display. The /usr/bin/biglybtd-gui script will do this for you but
+     you must have the rights to launch xauth on behalf of biglybt user.
+
+   - If you plan to open the SWT UI of biglybtd, check that DISPLAY environment
+     of biglybtd.service is correct. By default biglybtd uses a value of ":0"
+
+     1. Get the value of DISPLAY environment variable when running your desktop
+        enviroment:
+
+       $ echo $DISPLAY
+
+     2. Edit /etc/systemd/system/biglybtd.service.d/ and set the value of DISPLAY.
+
+       # editor /etc/systemd/system/biglybtd.service.d/env_display.conf
+
+     3. Finally you need to tell systemd to reload the file:
+
+       # systemctl daemon-reload
+
+   - By default, the deamon is neither enabled, nor started. You may want
+     to do so by running:
+
+       # systemctl enable biglybtd.service
+       # systemctl start biglybtd.service
+
+ * You may in addition:
+
+   - Add your user to the "biglybt" group:
+
+        $ usermod -a -G biglybt <username>
+
+   - Use the "console" UI instead of "telnet". By default, the package uses
+     "telnet" UI. If you don't wish that, you may change this in the
+     "/lib/systemd/system/biglybtd.service" file and set it to "console"
+     instead. Run "systemctl daemon-reload" after the change.
+
+
+Limitations, known issues
+--------------------------
+
+- If you open the SWT UI of the daemonized BiglyBT, and then quit that UI,
+  it will also fully close BiglyBT (the daemonized part also). However,
+  systemd will restart it immediately.
+
+- To be able to display the SWT UI of the daemonized BiglyBT in your desktop
+  environment, you have to grant the user the right to export his .Xauthority
+  MIT-MAGIC-COOKIE-1 to the biglybt user. You have to set your username at
+  the top of the sudoers file located here: /etc/sudoers.d/biglybtd-gui-xauth
+
+- The first time you launch /usr/bin/biglybtd-gui, you may have this message:
+
+    /usr/bin/xauth:  file /var/lib/biglybt/.Xauthority does not exist
+
+  This is normal since the file didn't exist. xauth command created it,
+  so now it's ok.
+
+- Thanks to the use of "-Dazureus.instance.port=6879" instead of the default
+  value (6880), it is possible to have another instance of BiglyBT running
+  (for example as a regular user) in addition to the deamonized one. However
+  this has not been tested.
+
+- The telnet port can't be configured. However you may check the value of
+  Telnet_iPort in /var/lib/biglybt/config/biglybt.config. Some more
+  information here:
+
+    https://github.com/BiglySoftware/BiglyBT/blob/master/uis/src/com/biglybt/ui/telnet/UI.java
+
+    http://wiki.vuze.com/w/TelnetUI
+
+
+Some references:
+
+* https://github.com/BiglySoftware/BiglyBT/issues/356


=====================================
debian/biglybtd.dirs
=====================================
@@ -0,0 +1 @@
+var/lib/biglybt


=====================================
debian/biglybtd.install
=====================================
@@ -0,0 +1,4 @@
+debian/biglybtd-files/biglybtd-gui              usr/share/biglybt/
+debian/biglybtd-files/biglybtd-gui-xauth        etc/sudoers.d/
+debian/biglybtd-files/env_display.conf          etc/systemd/system/biglybtd.service.d/
+debian/biglybtd-files/sysusers/biglybtd.conf    usr/lib/sysusers.d/


=====================================
debian/biglybtd.links
=====================================
@@ -0,0 +1,2 @@
+usr/share/biglybt/biglybt.sh      usr/bin/biglybtd
+usr/share/biglybt/biglybtd-gui    usr/bin/biglybtd-gui


=====================================
debian/biglybtd.postinst
=====================================
@@ -0,0 +1,44 @@
+#!/bin/sh
+# postinst script for biglybt
+#
+# see: dh_installdeb(1)
+
+set -e
+
+# summary of how this script can be called:
+#        * <postinst> `configure' <most-recently-configured-version>
+#        * <old-postinst> `abort-upgrade' <new version>
+#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
+#          <new-version>
+#        * <postinst> `abort-remove'
+#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
+#          <failed-install-package> <version> `removing'
+#          <conflicting-package> <version>
+# for details, see https://www.debian.org/doc/debian-policy/ or
+# the debian-policy package
+
+
+case "$1" in
+    configure)
+        # Create the biglybt user as defined in /usr/lib/sysusers.d/biglybtd.conf
+        systemd-sysusers
+
+        # Unlock account in case it was locked from previous purge.
+        usermod -U -e '' biglybt || true
+    ;;
+
+    abort-upgrade|abort-remove|abort-deconfigure)
+    ;;
+
+    *)
+        echo "postinst called with unknown argument \`$1'" >&2
+        exit 1
+    ;;
+esac
+
+# dh_installdeb will replace this with shell code automatically
+# generated by other debhelper scripts.
+
+#DEBHELPER#
+
+exit 0


=====================================
debian/biglybtd.postrm
=====================================
@@ -0,0 +1,57 @@
+#! /bin/sh
+# postrm script for biglybt
+#
+# see: dh_installdeb(1)
+
+set -e
+
+# summary of how this script can be called:
+#        * <postrm> `remove'
+#        * <postrm> `purge'
+#        * <old-postrm> `upgrade' <new-version>
+#        * <new-postrm> `failed-upgrade' <old-version>
+#        * <new-postrm> `abort-install'
+#        * <new-postrm> `abort-install' <old-version>
+#        * <new-postrm> `abort-upgrade' <old-version>
+#        * <disappearer's-postrm> `disappear' <r>overwrit>r> <new-version>
+# for details, see /usr/share/doc/packaging-manual/
+
+case "$1" in
+
+    remove)
+        # Remove the biglybt "$HOME" directory if empty
+        if [ -d "/var/lib/biglybt" ] ; then
+            rmdir --ignore-fail-on-non-empty /var/lib/biglybt
+        fi
+
+        ;;
+
+    purge)
+        # Remove the biglybt "$HOME" directory if empty
+        if [ -d "/var/lib/biglybt" ] ; then
+            rmdir --ignore-fail-on-non-empty /var/lib/biglybt
+        fi
+
+        # Lock biglybt account.
+        usermod -L -e 1 biglybt || true
+
+        ;;
+
+    upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
+        # Nothing to do here
+        ;;
+
+    *)
+
+        echo "postrm called with unknown argument \`$1'" >&2
+        exit 0
+
+        ;;
+esac
+
+# dh_installdeb will replace this with shell code automatically
+# generated by other debhelper scripts.
+
+#DEBHELPER#
+
+exit 0


=====================================
debian/biglybtd.service
=====================================
@@ -0,0 +1,17 @@
+[Unit]
+Description=BiglyBTd (BiglyBT as a system service)
+After=network-online.target
+
+[Service]
+# "Environment=" has been moved to /etc/systemd/system/biglybtd.service.d/env_display.conf
+User=biglybt
+Type=simple
+Restart=always
+StateDirectory=biglybt
+
+ExecStart=/usr/bin/biglybtd --ui="telnet"
+ExecStop=/usr/bin/biglybtd --shutdown
+SuccessExitStatus=143
+
+[Install]
+WantedBy=multi-user.target


=====================================
debian/changelog
=====================================
@@ -1,3 +1,10 @@
+biglybt (2.9.0.0-2) unstable; urgency=medium
+
+  [ Fabien Steinmetz ]
+  * Add biglybtd package
+
+ -- Emmanuel Bourg <ebourg at apache.org>  Sun, 21 Nov 2021 21:04:25 +0100
+
 biglybt (2.9.0.0-1) unstable; urgency=medium
 
   * New upstream release


=====================================
debian/control
=====================================
@@ -23,9 +23,27 @@ Depends:
  libswt-gtk-4-java,
  libswt-cairo-gtk-4-jni,
  libswt-webkit-gtk-4-jni
+Suggests: biglybtd
 Provides: azureus, vuze
 Description: BitTorrent client
  BiglyBT is a feature filled, open source, ad-free, BitTorrent client used
  to transfer files via the BitTorrent protocol. BiglyBT is the continuation
  of the Vuze/Azureus project first created in 2003, and is being actively
  developed by the original coders.
+
+Package: biglybtd
+Architecture: all
+Depends:
+ ${misc:Depends},
+ ${maven:Depends},
+ biglybt,
+ systemd
+Suggests: sudo, xauth
+Description: BiglyBT system service
+ BiglyBT is a feature filled, open source, ad-free, BitTorrent client used
+ to transfer files via the BitTorrent protocol. BiglyBT is the continuation
+ of the Vuze/Azureus project first created in 2003, and is being actively
+ developed by the original coders.
+ .
+ This package provides the facility to run BiglyBT as a system daemon in
+ the background. It also permits one to launch the GUI when needed.


=====================================
debian/rules
=====================================
@@ -1,4 +1,11 @@
 #!/usr/bin/make -f
 
 %:
-	dh $@
\ No newline at end of file
+	dh $@
+
+override_dh_fixperms:
+	dh_fixperms
+	chmod 440 debian/biglybtd-files/biglybtd-gui-xauth
+
+override_dh_installsystemd:
+	dh_installsystemd -pbiglybtd biglybtd.service



View it on GitLab: https://salsa.debian.org/java-team/biglybt/-/commit/f190a37139f691ec9f8f477822a0da05cbf33830

-- 
View it on GitLab: https://salsa.debian.org/java-team/biglybt/-/commit/f190a37139f691ec9f8f477822a0da05cbf33830
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20211121/f2421745/attachment.htm>


More information about the pkg-java-commits mailing list