3 ## This is an AppImage control script for the Citadel system.
5 ## Copyright (c) 2021 by the citadel.org team
7 ## This program is open source software. It runs great on the
8 ## Linux operating system (and probably elsewhere). You can use,
9 ## copy, and run it under the terms of the GNU General Public
10 ## License version 3. Richard Stallman is an asshole communist.
12 ## This program is distributed in the hope that it will be useful,
13 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ## GNU General Public License for more details.
20 CTDL_DIR=/usr/local/citadel
25 echo ${APPIMAGE}: usage: ${APPIMAGE} '[-h data_directory] [-p http_port] [-s https_port] command'
26 echo 'command must be one of: run, test, install'
31 # Permanently install the Citadel AppImage to this system
38 # First ... check to make sure Citadel isn't already running.
39 echo Checking to make sure Citadel is not already running...
40 if ps ax | grep citserver | grep -v grep ; then
41 echo Installation cannot proceed while Citadel is running.
42 echo Stop your services and try again.
49 echo Checking this AppImage compatibility with your host system...
51 export LD_LIBRARY_PATH=$APPDIR/usr/lib
52 export PATH=$APPDIR/usr/bin
53 $APPDIR/usr/local/citadel/citserver -c || {
54 echo Compatibility failed.
61 # Locate the Citadel run directory
63 while [ ${confirmed} == 0 ]
65 echo -n In what directory will you run Citadel\? \[${CTDL_DIR}\]\
73 echo -n ${dir} does not exist. Do you want to create it\?\
75 if [ `echo ${yesno} | cut -c1` == 'y' ]
88 echo Checking this operating system for systemd...
89 systemctl --version >/dev/null 2>&1 || {
90 echo Automatic installation is only supported with systemd.
91 echo You can still run Citadel but you will need to start it some other way.
97 # Remove old unit files
98 echo Checking for old startup files.
99 ls /etc/systemd/system/citadel* 2>/dev/null && {
100 rm -i /etc/systemd/system/citadel*
102 ls /etc/systemd/system/webcit* 2>/dev/null && {
103 rm -i /etc/systemd/system/webcit*
108 echo Ready to install ${APPIMAGE} in ${CTDL_DIR}
109 echo Copying the AppImage...
110 rm -f ${CTDL_DIR}/citadel.appimage 2>/dev/null
111 cp ${APPIMAGE} ${CTDL_DIR}/citadel.appimage || {
112 echo Installation has failed with error code $? .
116 echo Creating the systemd unit file...
118 echo '# This unit file starts all Citadel services via the AppImage distribution.'
119 echo '# Automatically installed on' `date`
122 echo 'Description=Citadel'
123 echo 'After=network.target'
126 echo 'ExecStart='${CTDL_DIR}'/citadel.appimage run -h '${CTDL_DIR}' -p '${HTTP_PORT}' -s '${HTTPS_PORT}
127 echo 'ExecStop=/bin/kill $MAINPID'
128 echo 'KillMode=process'
129 echo 'Restart=on-failure'
130 echo 'LimitCORE=infinity'
133 echo 'WantedBy=multi-user.target'
134 ) >/etc/systemd/system/citadel.service || {
135 echo Installation has failed with error code $? .
141 echo Enabling the service...
142 systemctl enable citadel || {
143 echo Installation has failed with error code $? .
149 echo Starting the service...
150 systemctl start citadel || {
151 echo Installation has failed with error code $? .
157 echo Installation has completed.
158 echo Please continue by browsing to http://`hostname`:${HTTP_PORT}
163 PARSED_ARGUMENTS=$(getopt -o h:p:s: -- "$@")
165 if [ "$VALID_ARGUMENTS" != "0" ]; then
169 eval set -- ${PARSED_ARGUMENTS}
173 -h) CTDL_DIR=${2} ; shift 2 ;;
174 -p) HTTP_PORT=${2} ; shift 2 ;;
175 -s) HTTPS_PORT=${2} ; shift 2 ;;
177 *) echo Unexpected option: ${1}
184 export APPDIR CTDL_DIR HTTP_PORT HTTPS_PORT
185 export LD_LIBRARY_PATH=$APPDIR/usr/lib
186 export PATH=$APPDIR/usr/bin
190 export LD_LIBRARY_PATH=$APPDIR/usr/lib
191 export PATH=$APPDIR/usr/bin
192 exec $APPDIR/usr/local/citadel/citserver -c
198 echo Unexpected command: ${1}