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
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, database_cleanup, migrate'
31 # Permanently install the Citadel AppImage to this system
34 # Clear the screen and draw the banner
35 echo -e '\033[2J\033[H\033[44m\033[37m\033[K\033[0m'
36 echo -e '\033[44m\033[37m\033[1m Citadel installation\033[K\033[0m'
37 echo -e '\033[44m\033[37m \033[K\033[0m'
40 # First ... check to make sure Citadel isn't already running.
41 echo Checking to make sure Citadel is not already running...
42 if ps ax | grep citserver | grep -v grep ; then
44 echo -e '\033[31m\033[1mInstallation cannot proceed while Citadel is running.\033[0m'
45 echo Stop your services and try again.
53 echo Checking this AppImage compatibility with your host system...
55 export LD_LIBRARY_PATH=$APPDIR/usr/lib
56 export PATH=$APPDIR/usr/bin
57 $APPDIR/usr/local/citadel/citserver -c || {
59 echo -e '\033[31m\033[1mCompatibility failed.\033[0m'
60 echo 'This AppImage is not compatible with your system.'
61 echo 'If you are attempting to run it on a compatible platform, please make sure you'
62 echo 'have all of the latest updates and patches applied. Otherwise, you may have'
63 echo 'better luck with the Easy Install method.'
71 # Clear the screen and draw the banner
72 echo -e '\033[2J\033[H\033[44m\033[37m\033[K\033[0m'
73 echo -e '\033[44m\033[37m\033[1m Citadel installation\033[K\033[0m'
74 echo -e '\033[44m\033[37m \033[K\033[0m'
77 # Locate the Citadel run directory
79 while [ ${confirmed} == 0 ]
81 echo -n In what directory will you run Citadel\? \[${CTDL_DIR}\]\
89 echo -n ${dir} does not exist. Do you want to create it\?\
91 if [ `echo ${yesno} | cut -c1` == 'y' ]
104 echo Checking this operating system for systemd...
105 systemctl --version >/dev/null 2>&1 || {
106 echo Automatic installation is only supported with systemd.
107 echo You can still run Citadel but you will need to start it some other way.
113 # Remove old unit files
114 echo Checking for old startup files.
115 ls /etc/systemd/system/citadel* 2>/dev/null && {
116 rm -i /etc/systemd/system/citadel*
118 ls /etc/systemd/system/webcit* 2>/dev/null && {
119 rm -i /etc/systemd/system/webcit*
124 # Clear the screen and draw the banner
125 echo -e '\033[2J\033[H\033[44m\033[37m\033[K\033[0m'
126 echo -e '\033[44m\033[37m\033[1m Citadel installation\033[K\033[0m'
127 echo -e '\033[44m\033[37m \033[K\033[0m'
130 echo Ready to install ${APPIMAGE} in ${CTDL_DIR}
131 echo Copying the AppImage...
132 rm -f ${CTDL_DIR}/citadel.appimage 2>/dev/null
133 cp ${APPIMAGE} ${CTDL_DIR}/citadel.appimage || {
134 echo Installation has failed with error code $? .
138 echo Creating the systemd unit file...
140 echo '# This unit file starts all Citadel services via the AppImage distribution.'
141 echo '# Automatically installed on' `date`
144 echo 'Description=Citadel'
145 echo 'After=network.target'
148 echo 'ExecStart='${CTDL_DIR}'/citadel.appimage run -h '${CTDL_DIR}' -p '${HTTP_PORT}' -s '${HTTPS_PORT}
149 echo 'ExecStop=/bin/kill $MAINPID'
150 echo 'KillMode=process'
151 echo 'Restart=on-failure'
152 echo 'LimitCORE=infinity'
155 echo 'WantedBy=multi-user.target'
156 ) >/etc/systemd/system/citadel.service || {
157 echo Installation has failed with error code $? .
163 echo Enabling the service...
164 systemctl enable citadel || {
165 echo Installation has failed with error code $? .
171 echo Starting the service...
172 systemctl start citadel || {
173 echo Installation has failed with error code $? .
179 # Clear the screen and draw the banner
180 echo -e '\033[2J\033[H\033[44m\033[37m\033[K\033[0m'
181 echo -e '\033[44m\033[37m\033[1m Citadel installation\033[K\033[0m'
182 echo -e '\033[44m\033[37m \033[K\033[0m'
185 echo -e '\033[32m\033[1mInstallation has completed.\033[0m'
186 echo Please continue by browsing to http://`hostname`:${HTTP_PORT}
188 echo -e 'If this is a new installation, the default administrator'
189 echo -e 'will be named \033[7madmin\033[0m with password \033[7mcitadel\033[0m.'
194 PARSED_ARGUMENTS=$(getopt -o h:p:s: -- "$@")
196 if [ "$VALID_ARGUMENTS" != "0" ]; then
200 eval set -- ${PARSED_ARGUMENTS}
204 -h) CTDL_DIR=${2} ; shift 2 ;;
205 -p) HTTP_PORT=${2} ; shift 2 ;;
206 -s) HTTPS_PORT=${2} ; shift 2 ;;
208 *) echo Unexpected option: ${1}
215 export APPDIR CTDL_DIR HTTP_PORT HTTPS_PORT
216 export LD_LIBRARY_PATH=$APPDIR/usr/lib
217 export PATH=$APPDIR/usr/bin
221 export LD_LIBRARY_PATH=$APPDIR/usr/lib
222 export PATH=$APPDIR/usr/bin
223 exec $APPDIR/usr/local/citadel/citserver -c
229 export LD_LIBRARY_PATH=$APPDIR/usr/lib
230 export PATH=$APPDIR/usr/bin:$PATH
231 exec $APPDIR/usr/local/citadel/database_cleanup.sh -h $CTDL_DIR
234 export APPDIR CTDL_DIR HTTP_PORT HTTPS_PORT
235 export LD_LIBRARY_PATH=$APPDIR/usr/lib
236 export PATH=$APPDIR/usr/bin
240 echo This mode of operation mounts the AppImage but does not run anything.
241 echo -n Kill it when you are finished...
248 export LD_LIBRARY_PATH=$APPDIR/usr/lib
249 export PATH=$APPDIR/usr/bin:$PATH
250 exec $APPDIR/usr/local/citadel/citserver -x9 -h $CTDL_DIR
253 echo Unexpected command: ${1}