source: installer/resources/i2prouter @ 53ae4125

Last change on this file since 53ae4125 was 53ae4125, checked in by kytv <kytv@…>, 5 years ago

Add time-sync to the systemd unit created by i2prouter install (#1578)

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