Sfoglia il codice sorgente

Don't restart with sudo(8) if it's not available

Some environments, like system containers, have no reason to have
sudo(8) installed. In these environments restart.sh will silently fail
because /usr/bin/sudo does not exist to execute, so test that sudo
exists and don't try to use it otherwise.

Note also that hardcoding sudo's path is wrong: it can be installed in
other places. On FreeBSD, for example, it is /usr/local/bin/sudo when
installed from ports.
AJ Jordan 4 anni fa
parent
commit
2911dfc37d
2 ha cambiato i file con 16 aggiunte e 4 eliminazioni
  1. 8 2
      debian/bin/restart.sh
  2. 8 2
      fedora/restart.sh

+ 8 - 2
debian/bin/restart.sh

@@ -34,13 +34,19 @@ else
     fi
     fi
 fi
 fi
 
 
+if type sudo >/dev/null 2>&1; then
+    sudo_command=sudo
+else
+    sudo_command=
+fi
+
 echo "Detected service control platform '$cmd'; using it to restart Jellyfin..."
 echo "Detected service control platform '$cmd'; using it to restart Jellyfin..."
 case $cmd in
 case $cmd in
     'systemctl')
     'systemctl')
-        echo "sleep 0.5; /usr/bin/sudo systemctl start jellyfin" | at now 
+        echo "sleep 0.5; $sudo_command systemctl start jellyfin" | at now
         ;;
         ;;
     'service')
     'service')
-        echo "sleep 0.5; /usr/bin/sudo service jellyfin start" | at now 
+        echo "sleep 0.5; $sudo_command service jellyfin start" | at now
         ;;
         ;;
     'sysv')
     'sysv')
         echo "sleep 0.5; /usr/bin/sudo /etc/init.d/jellyfin start" | at now 
         echo "sleep 0.5; /usr/bin/sudo /etc/init.d/jellyfin start" | at now 

+ 8 - 2
fedora/restart.sh

@@ -34,13 +34,19 @@ else
     fi
     fi
 fi
 fi
 
 
+if type sudo >/dev/null 2>&1; then
+    sudo_command=sudo
+else
+    sudo_command=
+fi
+
 echo "Detected service control platform '$cmd'; using it to restart Jellyfin..."
 echo "Detected service control platform '$cmd'; using it to restart Jellyfin..."
 case $cmd in
 case $cmd in
     'systemctl')
     'systemctl')
-        echo "sleep 0.5; /usr/bin/sudo systemctl start jellyfin" | at now 
+        echo "sleep 0.5; $sudo_command systemctl start jellyfin" | at now
         ;;
         ;;
     'service')
     'service')
-        echo "sleep 0.5; /usr/bin/sudo service jellyfin start" | at now 
+        echo "sleep 0.5; $sudo_command service jellyfin start" | at now
         ;;
         ;;
     'sysv')
     'sysv')
         echo "sleep 0.5; /usr/bin/sudo /etc/init.d/jellyfin start" | at now 
         echo "sleep 0.5; /usr/bin/sudo /etc/init.d/jellyfin start" | at now