source: installer/resources/i2prouter @ ab44488

Last change on this file since ab44488 was ab44488, checked in by kytv <kytv@…>, 6 years ago

i2prouter: don't use uname -p to determine the arch

  • This came from the script from Tanuki but it does return useful information (as far as its use in the script) in my testing. uname -m is better for our needs. (The problem is only seen on certain CPUs when *all* available wrapper binaries are present and the script tries to resolve the correct binary to use..
  • Property mode set to 100644
File size: 68.1 KB
Line 
1#!/bin/sh
2
3#
4# Copyright (c) 1999, 2011 Tanuki Software, Ltd.
5# http://www.tanukisoftware.com
6# All rights reserved.
7#
8# Make sure that PIDFILE points to the correct location,
9# if you have changed the default location set in the
10# wrapper configuration file.
11#
12# If this script fails to successfully invoke i2psvc on your platform,
13# try the runplain.sh script instead.
14#
15# This software is the proprietary information of Tanuki Software.
16# You shall use it only in accordance with the terms of the
17# license agreement you entered into with Tanuki Software.
18# http://wrapper.tanukisoftware.com/doc/english/licenseOverview.html
19#
20# Java Service Wrapper sh script.  Suitable for starting and stopping
21#  wrapped Java applications on UNIX platforms.
22#
23#-----------------------------------------------------------------------------
24# These settings can be modified to fit the needs of your application
25# Optimized for use with version 3.5.22 of the Wrapper.
26
27# Paths
28# Note that (percent)INSTALL_PATH, (percent)USER_HOME,  and (percent)SYSTEM_java_io_tmpdir
29# should have been replaced by the izpack installer.
30# If you did not run the installer, replace them with the appropriate paths.
31I2P="%INSTALL_PATH"
32if [ "`uname -s`" = "Darwin" ]; then
33   if [ -d "%USER_HOME/Library/Application Support" ]; then
34       I2P_CONFIG_DIR="%USER_HOME/Library/Application Support/i2p"
35   else
36       I2P_CONFIG_DIR="%USER_HOME/.i2p"
37   fi
38else
39    I2P_CONFIG_DIR="%USER_HOME/.i2p"
40fi
41I2PTEMP="%SYSTEM_java_io_tmpdir"
42# PORTABLE installation:
43# Use the following instead.
44#I2PTEMP="%INSTALL_PATH"
45
46# Application
47APP_NAME="i2p"
48APP_LONG_NAME="I2P Service"
49
50# gettext - we look for it in the path
51# fallback to echo is below, we can't set it to echo here.
52GETTEXT=$(which gettext > /dev/null 2>&1)
53
54# Where to install the systemd service
55SYSTEMD_SERVICE="/etc/systemd/system/${APP_NAME}.service"
56if grep -q systemd /proc/1/comm > /dev/null 2>&1 ; then
57    USE_SYSTEMD=1
58fi
59
60# If specified, the Wrapper will be run as the specified user.
61# IMPORTANT - Make sure that the user has the required privileges to write
62#  the PID file and wrapper.log files and that the directories exist.
63#  Failure to write the pid file will cause the Wrapper to exit.
64#  Failure to write the log file will cause the Wrapper to use CWD for the log file location.
65#
66# NOTE - This will set the user which is used to run the Wrapper as well as
67#  the JVM and is not useful in situations where a privileged resource or
68#  port needs to be allocated prior to the user being changed.
69#RUN_AS_USER=
70
71# Wrapper
72WRAPPER_CMD="$I2P/i2psvc"
73WRAPPER_CONF="$I2P/wrapper.config"
74
75# Priority at which to run the wrapper.  See "man nice" for valid priorities.
76#  nice is only used if a priority is specified.
77PRIORITY=
78
79# Location of the pid and status files.
80PIDDIR="$I2P_CONFIG_DIR"
81#PIDDIR="$I2PTEMP"
82
83# Location of the wrapper.log file
84LOGDIR="$I2P_CONFIG_DIR"
85#LOGDIR="$I2PTEMP"
86LOGFILE="$LOGDIR/wrapper.log"
87
88# If you'd like to run I2P as root (not recommended), uncomment the
89# following line
90#ALLOW_ROOT=true
91
92# FIXED_COMMAND tells the script to use a hard coded action rather than
93# expecting the first parameter of the command line to be the command.
94# By default the command will will be expected to be the first parameter.
95#FIXED_COMMAND=console
96
97# PASS_THROUGH tells the script to pass all arguments through to the JVM
98#  as is.  If FIXED_COMMAND is specified then all arguments will be passed.
99#  If not set then all arguments starting with the second will be passed.
100#PASS_THROUGH=true
101
102# If uncommented, causes the Wrapper to be shutdown using an anchor file.
103#  When launched with the 'start' command, it will also ignore all INT and
104#  TERM signals.
105#IGNORE_SIGNALS=true
106
107# Wrapper will start the JVM asynchronously. Your application may have some
108#  initialization tasks and it may be desirable to wait a few seconds
109#  before returning.  For example, to delay the invocation of following
110#  startup scripts.  Setting WAIT_AFTER_STARTUP to a positive number will
111#  cause the start command to delay for the indicated period of time
112#  (in seconds).
113#
114WAIT_AFTER_STARTUP=0
115
116# If set, wait for the wrapper to report that the daemon has started
117WAIT_FOR_STARTED_STATUS=true
118WAIT_FOR_STARTED_TIMEOUT=120
119
120# If set, the status, start_msg and stop_msg commands will print out detailed
121#   state information on the Wrapper and Java processes.
122#DETAIL_STATUS=true
123
124# By default we show a detailed usage block.  Uncomment to show brief usage.
125#BRIEF_USAGE=true
126
127# flag for using upstart when installing (rather than init.d rc.d)
128USE_UPSTART=
129
130# Source the environment variables for the locale if $LANG isn't set
131# If you want to set custom locale variables for I2P,
132# you may comment out this block and set them yourself here.
133
134if [ ! -n $LANG ]; then
135        for ENV_FILE in /etc/environment /etc/default/locale; do
136                [ -r "$ENV_FILE" ] || continue
137                [ -s "$ENV_FILE" ] || continue
138
139                for var in LANG LANGUAGE LC_ALL LC_CTYPE; do
140                        value=`egrep "^${var}=" "$ENV_FILE" | tail -n1 | cut -d= -f2`
141                        [ -n "$value" ] && eval export $var=$value
142                done
143        done
144fi
145
146# When installing on On Mac OSX platforms, the following domain will be used to
147#  prefix the plist file name.
148PLIST_DOMAIN=org.tanukisoftware.wrapper
149
150# The following two lines are used by the chkconfig command. Change as is
151#  appropriate for your application.  They should remain commented.
152# chkconfig: 2345 20 80
153# description: I2P Service
154
155# Initialization block for the install_initd and remove_initd scripts used by
156#  SUSE linux distributions.
157### BEGIN INIT INFO
158# Provides: i2p
159# Required-Start: $local_fs $network $syslog
160# Should-Start:
161# Required-Stop:
162# Default-Start: 2 3 4 5
163# Default-Stop: 0 1 6
164# Short-Description: I2P Service
165# Description: I2P is a load-balanced unspoofable packet switching network
166### END INIT INFO
167
168# Do not modify anything beyond this point
169#-----------------------------------------------------------------------------
170if [ ! -e "$WRAPPER_CONF" ]; then
171       echo "Starting I2P Failed: Unable to find $WRAPPER_CONF"
172       exit 1
173fi
174
175# Workaround for Gentoo
176JAVABINARY=$(awk -F'=' '/^ *wrapper\.java\.command/{print $2}' "$WRAPPER_CONF")
177
178if [ -e /etc/gentoo-release ]; then
179    if [ $JAVABINARY = java ]; then
180        if [ -x /etc/java-config-2/current-system-vm/bin/java ]; then
181            JAVABINARY="/etc/java-config-2/current-system-vm/bin/java"
182        else
183            echo "Please set wrapper.java.command in $WRAPPER_CONF"
184            exit 1
185        fi
186    fi
187fi
188
189WRAPPER_URL="http://www.i2p2.de/manualwrapper"
190unsupported() {
191    echo "The most likely reason is that a supported version of the java"
192    echo "wrapper is not available in the I2P installation package for your"
193    echo "platform. It may be possible to manually download and install"
194    echo "a compatible wrapper for your system."
195    echo "See ${WRAPPER_URL} for hints."
196    echo
197    echo "In the meantime, you may start I2P by running the script"
198    echo "${I2P}/runplain.sh"
199    echo
200}
201
202freebsd10() {
203    echo
204    echo "The current version of the Tanuki wrapper does not"
205    echo "support FreeBSD 10."
206    echo
207    echo "See https://trac.i2p2.de/ticket/1118 for more information"
208    echo "and a workaround for this issue."
209    echo
210    echo "In the meantime, you may start I2P by running the script"
211    echo "${I2P}/runplain.sh"
212    echo
213}
214
215failed() {
216    echo "**`gettext 'Failed to load the wrapper'`**"
217    case `uname -s` in
218        FreeBSD)
219            case `uname -r` in
220                10*|11*)
221                    freebsd10
222                    ;;
223                *)
224                    # We should never get here on recent versions of FreeBSD
225                    if ! $(pkg_info -E 'libiconv*' > /dev/null 2>&1); then
226                        echo
227                        echo "The wrapper requires libiconv."
228                        echo
229                        echo "It can be installed with pkg_add -r libiconv"
230                        echo
231                    fi
232                    ;;
233            esac
234            ;;
235
236        *)
237            echo
238            unsupported
239            ;;
240    esac
241    exit 1
242}
243
244if [ -n "$FIXED_COMMAND" ]
245then
246    COMMAND="$FIXED_COMMAND"
247else
248    COMMAND="$1"
249fi
250
251
252# Required for HP-UX Startup
253if [ `uname -s` = "HP-UX" -o `uname -s` = "HP-UX64" ] ; then
254        PATH=$PATH:/usr/bin
255fi
256
257# Get the fully qualified path to the script
258case $0 in
259    /*)
260        SCRIPT="$0"
261        ;;
262    *)
263        PWD=`pwd`
264        SCRIPT="$PWD/$0"
265        ;;
266esac
267
268# Resolve the true real path without any sym links.
269CHANGED=true
270while [ "X$CHANGED" != "X" ]
271do
272    # Change spaces to ":" so the tokens can be parsed.
273    SAFESCRIPT=`echo $SCRIPT | sed -e 's; ;:;g'`
274    # Get the real path to this script, resolving any symbolic links
275    TOKENS=`echo $SAFESCRIPT | sed -e 's;/; ;g'`
276    REALPATH=
277    for C in $TOKENS; do
278        # Change any ":" in the token back to a space.
279        C=`echo $C | sed -e 's;:; ;g'`
280        REALPATH="$REALPATH/$C"
281        # If REALPATH is a sym link, resolve it.  Loop for nested links.
282        while [ -h "$REALPATH" ] ; do
283            LS="`ls -ld "$REALPATH"`"
284            LINK="`expr "$LS" : '.*-> \(.*\)$'`"
285            if expr "$LINK" : '/.*' > /dev/null; then
286                # LINK is absolute.
287                REALPATH="$LINK"
288            else
289                # LINK is relative.
290                REALPATH="`dirname "$REALPATH"`""/$LINK"
291            fi
292        done
293    done
294
295    if [ "$REALPATH" = "$SCRIPT" ]
296    then
297        CHANGED=""
298    else
299        SCRIPT="$REALPATH"
300    fi
301done
302
303# Get the location of the script.
304REALDIR=`dirname "$REALPATH"`
305# Normalize the path
306REALDIR=`cd "${REALDIR}"; pwd`
307
308# If the PIDDIR is relative, set its value relative to the full REALPATH to avoid problems if
309#  the working directory is later changed.
310FIRST_CHAR=`echo $PIDDIR | cut -c1,1`
311if [ "$FIRST_CHAR" != "/" ]
312then
313    PIDDIR=$REALDIR/$PIDDIR
314fi
315# Same test for WRAPPER_CMD
316FIRST_CHAR=`echo $WRAPPER_CMD | cut -c1,1`
317if [ "$FIRST_CHAR" != "/" ]
318then
319    WRAPPER_CMD=$REALDIR/$WRAPPER_CMD
320fi
321# Same test for WRAPPER_CONF
322FIRST_CHAR=`echo $WRAPPER_CONF | cut -c1,1`
323if [ "$FIRST_CHAR" != "/" ]
324then
325    WRAPPER_CONF=$REALDIR/$WRAPPER_CONF
326fi
327
328# Process ID
329ANCHORFILE="$PIDDIR/$APP_NAME.anchor"
330COMMANDFILE="$PIDDIR/$APP_NAME.command"
331STATUSFILE="$PIDDIR/$APP_NAME.status"
332JAVASTATUSFILE="$PIDDIR/$APP_NAME.java.status"
333PIDFILE="$PIDDIR/$APP_NAME.pid"
334LOCKDIR="/var/lock/subsys"
335LOCKFILE="$LOCKDIR/$APP_NAME"
336pid=""
337
338# Resolve the location of the 'ps' command
339PSEXE="/usr/ucb/ps"
340    if [ ! -x "$PSEXE" ]
341    then
342        PSEXE="/usr/bin/ps"
343        if [ ! -x "$PSEXE" ]
344        then
345            PSEXE="/bin/ps"
346            if [ ! -x "$PSEXE" ]
347            then
348                echo 'Unable to locate "ps".'
349                echo 'Please report this message along with the location of the command on your system.'
350                exit 1
351            fi
352        fi
353    fi
354
355TREXE="/usr/bin/tr"
356if [ ! -x "$TREXE" ]
357then
358    TREXE="/bin/tr"
359    if [ ! -x "$TREXE" ]
360    then
361        echo 'Unable to locate "tr".'
362        echo 'Please report this message along with the location of the command on your system.'
363        exit 1
364    fi
365fi
366
367
368# Resolve the os
369DIST_OS=`uname -s | $TREXE "[A-Z]" "[a-z]" | $TREXE -d ' '`
370case "$DIST_OS" in
371    'sunos')
372        DIST_OS="solaris"
373        ;;
374    'hp-ux' | 'hp-ux64')
375        # HP-UX needs the XPG4 version of ps (for -o args)
376        DIST_OS="hpux"
377        UNIX95=""
378        export UNIX95
379        ;;
380    'darwin')
381        DIST_OS="macosx"
382        ;;
383    'unix_sv')
384        DIST_OS="unixware"
385        ;;
386    'gnu/kfreebsd')
387        DIST_OS="kfreebsd"
388        ;;
389    'os/390')
390        DIST_OS="zos"
391        ;;
392esac
393
394# Resolve the architecture
395if [ "$DIST_OS" = "macosx" ]
396then
397    OS_VER=`sw_vers | grep ProductVersion | cut -d: -f2 | sed -e 's/[^0-9]*//'`
398    DIST_ARCH="universal"
399    if [ $(sysctl -n hw.cpu64bit_capable) -eq 1 ]; then
400        DIST_BITS="64"
401    else
402        DIST_BITS="32"
403    fi
404    APP_PLIST_BASE=${PLIST_DOMAIN}.${APP_NAME}
405    APP_PLIST=${APP_PLIST_BASE}.plist
406else
407    DIST_ARCH=`uname -m 2>/dev/null | $TREXE "[A-Z]" "[a-z]" | $TREXE -d ' '`
408    case "$DIST_ARCH" in
409        'athlon' | 'i386' | 'i486' | 'i586' | 'i686')
410            DIST_ARCH="x86"
411            if [ "${DIST_OS}" = "solaris" ] ; then
412                DIST_BITS=`isainfo -b`
413            else
414                DIST_BITS="32"
415            fi
416            ;;
417        amdfx* | 'amd64' | 'x86_64')
418            DIST_ARCH="x86"
419            DIST_BITS="64"
420            ;;
421        'ia32')
422            DIST_ARCH="ia"
423            DIST_BITS="32"
424            ;;
425        'ia64' | 'ia64n' | 'ia64w')
426            DIST_ARCH="ia"
427            DIST_BITS="64"
428            ;;
429        'ip27')
430            DIST_ARCH="mips"
431            DIST_BITS="32"
432            ;;
433        'power' | 'powerpc' | 'power_pc' | 'ppc64')
434            if [ "${DIST_ARCH}" = "ppc64" ] ; then
435                DIST_BITS="64"
436            else
437                DIST_BITS="32"
438            fi
439            DIST_ARCH="ppc"
440            if [ "${DIST_OS}" = "aix" ] ; then
441                if [ `getconf KERNEL_BITMODE` -eq 64 ]; then
442                    DIST_BITS="64"
443                else
444                    DIST_BITS="32"
445                fi
446            fi
447            ;;
448        'pa_risc' | 'pa-risc')
449            DIST_ARCH="parisc"
450            if [ `getconf KERNEL_BITS` -eq 64 ]; then
451                DIST_BITS="64"
452            else
453                DIST_BITS="32"
454            fi
455            ;;
456        'sun4u' | 'sparcv9' | 'sparc')
457            DIST_ARCH="sparc"
458            DIST_BITS=`isainfo -b`
459            ;;
460        '9000/800' | '9000/785')
461            DIST_ARCH="parisc"
462            if [ `getconf KERNEL_BITS` -eq 64 ]; then
463                DIST_BITS="64"
464            else
465                DIST_BITS="32"
466            fi
467            ;;
468        '2064' | '2066' | '2084' | '2086' | '2094' | '2096' | '2097' | '2098' | '2817')
469            DIST_ARCH="390"
470            DIST_BITS="64"
471            ;;
472        armv*)
473            if [ -z "`readelf -A /proc/self/exe | grep Tag_ABI_VFP_args`" ] ; then
474                DIST_ARCH="armel"
475                DIST_BITS="32"
476            else
477                DIST_ARCH="armhf"
478                DIST_BITS="32"
479            fi
480            ;;
481    esac
482fi
483
484# OSX always places Java in the same location so we can reliably set JAVA_HOME
485if [ "$DIST_OS" = "macosx" ]
486then
487    if [ -z "$JAVA_HOME" ]; then
488        JAVA_HOME="/Library/Java/Home"; export JAVA_HOME
489    fi
490fi
491
492# Test Echo
493ECHOTEST=`echo -n "x"`
494if [ "$ECHOTEST" = "x" ]
495then
496    ECHOOPT="-n "
497else
498    ECHOOPT=""
499fi
500
501
502gettext() {
503    # Call external gettext using our own translation files.
504    # Don't attempt to translate via the wrapper,
505    # it probably isn't supported in the community edition.
506    if [ "X${LANG#en}" = "X$LANG" ] && [ $(which $GETTEXT > /dev/null 2>&1) ] ; then
507            TEXTDOMAINDIR=$I2P/locale $GETTEXT -d i2prouter "$1"
508            if [ $? != 0 ] ; then
509                echo "$1"
510            fi
511        else
512            echo "$1"
513        fi
514}
515
516outputFile() {
517    if [ -f "$1" ]
518    then
519        echo "  $1  Found but not executable.";
520    else
521        echo "  $1"
522    fi
523}
524
525# Decide on the wrapper binary to use.
526# If the bits of the OS could be detected, we will try to look for the
527#  binary with the correct bits value.  If it doesn't exist, fall back
528#  and look for the 32-bit binary.  If that doesn't exist either then
529#  look for the default.
530WRAPPER_TEST_CMD=""
531if [ -f "$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-$DIST_BITS" ]
532then
533    WRAPPER_TEST_CMD="$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-$DIST_BITS"
534    if [ ! -x "$WRAPPER_TEST_CMD" ]
535    then
536        chmod +x "$WRAPPER_TEST_CMD" 2>/dev/null
537    fi
538    if [ -x "$WRAPPER_TEST_CMD" ]
539    then
540        WRAPPER_CMD="$WRAPPER_TEST_CMD"
541    else
542        outputFile "$WRAPPER_TEST_CMD"
543        WRAPPER_TEST_CMD=""
544    fi
545fi
546if [ -f "$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32" -a -z "$WRAPPER_TEST_CMD" ]
547then
548    WRAPPER_TEST_CMD="$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32"
549    if [ ! -x "$WRAPPER_TEST_CMD" ]
550    then
551        chmod +x "$WRAPPER_TEST_CMD" 2>/dev/null
552    fi
553    if [ -x "$WRAPPER_TEST_CMD" ]
554    then
555        WRAPPER_CMD="$WRAPPER_TEST_CMD"
556    else
557        outputFile "$WRAPPER_TEST_CMD"
558        WRAPPER_TEST_CMD=""
559    fi
560fi
561if [ -f "$WRAPPER_CMD" -a -z "$WRAPPER_TEST_CMD" ]
562then
563    WRAPPER_TEST_CMD="$WRAPPER_CMD"
564    if [ ! -x "$WRAPPER_TEST_CMD" ]
565    then
566        chmod +x "$WRAPPER_TEST_CMD" 2>/dev/null
567    fi
568    if [ -x "$WRAPPER_TEST_CMD" ]
569    then
570        WRAPPER_CMD="$WRAPPER_TEST_CMD"
571    else
572        outputFile "$WRAPPER_TEST_CMD"
573        WRAPPER_TEST_CMD=""
574    fi
575fi
576if [ -z "$WRAPPER_TEST_CMD" ]
577then
578    echo 'Unable to locate any of the following binaries:'
579    outputFile "$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-$DIST_BITS"
580    if [ ! "$DIST_BITS" = "32" ]
581    then
582        outputFile "$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32"
583    fi
584    outputFile "$WRAPPER_CMD"
585
586    exit 1
587fi
588
589if [ ! -r "${WRAPPER_CMD}" ]; then
590    echo "Unable to locate ${WRAPPER_CMD} in ${I2P}!"
591    echo
592    unsupported
593    echo
594    exit 1
595fi
596
597if $(which ldd > /dev/null 2>&1); then
598    # This should cover every *NIX other than OSX since OSX doesn't have ldd.
599    # OSX has otool. Is otool on every OSX installation? Is otool's output the same as ldd's?
600    # The wrapper we ship for OSX are for PPC and Intel, so maybe we don't need to worry about OSX?
601    if (ldd "$WRAPPER_CMD" |grep -q 'not found') > /dev/null 2>&1 || \
602                         ! (ldd "$WRAPPER_CMD" > /dev/null 2>&1); then
603        failed
604    fi
605fi
606
607
608# Build the nice clause
609if [ "X$PRIORITY" = "X" ]
610then
611    CMDNICE=""
612else
613    CMDNICE="nice -$PRIORITY"
614fi
615
616# Build the anchor file clause.
617if [ "X$IGNORE_SIGNALS" = "X" ]
618then
619   ANCHORPROP=
620   IGNOREPROP=
621else
622   ANCHORPROP=wrapper.anchorfile=\"$ANCHORFILE\"
623   IGNOREPROP=wrapper.ignore_signals=TRUE
624fi
625
626# Build the status file clause.
627if [ "X$DETAIL_STATUS$WAIT_FOR_STARTED_STATUS" = "X" ]
628then
629   STATUSPROP=
630else
631   STATUSPROP="wrapper.statusfile=\"$STATUSFILE\" wrapper.java.statusfile=\"$JAVASTATUSFILE\""
632fi
633
634# Build the command file clause.
635COMMANDPROP=
636
637# Build the log file clause.
638LOGPROP="wrapper.logfile=\"$LOGFILE\""
639
640if [ ! -n "$WAIT_FOR_STARTED_STATUS" ]
641then
642    WAIT_FOR_STARTED_STATUS=true
643fi
644
645if [ $WAIT_FOR_STARTED_STATUS = true ] ; then
646    DETAIL_STATUS=true
647fi
648
649
650# Build the lock file clause.  Only create a lock file if the lock directory exists on this platform.
651LOCKPROP=
652if [ -d $LOCKDIR ]
653then
654    if [ -w $LOCKDIR ]
655    then
656        LOCKPROP=wrapper.lockfile=\"$LOCKFILE\"
657    fi
658fi
659
660prepAdditionalParams() {
661    ADDITIONAL_PARA=""
662    if [ -n "$PASS_THROUGH" ] ; then
663        ADDITIONAL_PARA="--"
664    fi
665    while [ -n "$1" ] ; do
666        ADDITIONAL_PARA="$ADDITIONAL_PARA \"$1\""
667        shift
668    done
669}
670
671checkUser() {
672    # $1 touchLock flag
673    # $2.. [command] args
674
675    # Check the configured user.  If necessary rerun this script as the desired user.
676    if [ "X$RUN_AS_USER" != "X" ]
677    then
678
679        # Resolve the location of the 'id' command
680        IDEXE="/usr/xpg4/bin/id"
681        if [ ! -x "$IDEXE" ]
682        then
683            IDEXE="/usr/bin/id"
684            if [ ! -x "$IDEXE" ]
685            then
686                echo 'Unable to locate "id".'
687                echo 'Please report this message along with the location of the command on your system.'
688                exit 1
689            fi
690        fi
691        if [ "`$IDEXE -u -n "$RUN_AS_USER" 2>/dev/null`" != "$RUN_AS_USER" ]
692        then
693            echo "User $RUN_AS_USER does not exist."
694            exit 1
695        fi
696
697        if [ "`$IDEXE -u -n`" = "$RUN_AS_USER" ]
698        then
699            # Already running as the configured user.  Avoid password prompts by not calling su.
700            RUN_AS_USER=""
701        fi
702    fi
703    if [ "X$RUN_AS_USER" != "X" ]
704    then
705        # If LOCKPROP and $RUN_AS_USER are defined then the new user will most likely not be
706        # able to create the lock file.  The Wrapper will be able to update this file once it
707        # is created but will not be able to delete it on shutdown.  If $1 is set then
708        # the lock file should be created for the current command
709        if [ "X$LOCKPROP" != "X" ]
710        then
711            if [ "X$1" != "X" ]
712            then
713                # Resolve the primary group
714                RUN_AS_GROUP=`groups $RUN_AS_USER | awk '{print $3}' | tail -1`
715                if [ "X$RUN_AS_GROUP" = "X" ]
716                then
717                    RUN_AS_GROUP=$RUN_AS_USER
718                fi
719                touch $LOCKFILE
720                chown $RUN_AS_USER:$RUN_AS_GROUP $LOCKFILE
721            fi
722        fi
723
724        # Still want to change users, recurse.  This means that the user will only be
725        #  prompted for a password once. Variables shifted by 1
726        shift
727
728        # Wrap the parameters so they can be passed.
729        ADDITIONAL_PARA=""
730        while [ -n "$1" ] ; do
731            ADDITIONAL_PARA="$ADDITIONAL_PARA \"$1\""
732            shift
733        done
734
735        # Use "runuser" if this exists.  runuser should be used on RedHat in preference to su.
736        #
737        if test -f "/sbin/runuser"
738        then
739            /sbin/runuser -s /bin/sh - $RUN_AS_USER -c "\"$REALPATH\" $ADDITIONAL_PARA"
740        else
741            su - $RUN_AS_USER -s /bin/sh -c "\"$REALPATH\" $ADDITIONAL_PARA"
742        fi
743        RUN_AS_USER_EXITCODE=$?
744        # Now that we are the original user again, we may need to clean up the lock file.
745        if [ "X$LOCKPROP" != "X" ]
746        then
747            getpid
748            if [ "X$pid" = "X" ]
749            then
750                # Wrapper is not running so make sure the lock file is deleted.
751                if [ -f "$LOCKFILE" ]
752                then
753                    rm "$LOCKFILE"
754                fi
755            fi
756        fi
757
758        exit $RUN_AS_USER_EXITCODE
759    fi
760}
761
762getpid() {
763    pid=""
764    if [ -f "$PIDFILE" ]
765    then
766        if [ -r "$PIDFILE" ]
767        then
768            pid=`cat "$PIDFILE"`
769            if [ "X$pid" != "X" ]
770            then
771                # It is possible that 'a' process with the pid exists but that it is not the
772                #  correct process.  This can happen in a number of cases, but the most
773                #  common is during system startup after an unclean shutdown.
774                # The ps statement below looks for the specific wrapper command running as
775                #  the pid.  If it is not found then the pid file is considered to be stale.
776                case "$DIST_OS" in
777                    'freebsd')
778                        pidtest=`$PSEXE -p $pid -o args | tail -1`
779                        if [ "X$pidtest" = "XCOMMAND" ]
780                        then
781                            pidtest=""
782                        fi
783                        ;;
784                    'macosx')
785                        pidtest=`$PSEXE -ww -p $pid -o command | grep -F "$WRAPPER_CMD" | tail -1`
786                        ;;
787                    'solaris')
788                        if [ -f "/usr/bin/pargs" ]
789                        then
790                            pidtest=`pargs $pid | fgrep "$WRAPPER_CMD" | tail -1`
791                        else
792                            case "$PSEXE" in
793                            '/usr/ucb/ps')
794                                pidtest=`$PSEXE -auxww  $pid | fgrep "$WRAPPER_CMD" | tail -1`
795                                ;;
796                            '/usr/bin/ps')
797                                TRUNCATED_CMD=`$PSEXE -o comm -p $pid | tail -1`
798                                COUNT=`echo $TRUNCATED_CMD | wc -m`
799                                COUNT=`echo ${COUNT}`
800                                COUNT=`expr $COUNT - 1`
801                                TRUNCATED_CMD=`echo $WRAPPER_CMD | cut -c1-$COUNT`
802                                pidtest=`$PSEXE -o comm -p $pid | fgrep "$TRUNCATED_CMD" | tail -1`
803                                ;;
804                            '/bin/ps')
805                                TRUNCATED_CMD=`$PSEXE -o comm -p $pid | tail -1`
806                                COUNT=`echo $TRUNCATED_CMD | wc -m`
807                                COUNT=`echo ${COUNT}`
808                                COUNT=`expr $COUNT - 1`
809                                TRUNCATED_CMD=`echo $WRAPPER_CMD | cut -c1-$COUNT`
810                                pidtest=`$PSEXE -o comm -p $pid | fgrep "$TRUNCATED_CMD" | tail -1`
811                                ;;
812                            *)
813                                echo "Unsupported ps command $PSEXE"
814                                exit 1
815                                ;;
816                            esac
817                        fi
818                        ;;
819                    'hpux')
820                        pidtest=`$PSEXE -p $pid -x -o args | grep -F "$WRAPPER_CMD" | tail -1`
821                        ;;
822                    *)
823                        pidtest=`$PSEXE -p $pid -o args | grep -F "$WRAPPER_CMD" | tail -1`
824                        ;;
825                esac
826
827                if [ "X$pidtest" = "X" ]
828                then
829                    # This is a stale pid file.
830                    rm -f "$PIDFILE"
831                    echo "Removed stale pid file: $PIDFILE"
832                    pid=""
833                fi
834            fi
835        else
836            echo "Cannot read $PIDFILE."
837            exit 1
838        fi
839    fi
840}
841
842getstatus() {
843    STATUS=
844    if [ -f "$STATUSFILE" ]
845    then
846        if [ -r "$STATUSFILE" ]
847        then
848            STATUS=`cat "$STATUSFILE"`
849        fi
850    fi
851    if [ "X$STATUS" = "X" ]
852    then
853        STATUS="Unknown"
854    fi
855
856    JAVASTATUS=
857    if [ -f "$JAVASTATUSFILE" ]
858    then
859        if [ -r "$JAVASTATUSFILE" ]
860        then
861            JAVASTATUS=`cat "$JAVASTATUSFILE"`
862        fi
863    fi
864    if [ "X$JAVASTATUS" = "X" ]
865    then
866        JAVASTATUS="Unknown"
867    fi
868}
869
870testpid() {
871    case "$DIST_OS" in
872     'solaris')
873        case "$PSEXE" in
874        '/usr/ucb/ps')
875            pid=`$PSEXE  $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1`
876            ;;
877        '/usr/bin/ps')
878            pid=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1`
879            ;;
880        '/bin/ps')
881            pid=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1`
882            ;;
883        *)
884            echo "Unsupported ps command $PSEXE"
885            exit 1
886            ;;
887        esac
888        ;;
889    *)
890        pid=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1` 2>/dev/null
891        ;;
892    esac
893    if [ "X$pid" = "X" ]
894    then
895        # Process is gone so remove the pid file.
896        rm -f "$PIDFILE"
897        pid=""
898    fi
899}
900
901launchdtrap() {
902    stopit
903    exit
904}
905
906waitforwrapperstop() {
907    getpid
908    while [ "X$pid" != "X" ] ; do
909        sleep 1
910        getpid
911    done
912}
913
914create_config_dir() {
915    if [ ! -d "$I2P_CONFIG_DIR" ]; then
916        UMASK=$(awk -F'=' '/^ *wrapper\.umask/{print $2}' $WRAPPER_CONF)
917        umask $UMASK
918        if ! mkdir -p "$I2P_CONFIG_DIR"; then
919            echo "Error creating $I2P_CONFIG_DIR! Edit $0 and set I2P_CONFIG_DIR" >&2
920            echo "to the correct location." >&2
921            exit 1
922        fi
923    fi
924}
925
926launchdinternal() {
927    getpid
928    trap launchdtrap TERM
929    if [ "X$pid" = "X" ]
930    then
931        prepAdditionalParams "$@"
932        create_config_dir
933
934        # The string passed to eval must handles spaces in paths correctly.
935        COMMAND_LINE="$CMDNICE \"$WRAPPER_CMD\" \"$WRAPPER_CONF\" wrapper.syslog.ident=\"$APP_NAME\" wrapper.pidfile=\"$PIDFILE\" wrapper.name=\"$APP_NAME\" wrapper.java.command=\"$JAVABINARY\" wrapper.displayname=\"$APP_LONG_NAME\" wrapper.daemonize=TRUE $ANCHORPROP $IGNOREPROP $STATUSPROP $COMMANDPROP $LOCKPROP $LOGPROP $ADDITIONAL_PARA"
936        eval $COMMAND_LINE || failed
937    else
938        eval echo `gettext '$APP_LONG_NAME is already running.'`
939        exit 1
940    fi
941    # launchd expects that this script stay up and running so we need to do our own monitoring of the Wrapper process.
942    if [ $WAIT_FOR_STARTED_STATUS = true ]
943    then
944        waitforwrapperstop
945    fi
946}
947
948console() {
949    eval echo "`gettext 'Running $APP_LONG_NAME'`..."
950    getpid
951    if [ "X$pid" = "X" ]
952    then
953        trap '' 3 2
954
955        prepAdditionalParams "$@"
956        create_config_dir
957
958        # The string passed to eval must handles spaces in paths correctly.
959        COMMAND_LINE="$CMDNICE \"$WRAPPER_CMD\" \"$WRAPPER_CONF\" wrapper.syslog.ident=\"$APP_NAME\" wrapper.java.command=\"$JAVABINARY\" wrapper.pidfile=\"$PIDFILE\" wrapper.name=\"$APP_NAME\" wrapper.displayname=\"$APP_LONG_NAME\" $ANCHORPROP $STATUSPROP $COMMANDPROP $LOCKPROP $LOGPROP $ADDITIONAL_PARA"
960        eval $COMMAND_LINE || failed
961    else
962        eval echo `gettext '$APP_LONG_NAME is already running.'`
963        exit 1
964    fi
965}
966
967waitforjavastartup() {
968    getstatus
969    eval echo $ECHOOPT "`gettext 'Waiting for $APP_LONG_NAME'`..."
970
971    # Wait until the timeout or we have something besides Unknown.
972    counter=15
973    while [ "$JAVASTATUS" = "Unknown" -a $counter -gt 0 -a -n "$JAVASTATUS" ] ; do
974        echo $ECHOOPT"."
975        sleep 1
976        getstatus
977        counter=`expr $counter - 1`
978    done
979
980    if [ -n "$WAIT_FOR_STARTED_TIMEOUT" ] ; then
981        counter=$WAIT_FOR_STARTED_TIMEOUT
982    else
983        counter=120
984    fi
985    while [ "$JAVASTATUS" != "STARTED" -a "$JAVASTATUS" != "Unknown" -a $counter -gt 0 -a -n "$JAVASTATUS" ] ; do
986        echo $ECHOOPT"."
987        sleep 1
988        getstatus
989        counter=`expr $counter - 1`
990    done
991    if [ "X$ECHOOPT" != "X" ] ; then
992        echo ""
993    fi
994}
995
996startwait() {
997    if [ $WAIT_FOR_STARTED_STATUS = true ]
998    then
999        waitforjavastartup
1000    fi
1001    # Sleep for a few seconds to allow for intialization if required
1002    #  then test to make sure we're still running.
1003    #
1004    i=0
1005    while [ $i -lt $WAIT_AFTER_STARTUP ]
1006    do
1007        sleep 1
1008        echo $ECHOOPT"."
1009        i=`expr $i + 1`
1010    done
1011    if [ $WAIT_AFTER_STARTUP -gt 0 -o $WAIT_FOR_STARTED_STATUS = true ]
1012    then
1013        getpid
1014        if [ "X$pid" = "X" ]
1015        then
1016            eval echo " `gettext 'WARNING: $APP_LONG_NAME may have failed to start.'`"
1017            failed
1018        else
1019            eval echo ' running: PID:$pid'
1020        fi
1021    else
1022        echo ""
1023    fi
1024}
1025
1026macosxstart() {
1027    # The daemon has been installed.
1028    echo "Starting $APP_LONG_NAME.  Detected Mac OSX and installed launchd daemon."
1029    if [ `id | sed 's/^uid=//;s/(.*$//'` != "0" ] ; then
1030        eval echo `gettext 'Must be root to perform this action.'`
1031        exit 1
1032    fi
1033
1034    getpid
1035    if [ "X$pid" != "X" ] ; then
1036        eval echo `gettext '$APP_LONG_NAME is already running.'`
1037        exit 1
1038    fi
1039
1040    # If the daemon was just installed, it may not be loaded.
1041    LOADED_PLIST=`launchctl list | grep ${APP_PLIST_BASE}`
1042    if [ "X${LOADED_PLIST}" = "X" ] ; then
1043        launchctl load /Library/LaunchDaemons/${APP_PLIST}
1044    fi
1045    # If launchd is set to run the daemon already at Load, we don't need to call start
1046    getpid
1047    if [ "X$pid" = "X" ] ; then
1048        launchctl start ${APP_PLIST_BASE}
1049    fi
1050
1051    startwait
1052}
1053
1054upstartstart() {
1055    # The daemon has been installed.
1056    echo "Starting $APP_LONG_NAME.  Detected Linux and installed upstart."
1057    if [ `id | sed 's/^uid=//;s/(.*$//'` != "0" ] ; then
1058        eval echo `gettext 'Must be root to perform this action.'`
1059        exit 1
1060    fi
1061
1062    getpid
1063    if [ "X$pid" != "X" ] ; then
1064        eval echo `gettext '$APP_LONG_NAME is already running.'`
1065        exit 1
1066    fi
1067
1068    /sbin/start ${APP_NAME}
1069
1070    startwait
1071}
1072
1073start() {
1074    eval echo "`gettext 'Starting $APP_LONG_NAME'`..."
1075    getpid
1076    if [ "X$pid" = "X" ]
1077    then
1078        prepAdditionalParams "$@"
1079        create_config_dir
1080
1081        # The string passed to eval must handles spaces in paths correctly.
1082        COMMAND_LINE="$CMDNICE \"$WRAPPER_CMD\" \"$WRAPPER_CONF\" wrapper.syslog.ident=\"$APP_NAME\" wrapper.java.command=\"$JAVABINARY\" wrapper.pidfile=\"$PIDFILE\" wrapper.name=\"$APP_NAME\" wrapper.displayname=\"$APP_LONG_NAME\" wrapper.daemonize=TRUE $ANCHORPROP $IGNOREPROP $STATUSPROP $COMMANDPROP $LOCKPROP $LOGPROP $ADDITIONAL_PARA"
1083        eval $COMMAND_LINE || failed
1084    else
1085        eval echo `gettext '$APP_LONG_NAME is already running.'`
1086        exit 1
1087    fi
1088
1089    startwait
1090}
1091
1092
1093stopit() {
1094    # $1 exit if down flag
1095
1096    eval echo "`gettext 'Stopping $APP_LONG_NAME'`..."
1097    getpid
1098    if [ "X$pid" = "X" ]
1099    then
1100        eval echo `gettext '$APP_LONG_NAME was not running.'`
1101        if [ "X$1" = "X1" ]
1102        then
1103            exit 1
1104        fi
1105    else
1106        if [ "X$IGNORE_SIGNALS" = "X" ]
1107        then
1108            # Running so try to stop it.
1109            kill -TERM $pid
1110            if [ $? -ne 0 ]
1111            then
1112                # An explanation for the failure should have been given
1113                eval echo `gettext 'Unable to stop $APP_LONG_NAME.'`
1114                exit 1
1115            fi
1116        else
1117            rm -f "$ANCHORFILE"
1118            if [ -f "$ANCHORFILE" ]
1119            then
1120                # An explanation for the failure should have been given
1121                eval echo `gettext 'Unable to stop $APP_LONG_NAME.'`
1122                exit 1
1123            fi
1124        fi
1125
1126        # We can not predict how long it will take for the wrapper to
1127        #  actually stop as it depends on settings in wrapper.conf.
1128        #  Loop until it does.
1129        savepid=$pid
1130        CNT=0
1131        TOTCNT=0
1132        while [ "X$pid" != "X" ]
1133        do
1134            # Show a waiting message every 5 seconds.
1135            if [ "$CNT" -lt "5" ]
1136            then
1137                CNT=`expr $CNT + 1`
1138            else
1139                eval echo "`gettext 'Waiting for $APP_LONG_NAME to exit'`..."
1140                CNT=0
1141            fi
1142            TOTCNT=`expr $TOTCNT + 1`
1143
1144            sleep 1
1145
1146            testpid
1147        done
1148
1149        pid=$savepid
1150        testpid
1151        if [ "X$pid" != "X" ]
1152        then
1153            eval echo `gettext 'Failed to stop $APP_LONG_NAME.'`
1154            exit 1
1155        else
1156            eval echo `gettext 'Stopped $APP_LONG_NAME.'`
1157        fi
1158    fi
1159}
1160
1161graceful() {
1162    # $1 exit if down flag
1163
1164    eval echo "`gettext 'Stopping $APP_LONG_NAME gracefully'`..."
1165    getpid
1166    if [ "X$pid" = "X" ]
1167    then
1168        eval echo `gettext '$APP_LONG_NAME was not running.'`
1169        if [ "X$1" = "X1" ]
1170        then
1171            exit 1
1172        fi
1173    else
1174        if [ "X$IGNORE_SIGNALS" = "X" ]
1175        then
1176            # Running so try to stop it.
1177            # This sends HUP. router.gracefulHUP must be set in router.config,
1178            # or else this will do the same as stop.
1179            kill -HUP $pid
1180            if [ $? -ne 0 ]
1181            then
1182                # An explanation for the failure should have been given
1183                eval echo `gettext 'Unable to stop $APP_LONG_NAME.'`
1184                exit 1
1185            fi
1186        else
1187            rm -f "$ANCHORFILE"
1188            if [ -f "$ANCHORFILE" ]
1189            then
1190                # An explanation for the failure should have been given
1191                eval echo `gettext 'Unable to stop $APP_LONG_NAME.'`
1192                exit 1
1193            fi
1194        fi
1195    fi
1196}
1197
1198pause() {
1199    echo "Pausing $APP_LONG_NAME."
1200}
1201
1202resume() {
1203    echo "Resuming $APP_LONG_NAME."
1204}
1205
1206status() {
1207    getpid
1208    if [ "X$pid" = "X" ]
1209    then
1210        eval echo `gettext '$APP_LONG_NAME is not running.'`
1211        exit 1
1212    else
1213        if [ "X$DETAIL_STATUS" = "X" ]
1214        then
1215            eval echo `gettext '$APP_LONG_NAME is running: PID:$pid'`
1216        else
1217            getstatus
1218            eval echo `gettext '$APP_LONG_NAME is running: PID:$pid, Wrapper:$STATUS, Java:$JAVASTATUS'`
1219        fi
1220        exit 0
1221    fi
1222}
1223
1224installUpstart() {
1225    echo " Installing the $APP_LONG_NAME daemon using upstart.."
1226    if [ -f "${APP_NAME}.conf" ] ; then
1227        echo " a custom upstart conf file ${APP_NAME}.conf found"
1228        cp "${REALDIR}/${APP_NAME}.install" "/etc/init/${APP_NAME}.conf"
1229    else
1230        echo ' creating default upstart conf file..'
1231        echo "# ${APP_NAME} - ${APP_LONG_NAME}" > "/etc/init/${APP_NAME}.conf"
1232        echo "description \"${APP_LONG_NAME}\"" >> "/etc/init/${APP_NAME}.conf"
1233        echo "author \"Tanuki Software Ltd. <info@tanukisoftware.com>\"" >> "/etc/init/${APP_NAME}.conf"
1234        echo "start on runlevel [2345]" >> "/etc/init/${APP_NAME}.conf"
1235        echo "stop on runlevel [!2345]" >> "/etc/init/${APP_NAME}.conf"
1236        echo "env LANG=${LANG}" >> "/etc/init/${APP_NAME}.conf"
1237       echo "exec \"${REALPATH}\" launchdinternal" >> "/etc/init/${APP_NAME}.conf"
1238    fi
1239}
1240
1241installsystemd() {
1242    if [ -d "/etc/systemd/system/" ]; then
1243        cat << EOF >> "$SYSTEMD_SERVICE"
1244[Unit]
1245Description=$APP_LONG_NAME
1246After= local-fs.target network.target
1247
1248[Service]
1249Type=forking
1250ExecStart=$I2P/i2prouter start
1251ExecReload=$I2P/i2prouter restart
1252ExecStop=$I2P/i2prouter stop
1253PIDFile=$I2P_CONFIG_DIR/i2p.pid
1254
1255[Install]
1256WantedBy=multi-user.target
1257EOF
1258    systemctl --system daemon-reload > /dev/null 2>&1
1259    fi
1260}
1261
1262installdaemon() {
1263    if [ `id | sed 's/^uid=//;s/(.*$//'` != "0" ] ; then
1264        eval echo `gettext 'Must be root to perform this action.'`
1265        exit 1
1266    else
1267        APP_NAME_LOWER=`echo "$APP_NAME" | $TREXE "[A-Z]" "[a-z]"`
1268        if [ "$DIST_OS" = "solaris" ] ; then
1269            echo 'Detected Solaris:'
1270            if [ -f /etc/init.d/$APP_NAME ] ; then
1271                eval echo " `gettext 'The $APP_LONG_NAME daemon is already installed.'`"
1272                exit 1
1273            else
1274                eval echo " `gettext 'Installing the $APP_LONG_NAME daemon'`.."
1275                ln -s "$REALPATH" "/etc/init.d/$APP_NAME"
1276                ln -s "/etc/init.d/$APP_NAME" "/etc/rc3.d/K20$APP_NAME_LOWER"
1277                ln -s "/etc/init.d/$APP_NAME" "/etc/rc3.d/S20$APP_NAME_LOWER"
1278            fi
1279        elif [ "$DIST_OS" = "linux" ] ; then
1280            if [ -f /etc/redhat-release -o -f /etc/redhat_version -o -f /etc/fedora-release ]  ; then
1281                echo 'Detected RHEL or Fedora:'
1282                if [ -f "/etc/init.d/$APP_NAME" -o -f "/etc/init/${APP_NAME}.conf" ] ; then
1283                    eval echo " `gettext 'The $APP_LONG_NAME daemon is already installed.'`"
1284                    exit 1
1285                else
1286                    if [ -n "$USE_UPSTART" -a -d "/etc/init" ] ; then
1287                        installUpstart
1288                    else
1289                        eval echo " `gettext 'Installing the $APP_LONG_NAME daemon'`.."
1290                        ln -s "$REALPATH" "/etc/init.d/$APP_NAME"
1291                        /sbin/chkconfig --add "$APP_NAME"
1292                        /sbin/chkconfig "$APP_NAME" on
1293                    fi
1294                fi
1295            elif [ -f /etc/slackware-version ]; then
1296                echo 'Detected Slackware Linux:'
1297                if [ -e "/etc/rc.d/rc.i2p" -o -f "/etc/rc.d/rc.i2p.new" ]; then
1298                    echo "Found initscript from I2P Slackpkg. Aborting." >&2
1299                    exit 1
1300                else
1301                    if grep -q ${APP_NAME}router /etc/rc.d/rc.local > /dev/null 2>&1; then
1302                        eval echo " `gettext 'The $APP_LONG_NAME daemon is already installed.'`"
1303                        exit 1
1304                    else
1305                        echo "${REALDIR}/${APP_NAME}router start"  >> /etc/rc.d/rc.local
1306                        if [ ! -e /etc/rc.d/rc.local_shutdown ]; then
1307                            echo "#!/bin/sh" >> /etc/rc.d/rc.local_shutdown
1308                        fi
1309                        echo "${REALDIR}/${APP_NAME}router stop"  >> /etc/rc.d/rc.local_shutdown
1310                        chmod 755 /etc/rc.d/rc.local_shutdown
1311                    fi
1312                fi
1313            elif [ -f /etc/arch-release ]; then
1314            echo 'Detected Arch Linux:'
1315                if [ -f "/etc/rc.d/i2prouter" -o -f "/usr/lib/systemd/system/i2prouter.service" ]; then
1316                    echo 'AUR package found. Refusing to continue.'
1317                    exit 1
1318                elif [ -f /etc/rc.d/i2p -a ! "$USE_SYSTEMD" = "1" ] || [ -f "$SYSTEMD_SERVICE" -a "$USE_SYSTEMD" = "1" ]; then
1319                    eval echo " `gettext 'The $APP_LONG_NAME daemon is already installed.'`"
1320                    exit 1
1321                else
1322                        if [ ! -f "/etc/init.d/i2p" ]; then
1323                            if [ "$USE_SYSTEMD" != "1" ]; then
1324                                echo "#!/bin/bash"  > /etc/rc.d/${APP_NAME}
1325                                echo   >> /etc/rc.d/${APP_NAME}
1326                                echo ". /etc/rc.conf"  >> /etc/rc.d/${APP_NAME}
1327                                echo ". /etc/rc.d/functions"  >> /etc/rc.d/${APP_NAME}
1328                                echo   >> /etc/rc.d/${APP_NAME}
1329                                echo "case "\$1" in"  >> /etc/rc.d/${APP_NAME}
1330                                echo "  start)"  >> /etc/rc.d/${APP_NAME}
1331                                echo "    stat_busy \"Starting i2p-Router\""  >> /etc/rc.d/${APP_NAME}
1332                                echo "    ${REALDIR}/${APP_NAME}router start >/dev/null 2>&1"  >> /etc/rc.d/${APP_NAME}
1333                                echo "    if [ \$? -gt 0 ]; then"  >> /etc/rc.d/${APP_NAME}
1334                                echo "      stat_fail"  >> /etc/rc.d/${APP_NAME}
1335                                echo "    else"  >> /etc/rc.d/${APP_NAME}
1336                                echo "      stat_done"  >> /etc/rc.d/${APP_NAME}
1337                                echo "      add_daemon i2prouter"  >> /etc/rc.d/${APP_NAME}
1338                                echo "    fi"  >> /etc/rc.d/${APP_NAME}
1339                                echo "    ;;"  >> /etc/rc.d/${APP_NAME}
1340                                echo "  stop)"  >> /etc/rc.d/${APP_NAME}
1341                                echo "    stat_busy "Stopping i2p-Router""  >> /etc/rc.d/${APP_NAME}
1342                                echo "    ${REALDIR}/${APP_NAME}router stop > /dev/null 2>&1"  >> /etc/rc.d/${APP_NAME}
1343                                echo "    if [ \$? -gt 0 ]; then"  >> /etc/rc.d/${APP_NAME}
1344                                echo "      stat_fail"  >> /etc/rc.d/${APP_NAME}
1345                                echo "    else"  >> /etc/rc.d/${APP_NAME}
1346                                echo "      stat_done"  >> /etc/rc.d/${APP_NAME}
1347                                echo "      rm_daemon i2prouter"  >> /etc/rc.d/${APP_NAME}
1348                                echo "    fi"  >> /etc/rc.d/${APP_NAME}
1349                                echo "    ;;"  >> /etc/rc.d/${APP_NAME}
1350                                echo "  restart)"  >> /etc/rc.d/${APP_NAME}
1351                                echo "    ${REALDIR}/${APP_NAME}router restart"  >> /etc/rc.d/${APP_NAME}
1352                                echo "    ;;"  >> /etc/rc.d/${APP_NAME}
1353                                echo "  console)"  >> /etc/rc.d/${APP_NAME}
1354                                echo "    ${REALDIR}/${APP_NAME}router console"  >> /etc/rc.d/${APP_NAME}
1355                                echo "    ;;"  >> /etc/rc.d/${APP_NAME}
1356                                echo "  status)"  >> /etc/rc.d/${APP_NAME}
1357                                echo "    ${REALDIR}/${APP_NAME}router status"  >> /etc/rc.d/${APP_NAME}
1358                                echo "    ;;"  >> /etc/rc.d/${APP_NAME}
1359                                echo "  dump)"  >> /etc/rc.d/${APP_NAME}
1360                                echo "    ${REALDIR}/${APP_NAME}router dump"  >> /etc/rc.d/${APP_NAME}
1361                                echo "    ;;"  >> /etc/rc.d/${APP_NAME}
1362                                echo "  graceful)"  >> /etc/rc.d/${APP_NAME}
1363                                echo "    ${REALDIR}/${APP_NAME}router graceful"  >> /etc/rc.d/${APP_NAME}
1364                                echo "    ;;"  >> /etc/rc.d/${APP_NAME}
1365                                echo "  *)"  >> /etc/rc.d/${APP_NAME}
1366                                echo "    echo \"usage: \$0 {start|stop|restart|console|status|dump}\""  >> /etc/rc.d/${APP_NAME}
1367                                echo "    ;;"  >> /etc/rc.d/${APP_NAME}
1368                                echo "esac"  >> /etc/rc.d/${APP_NAME}
1369                                chmod 755 /etc/rc.d/${APP_NAME}
1370                                chown root:root /etc/rc.d/${APP_NAME}
1371                                echo " The $APP_LONG_NAME daemon has been installed."
1372                                echo ' Add \"i2p\" to the DAEMONS variable in /etc/rc.conf to enable.'
1373                            else
1374                                # We'll end up here if systemd is enabled.
1375                                # If systemd is enabled we don't need the initscript
1376                                rm -f /etc/rc.d/${APP_NAME}
1377                            fi
1378                        fi
1379                        if [ ! -f "${SYSTEMD_SERVICE}" ]; then
1380                            installsystemd
1381                        fi
1382                fi
1383            elif [ -f /etc/SuSE-release ] ; then
1384                echo 'Detected SuSE or SLES:'
1385                 if [ -f /etc/rc.d/${APP_NAME} -a ! "$USE_SYSTEMD" = "1" ] || [ -f "$SYSTEMD_SERVICE" -a "$USE_SYSTEMD" = "1" ]; then
1386                    eval echo " `gettext 'The $APP_LONG_NAME daemon is already installed.'`"
1387                    exit 1
1388                else
1389                    if [ ! -f "/etc/init.d/$APP_NAME" ]; then
1390                        if [ "$USE_SYSTEMD" != "1" ]; then
1391                            eval echo " `gettext 'Installing the $APP_LONG_NAME daemon'`.."
1392                            ln -s "$REALPATH" "/etc/init.d/$APP_NAME"
1393                            sed -i "s/Default-Start: 2 3 4 5/Default-Start: 5/" $0
1394                            insserv "/etc/init.d/$APP_NAME"
1395                        else
1396                            rm -f "/etc/init.d/$APP_NAME"
1397                        fi
1398                    fi
1399                    if [ ! -f "${SYSTEMD_SERVICE}" ]; then
1400                        installsystemd
1401                    fi
1402                fi
1403            elif [ -f /etc/lsb-release -o -f /etc/debian_version ] ; then
1404                echo 'Detected Debian-based distribution:'
1405                if [ -f "/etc/init.d/$APP_NAME" -o -f "/etc/init/${APP_NAME}.conf" ] ; then
1406                    eval echo " `gettext 'The $APP_LONG_NAME daemon is already installed.'`"
1407                    exit 1
1408                else
1409                    if [ -n "$USE_UPSTART" -a -d "/etc/init" ] ; then
1410                        installUpstart
1411                    else
1412                        echo " Installing the $APP_LONG_NAME daemon using init.d.."
1413                        ln -s "$REALPATH" "/etc/init.d/$APP_NAME"
1414                        update-rc.d "$APP_NAME" defaults
1415                    fi
1416                fi
1417            else
1418                echo 'Detected Linux:'
1419                if [ -f "/etc/init.d/$APP_NAME" ] ; then
1420                    eval echo " `gettext 'The $APP_LONG_NAME daemon is already installed.'`"
1421                    exit 1
1422                else
1423                    eval echo " `gettext 'Installing the $APP_LONG_NAME daemon'`.."
1424                    ln -s "$REALPATH" /etc/init.d/$APP_NAME
1425                    ln -s "/etc/init.d/$APP_NAME" "/etc/rc3.d/K20$APP_NAME_LOWER"
1426                    ln -s "/etc/init.d/$APP_NAME" "/etc/rc3.d/S20$APP_NAME_LOWER"
1427                    ln -s "/etc/init.d/$APP_NAME" "/etc/rc5.d/S20$APP_NAME_LOWER"
1428                    ln -s "/etc/init.d/$APP_NAME" "/etc/rc5.d/K20$APP_NAME_LOWER"
1429                fi
1430            fi
1431        elif [ "$DIST_OS" = "hpux" ] ; then
1432            echo 'Detected HP-UX:'
1433            if [ -f "/sbin/init.d/$APP_NAME" ] ; then
1434                eval echo " `gettext 'The $APP_LONG_NAME daemon is already installed.'`"
1435                exit 1
1436            else
1437                eval echo " `gettext 'Installing the $APP_LONG_NAME daemon'`.."
1438                ln -s "$REALPATH" "/sbin/init.d/$APP_NAME"
1439                ln -s "/sbin/init.d/$APP_NAME" "/sbin/rc3.d/K20$APP_NAME_LOWER"
1440                ln -s "/sbin/init.d/$APP_NAME" "/sbin/rc3.d/S20$APP_NAME_LOWER"
1441            fi
1442        elif [ "$DIST_OS" = "aix" ] ; then
1443            echo 'Detected AIX:'
1444            if [ -f "/etc/rc.d/init.d/$APP_NAME" ] ; then
1445                echo " The $APP_LONG_NAME daemon is already installed as rc.d script."
1446                exit 1
1447            elif [ -n "`/usr/sbin/lsitab $APP_NAME`" -a -n "`/usr/bin/lssrc -S -s $APP_NAME`" ] ; then
1448                echo " The $APP_LONG_NAME daemon is already installed as SRC service."
1449                exit 1
1450            else
1451                eval echo " `gettext 'Installing the $APP_LONG_NAME daemon'`.."
1452                if [ -n "`/usr/sbin/lsitab install_assist`" ] ; then
1453                    echo ' The task /usr/sbin/install_assist was found in the inittab, this might cause problems for all subsequent tasks to launch at this process is known to block the init task. Please make sure this task is not needed anymore and remove/deactivate it.'
1454                fi
1455                /usr/bin/mkssys -s "$APP_NAME" -p "$REALPATH" -a "launchdinternal" -u 0 -f 9 -n 15 -S
1456                /usr/sbin/mkitab "$APP_NAME":2:once:"/usr/bin/startsrc -s \"${APP_NAME}\" >/dev/console 2>&1"
1457
1458            fi
1459        elif [ "$DIST_OS" = "freebsd" ] ; then
1460            echo 'Detected FreeBSD:'
1461            if [ -f "/etc/rc.d/$APP_NAME" ] ; then
1462                eval echo " `gettext 'The $APP_LONG_NAME daemon is already installed.'`"
1463                exit 1
1464            else
1465                eval echo " `gettext 'Installing the $APP_LONG_NAME daemon'`.."
1466                sed -i .bak "/${APP_NAME}_enable=\"YES\"/d" /etc/rc.conf
1467                if [ -f "${REALDIR}/${APP_NAME}.install" ] ; then
1468                    ln -s "${REALDIR}/${APP_NAME}.install" "/etc/rc.d/$APP_NAME"
1469                else
1470                    echo '#!/bin/sh' > "/etc/rc.d/$APP_NAME"
1471                    echo "#" >> "/etc/rc.d/$APP_NAME"
1472                    echo "# PROVIDE: $APP_NAME" >> "/etc/rc.d/$APP_NAME"
1473                    echo "# REQUIRE: NETWORKING" >> "/etc/rc.d/$APP_NAME"
1474                    echo "# KEYWORD: shutdown" >> "/etc/rc.d/$APP_NAME"
1475                    echo ". /etc/rc.subr" >> "/etc/rc.d/$APP_NAME"
1476                    echo "name=\"$APP_NAME\"" >> "/etc/rc.d/$APP_NAME"
1477                    echo "rcvar=\`set_rcvar\`" >> "/etc/rc.d/$APP_NAME"
1478                    echo "command=\"${REALDIR}/${APP_NAME}router\"" >> "/etc/rc.d/$APP_NAME"
1479                    echo 'start_cmd="${name}_start"' >> "/etc/rc.d/$APP_NAME"
1480                    echo 'load_rc_config $name' >> "/etc/rc.d/$APP_NAME"
1481                    echo 'status_cmd="${name}_status"' >> "/etc/rc.d/$APP_NAME"
1482                    echo 'stop_cmd="${name}_stop"' >> "/etc/rc.d/$APP_NAME"
1483                    echo "${APP_NAME}_status() {" >> "/etc/rc.d/$APP_NAME"
1484                    echo '${command} status' >> "/etc/rc.d/$APP_NAME"
1485                    echo '}' >> "/etc/rc.d/$APP_NAME"
1486                    echo "${APP_NAME}_stop() {" >> "/etc/rc.d/$APP_NAME"
1487                    echo '${command} stop' >> "/etc/rc.d/$APP_NAME"
1488                    echo '}' >> "/etc/rc.d/$APP_NAME"
1489                    echo "${APP_NAME}_start() {" >> "/etc/rc.d/$APP_NAME"
1490                    echo '${command} start' >> "/etc/rc.d/$APP_NAME"
1491                    echo '}' >> "/etc/rc.d/$APP_NAME"
1492                    echo 'run_rc_command "$1"' >> "/etc/rc.d/$APP_NAME"
1493                fi
1494                echo "${APP_NAME}_enable=\"YES\"" >> /etc/rc.conf
1495                chmod 555 "/etc/rc.d/$APP_NAME"
1496            fi
1497        elif [ "$DIST_OS" = "macosx" ] ; then
1498            echo 'Detected Mac OSX:'
1499            if [ -f "/Library/LaunchDaemons/${APP_PLIST}" ] ; then
1500                eval echo " `gettext 'The $APP_LONG_NAME daemon is already installed.'`"
1501                exit 1
1502            else
1503                eval echo " `gettext 'Installing the $APP_LONG_NAME daemon'`.."
1504                if [ -f "${REALDIR}/${APP_PLIST}" ] ; then
1505                    ln -s "${REALDIR}/${APP_PLIST}" "/Library/LaunchDaemons/${APP_PLIST}"
1506                else
1507                    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > "/Library/LaunchDaemons/${APP_PLIST}"
1508                    echo "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\"" >> "/Library/LaunchDaemons/${APP_PLIST}"
1509                    echo "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">" >> "/Library/LaunchDaemons/${APP_PLIST}"
1510                    echo "<plist version=\"1.0\">" >> "/Library/LaunchDaemons/${APP_PLIST}"
1511                    echo "    <dict>" >> "/Library/LaunchDaemons/${APP_PLIST}"
1512                    echo "        <key>Label</key>" >> "/Library/LaunchDaemons/${APP_PLIST}"
1513                    echo "        <string>${APP_PLIST_BASE}</string>" >> "/Library/LaunchDaemons/${APP_PLIST}"
1514                    echo "        <key>ProgramArguments</key>" >> "/Library/LaunchDaemons/${APP_PLIST}"
1515                    echo "        <array>" >> "/Library/LaunchDaemons/${APP_PLIST}"
1516                    echo "            <string>${REALDIR}/${APP_NAME}router</string>" >> "/Library/LaunchDaemons/${APP_PLIST}"
1517                    echo "            <string>launchdinternal</string>" >> "/Library/LaunchDaemons/${APP_PLIST}"
1518                    echo "        </array>" >> "/Library/LaunchDaemons/${APP_PLIST}"
1519                    echo "        <key>OnDemand</key>" >> "/Library/LaunchDaemons/${APP_PLIST}"
1520                    echo "        <true/>" >> "/Library/LaunchDaemons/${APP_PLIST}"
1521                    echo "        <key>RunAtLoad</key>" >> "/Library/LaunchDaemons/${APP_PLIST}"
1522                    echo "        <true/>" >> "/Library/LaunchDaemons/${APP_PLIST}"
1523                    if [ "X$RUN_AS_USER" != "X" ] ; then
1524                        echo "        <key>UserName</key>" >> "/Library/LaunchDaemons/${APP_PLIST}"
1525                        echo "        <string>${RUN_AS_USER}</string>" >> "/Library/LaunchDaemons/${APP_PLIST}"
1526                    fi
1527                    echo "    </dict>" >> "/Library/LaunchDaemons/${APP_PLIST}"
1528                    echo "</plist>" >> "/Library/LaunchDaemons/${APP_PLIST}"
1529                fi
1530                chmod 555 "/Library/LaunchDaemons/${APP_PLIST}"
1531            fi
1532        elif [ "$DIST_OS" = "zos" ] ; then
1533            echo 'Detected z/OS:'
1534            if [ -f /etc/rc.bak ] ; then
1535                eval echo " `gettext 'The $APP_LONG_NAME daemon is already installed.'`"
1536                exit 1
1537            else
1538                eval echo " `gettext 'Installing the $APP_LONG_NAME daemon'`.."
1539                cp /etc/rc /etc/rc.bak
1540                sed  "s:echo /etc/rc script executed, \`date\`::g" /etc/rc.bak > /etc/rc
1541                echo "_BPX_JOBNAME='${APP_NAME}' \"${REALDIR}/${APP_NAME}router\" start" >>/etc/rc
1542                echo '/etc/rc script executed, `date`' >>/etc/rc
1543            fi
1544        else
1545            eval echo `gettext 'Install not currently supported for $DIST_OS'`
1546            exit 1
1547        fi
1548    fi
1549}
1550
1551removedaemon() {
1552    if [ `id | sed 's/^uid=//;s/(.*$//'` != "0" ] ; then
1553        eval echo `gettext 'Must be root to perform this action.'`
1554        exit 1
1555    else
1556        stopit "0"
1557        APP_NAME_LOWER=`echo "$APP_NAME" | $TREXE "[A-Z]" "[a-z]"`
1558        if [ "$DIST_OS" = "solaris" ] ; then
1559            echo 'Detected Solaris:'
1560            if [ -f "/etc/init.d/$APP_NAME" ] ; then
1561                eval echo " `gettext 'Removing $APP_LONG_NAME daemon'`..."
1562                for i in "/etc/rc3.d/S20$APP_NAME_LOWER" "/etc/rc3.d/K20$APP_NAME_LOWER" "/etc/init.d/$APP_NAME"
1563                do
1564                    rm -f $i
1565                done
1566            else
1567                eval echo " `gettext 'The $APP_LONG_NAME daemon is not currently installed.'`"
1568                exit 1
1569            fi
1570        elif [ "$DIST_OS" = "linux" ] ; then
1571            if [ -f /etc/redhat-release -o -f /etc/redhat_version -o -f /etc/fedora-release ] ; then
1572                echo 'Detected RHEL or Fedora:'
1573                if [ -f "/etc/init.d/$APP_NAME" ] ; then
1574                    eval echo " `gettext 'Removing $APP_LONG_NAME daemon'`..."
1575                    /sbin/chkconfig "$APP_NAME" off
1576                    /sbin/chkconfig --del "$APP_NAME"
1577                    rm -f "/etc/init.d/$APP_NAME"
1578                elif [ -f "/etc/init/${APP_NAME}.conf" ] ; then
1579                    echo " Removing $APP_LONG_NAME daemon from upstart..."
1580                    rm "/etc/init/${APP_NAME}.conf"
1581                else
1582                    eval echo " `gettext 'The $APP_LONG_NAME daemon is not currently installed.'`"
1583                    exit 1
1584                fi
1585            elif [ -f /etc/slackware-version ] ; then
1586                echo 'Detected Slackware Linux:'
1587                if grep -q ${APP_NAME}router /etc/rc.d/rc.local > /dev/null 2>&1 ; then
1588                    eval echo " `gettext 'Removing $APP_LONG_NAME daemon'`..."
1589                    sed -i "/i2prouter/d" /etc/rc.d/rc.local /etc/rc.d/rc.local_shutdown
1590                else
1591                    eval echo " `gettext 'The $APP_LONG_NAME daemon is not currently installed.'`"
1592                    exit 1
1593                fi
1594            elif [ -f /etc/arch-release ] ; then
1595                echo 'Detected Arch Linux:'
1596                if [ -f "/etc/rc.d/$APP_NAME" -o -f "$SYSTEMD_SERVICE" ] ; then
1597                    eval echo "`gettext 'Removing $APP_LONG_NAME daemon'`..."
1598                    rm -f "/etc/rc.d/$APP_NAME"
1599                    rm -f "$SYSTEMD_SERVICE"
1600                else
1601                    eval echo " `gettext 'The $APP_LONG_NAME daemon is not currently installed.'`"
1602                    exit 1
1603                fi
1604            elif [ -f /etc/SuSE-release ] ; then
1605                echo 'Detected SuSE or SLES:'
1606                if [ -f "/etc/init.d/$APP_NAME" -o ${SYSTEMD_SERVICE} ] ; then
1607                    eval echo " `gettext 'Removing $APP_LONG_NAME daemon'`..."
1608                    insserv -r "/etc/init.d/$APP_NAME"
1609                    rm -f "/etc/init.d/$APP_NAME"
1610                    rm -f "$SYSTEMD_SERVICE"
1611                else
1612                    eval echo " `gettext 'The $APP_LONG_NAME daemon is not currently installed.'`"
1613                    exit 1
1614                fi
1615            elif [ -f /etc/lsb-release -o -f /etc/debian_version ] ; then
1616                echo 'Detected Debian-based distribution:'
1617                if [ -f "/etc/init.d/$APP_NAME" ] ; then
1618                    echo " Removing $APP_LONG_NAME daemon from init.d..."
1619                    update-rc.d -f "$APP_NAME" remove
1620                    rm -f "/etc/init.d/$APP_NAME"
1621                elif [ -f "/etc/init/${APP_NAME}.conf" ] ; then
1622                    echo " Removing $APP_LONG_NAME daemon from upstart..."
1623                    rm "/etc/init/${APP_NAME}.conf"
1624                else
1625                    eval echo " `gettext 'The $APP_LONG_NAME daemon is not currently installed.'`"
1626                    exit 1
1627                fi
1628            else
1629                echo 'Detected Linux:'
1630                if [ -f "/etc/init.d/$APP_NAME" ] ; then
1631                    eval echo " `gettext 'Removing $APP_LONG_NAME daemon'`..."
1632                    for i in "/etc/rc3.d/K20$APP_NAME_LOWER" "/etc/rc5.d/K20$APP_NAME_LOWER" "/etc/rc3.d/S20$APP_NAME_LOWER" "/etc/init.d/$APP_NAME" "/etc/rc5.d/S20$APP_NAME_LOWER"
1633                    do
1634                        rm -f $i
1635                    done
1636                else
1637                    eval echo " `gettext 'The $APP_LONG_NAME daemon is not currently installed.'`"
1638                    exit 1
1639                fi
1640            fi
1641        elif [ "$DIST_OS" = "hpux" ] ; then
1642            echo 'Detected HP-UX:'
1643            if [ -f "/sbin/init.d/$APP_NAME" ] ; then
1644                eval echo " `gettext 'Removing $APP_LONG_NAME daemon'`..."
1645                for i in "/sbin/rc3.d/K20$APP_NAME_LOWER" "/sbin/rc3.d/S20$APP_NAME_LOWER" "/sbin/init.d/$APP_NAME"
1646                do
1647                    rm -f $i
1648                done
1649            else
1650                eval echo " `gettext 'The $APP_LONG_NAME daemon is not currently installed.'`"
1651                exit 1
1652            fi
1653        elif [ "$DIST_OS" = "aix" ] ; then
1654            echo 'Detected AIX:'
1655            if [ -f "/etc/rc.d/init.d/$APP_NAME" -o -n "`/usr/sbin/lsitab $APP_NAME`" -o -n "`/usr/bin/lssrc -S -s $APP_NAME`" ] ; then
1656                eval echo " `gettext 'Removing $APP_LONG_NAME daemon'`..."
1657                if [ -f "/etc/rc.d/init.d/$APP_NAME" ] ; then
1658                    for i in "/etc/rc.d/rc2.d/S20$APP_NAME_LOWER" "/etc/rc.d/rc2.d/K20$APP_NAME_LOWER" "/etc/rc.d/init.d/$APP_NAME"
1659                    do
1660                        rm -f $i
1661                    done
1662                fi
1663                if [ -n "`/usr/sbin/lsitab $APP_NAME`" -o -n "`/usr/bin/lssrc -S -s $APP_NAME`" ] ; then
1664                    /usr/sbin/rmitab $APP_NAME
1665                    /usr/bin/rmssys -s $APP_NAME
1666                fi
1667            else
1668                eval echo " `gettext 'The $APP_LONG_NAME daemon is not currently installed.'`"
1669                exit 1
1670            fi
1671        elif [ "$DIST_OS" = "freebsd" ] ; then
1672            echo 'Detected FreeBSD:'
1673            if [ -f "/etc/rc.d/$APP_NAME" ] ; then
1674                eval echo " `gettext 'Removing $APP_LONG_NAME daemon'`..."
1675                for i in "/etc/rc.d/$APP_NAME"
1676                do
1677                    rm -f $i
1678                done
1679                sed -i .bak "/${APP_NAME}_enable=\"YES\"/d" /etc/rc.conf
1680            else
1681                eval echo " `gettext 'The $APP_LONG_NAME daemon is not currently installed.'`"
1682                exit 1
1683            fi
1684        elif [ "$DIST_OS" = "macosx" ] ; then
1685            echo 'Detected Mac OSX:'
1686            if [ -f "/Library/LaunchDaemons/${APP_PLIST}" ] ; then
1687                eval echo " `gettext 'Removing $APP_LONG_NAME daemon'`..."
1688                # Make sure the plist is installed
1689                LOADED_PLIST=`launchctl list | grep ${APP_PLIST_BASE}`
1690                if [ "X${LOADED_PLIST}" != "X" ] ; then
1691                    launchctl unload "/Library/LaunchDaemons/${APP_PLIST}"
1692                fi
1693                rm -f "/Library/LaunchDaemons/${APP_PLIST}"
1694            else
1695                eval echo " `gettext 'The $APP_LONG_NAME daemon is not currently installed.'`"
1696                exit 1
1697            fi
1698        elif [ "$DIST_OS" = "zos" ] ; then
1699            echo 'Detected z/OS:'
1700            if [ -f /etc/rc.bak ] ; then
1701                eval echo " `gettext 'Removing $APP_LONG_NAME daemon'`..."
1702                cp /etc/rc /etc/rc.bak
1703                sed  "s/_BPX_JOBNAME=\'APP_NAME\'.*//g" /etc/rc.bak > /etc/rc
1704                rm /etc/rc.bak
1705            else
1706                eval echo " `gettext 'The $APP_LONG_NAME daemon is not currently installed.'`"
1707                exit 1
1708            fi
1709        else
1710            eval echo `gettext 'Remove not currently supported for $DIST_OS'`
1711            exit 1
1712        fi
1713    fi
1714}
1715
1716dump() {
1717    echo "Dumping $APP_LONG_NAME..."
1718    getpid
1719    if [ "X$pid" = "X" ]
1720    then
1721        eval echo `gettext '$APP_LONG_NAME was not running.'`
1722    else
1723        kill -3 $pid
1724
1725        if [ $? -ne 0 ]
1726        then
1727            echo "Failed to dump $APP_LONG_NAME."
1728            exit 1
1729        else
1730            echo "Dumped $APP_LONG_NAME."
1731        fi
1732    fi
1733}
1734
1735# Used by HP-UX init scripts.
1736startmsg() {
1737    getpid
1738    if [ "X$pid" = "X" ]
1739    then
1740        echo "Starting $APP_LONG_NAME...  Wrapper:Stopped"
1741    else
1742        if [ "X$DETAIL_STATUS" = "X" ]
1743        then
1744            echo "Starting $APP_LONG_NAME...  Wrapper:Running"
1745        else
1746            getstatus
1747            echo "Starting $APP_LONG_NAME...  Wrapper:$STATUS, Java:$JAVASTATUS"
1748        fi
1749    fi
1750}
1751
1752# Used by HP-UX init scripts.
1753stopmsg() {
1754    getpid
1755    if [ "X$pid" = "X" ]
1756    then
1757        echo "Stopping $APP_LONG_NAME...  Wrapper:Stopped"
1758    else
1759        if [ "X$DETAIL_STATUS" = "X" ]
1760        then
1761            echo "Stopping $APP_LONG_NAME...  Wrapper:Running"
1762        else
1763            getstatus
1764            echo "Stopping $APP_LONG_NAME...  Wrapper:$STATUS, Java:$JAVASTATUS"
1765        fi
1766    fi
1767}
1768
1769showUsage() {
1770    # $1 bad command
1771
1772    if [ -n "$1" ]
1773    then
1774        echo "Unexpected command: $1"
1775        echo "";
1776    fi
1777
1778    MSG='Usage: '
1779    if [ -n "$FIXED_COMMAND" ] ; then
1780        if [ -n "$PASS_THROUGH" ] ; then
1781            echo "${MSG} $0 {JavaAppArgs}"
1782        else
1783            echo "${MSG} $0"
1784        fi
1785    else
1786            if [ -n "$PASS_THROUGH" ] ; then
1787                echo "${MSG} $0 [ console {JavaAppArgs} | start {JavaAppArgs} | stop | restart {JavaAppArgs} | condrestart {JavaAppArgs} | status | install | remove | dump ]"
1788            else
1789                echo "${MSG} $0 [ console | start | stop | graceful | restart | condrestart | status | install | remove | dump ]"
1790        fi
1791    fi
1792
1793    if [ ! -n "$BRIEF_USAGE" ]
1794    then
1795        echo "";
1796        if [ ! -n "$FIXED_COMMAND" ] ; then
1797            echo "`gettext 'Commands:'`"
1798            echo "  console      `gettext 'Launch in the current console.'`"
1799            echo "  start        `gettext 'Start in the background as a daemon process.'`"
1800            echo "  stop         `gettext 'Stop if running as a daemon or in another console.'`"
1801            echo "  graceful     `gettext 'Stop gracefully, may take up to 11 minutes.'`"
1802            echo "  restart      `gettext 'Stop if running and then start.'`"
1803            echo "  condrestart  `gettext 'Restart only if already running.'`"
1804            echo "  status       `gettext 'Query the current status.'`"
1805            echo "  install      `gettext 'Install to start automatically when system boots.'`"
1806            echo "  remove       `gettext 'Uninstall.'`"
1807            echo "  dump         `gettext 'Request a Java thread dump if running.'`"
1808            echo "";
1809        fi
1810        if [ -n "$PASS_THROUGH" ] ; then
1811            echo "JavaAppArgs: Zero or more arguments which will be passed to the Java application."
1812            echo "";
1813        fi
1814    fi
1815
1816    exit 1
1817}
1818
1819showsetusermesg()  {
1820    echo "`gettext 'Please edit i2prouter and set the variable RUN_AS_USER'`."
1821}
1822
1823checkifstartingasroot() {
1824    if [ ! `grep ^RUN_AS_USER $0` ] && [ ! `grep ^ALLOW_ROOT $0` ] && [ `id -ur` = '0' ]; then
1825        echo "`gettext 'Running I2P as the root user is *not* recommended.'`"
1826        showsetusermesg
1827        echo
1828        echo "`gettext 'To run as root anyway, edit i2prouter and set ALLOW_ROOT=true.'`"
1829        exit 1
1830    fi
1831}
1832
1833docommand() {
1834    case "$COMMAND" in
1835        'console')
1836            checkifstartingasroot
1837            checkUser touchlock "$@"
1838            if [ ! -n "$FIXED_COMMAND" ] ; then
1839                shift
1840            fi
1841            console "$@"
1842            ;;
1843
1844        'start')
1845            checkifstartingasroot
1846            if [ "$DIST_OS" = "macosx" -a -f "/Library/LaunchDaemons/${APP_PLIST}" ] ; then
1847                macosxstart
1848            elif [ "$DIST_OS" = "linux" -a -f "/etc/init/${APP_NAME}.conf" ] ; then
1849                checkUser touchlock "$@"
1850                upstartstart
1851            else
1852                checkUser touchlock "$@"
1853                if [ ! -n "$FIXED_COMMAND" ] ; then
1854                    shift
1855                fi
1856                start "$@"
1857            fi
1858            ;;
1859
1860        'stop')
1861            checkUser "" "$COMMAND"
1862            stopit "0"
1863            ;;
1864
1865        'graceful')
1866            checkUser "" "$COMMAND"
1867            graceful "0"
1868            ;;
1869
1870        'restart')
1871            checkUser touchlock "$COMMAND"
1872            if [ ! -n "$FIXED_COMMAND" ] ; then
1873                shift
1874            fi
1875            stopit "0"
1876            start "$@"
1877            ;;
1878
1879        'condrestart')
1880            checkUser touchlock "$COMMAND"
1881            if [ ! -n "$FIXED_COMMAND" ] ; then
1882                shift
1883            fi
1884            stopit "1"
1885            start "$@"
1886            ;;
1887
1888        'status')
1889            checkUser "" "$COMMAND"
1890            status
1891            ;;
1892
1893        'install')
1894            installdaemon
1895            if [ ! `grep ^RUN_AS_USER $0` ]; then
1896                 echo
1897                 showsetusermesg
1898            fi
1899            echo
1900            echo "You may want to disable the browser from launching at startup at"
1901            echo "http://127.0.0.1:7657/configclients"
1902            echo
1903            echo "I2P_CONFIG_DIR is currently set to $I2P_CONFIG_DIR."
1904            echo "Change the value in $0 if this is not"
1905            echo "appropriate for your configuration."
1906            ;;
1907
1908        'remove' | 'uninstall')
1909            removedaemon
1910            ;;
1911
1912        'dump')
1913            checkUser "" "$COMMAND"
1914            dump
1915            ;;
1916
1917        'start_msg')
1918            # Internal command called by launchd on HP-UX.
1919            checkUser "" "$COMMAND"
1920            startmsg
1921            ;;
1922
1923        'stop_msg')
1924            # Internal command called by launchd on HP-UX.
1925            checkUser "" "$COMMAND"
1926            stopmsg
1927            ;;
1928
1929        'launchdinternal')
1930            # Internal command called by launchd on Max OSX.
1931            # We do not want to call checkUser here as it is handled in the launchd plist file.  Doing it here would confuse launchd.
1932            if [ ! -n "$FIXED_COMMAND" ] ; then
1933                shift
1934            fi
1935            launchdinternal "$@"
1936            ;;
1937
1938        *)
1939            showUsage "$COMMAND"
1940            ;;
1941    esac
1942}
1943
1944docommand "$@"
1945
1946exit 0
Note: See TracBrowser for help on using the repository browser.