source: installer/resources/i2prouter @ cdafab27

Last change on this file since cdafab27 was cdafab27, checked in by zzz <zzz@…>, 4 years ago

Wrapper: Update to wrapper 3.5.29
All binaries from Tanuki delta pack,
except for armhf, compiled on Raspberry Pi:

ant 1.8.2
javac 1.6.0_38
gcc 4.6.3-14+rpi1

Windows binaries remain unchanged as we must recompile them ourselves
(32 bit just to change the icon; 64 bit is not provided by Tanuki)
Old 3.5.25 wrapper.jar moved to win-all, use it in windows-only installer
so it will be consistent with the old binaries.
Fixes wrapper failure on FreeBSD 10 (ticket #1118)
Minor i2prouter script fixes for FreeBSD 10, from anonimal (ticket #1118)

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