X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=appimage%2Fcitadel.AppDir%2FAppRun;h=860b36b37eb20f878a1fdd9160447abe7bcb788b;hb=a5b89af01e00b8e95937ac60502cff4a34a710de;hp=027c553ce78878de56d02f1d842a23aaa19d3624;hpb=a69148ba680b403a3f07310e037210de606c4a51;p=citadel.git diff --git a/appimage/citadel.AppDir/AppRun b/appimage/citadel.AppDir/AppRun index 027c553ce..860b36b37 100755 --- a/appimage/citadel.AppDir/AppRun +++ b/appimage/citadel.AppDir/AppRun @@ -1,35 +1,200 @@ #!/bin/bash -// This is an AppImage control script for the Citadel system. -// -// Copyright (c) 2021 by the citadel.org team -// -// This program is open source software. It runs great on the -// Linux operating system (and probably elsewhere). You can use, -// copy, and run it under the terms of the GNU General Public -// License version 3. Richard Stallman is an asshole communist. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. +# This is an AppImage control script for the Citadel system. +# +# Copyright (c) 2021 by the citadel.org team +# +# This program is open source software. It runs great on the +# Linux operating system (and probably elsewhere). You can use, +# copy, and run it under the terms of the GNU General Public +# License version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # Default values HTTP_PORT=80 HTTPS_PORT=443 CTDL_DIR=/usr/local/citadel export APPDIR +ulimit -c unlimited usage() { - echo usage + echo ${APPIMAGE}: usage: ${APPIMAGE} '[-h data_directory] [-p http_port] [-s https_port] command' + echo 'command must be one of: run, test, install, database_cleanup, migrate' exit 2 } + +# Permanently install the Citadel AppImage to this system +installation() { + + # Clear the screen and draw the banner + echo -e '\033[2J\033[H\033[44m\033[37m\033[K\033[0m' + echo -e '\033[44m\033[37m\033[1m Citadel installation\033[K\033[0m' + echo -e '\033[44m\033[37m \033[K\033[0m' + echo + + # First ... check to make sure Citadel isn't already running. + echo Checking to make sure Citadel is not already running... + if ps ax | grep citserver | grep -v grep ; then + echo + echo -e '\033[31m\033[1mInstallation cannot proceed while Citadel is running.\033[0m' + echo Stop your services and try again. + echo + exit 1 + fi + echo OK + echo + + # Check compatibility + echo Checking this AppImage compatibility with your host system... + ( + export LD_LIBRARY_PATH=$APPDIR/usr/lib + export PATH=$APPDIR/usr/bin + $APPDIR/usr/local/citadel/citserver -c || { + echo + echo -e '\033[31m\033[1mCompatibility failed.\033[0m' + echo 'This AppImage is not compatible with your system.' + echo 'If you are attempting to run it on a compatible platform, please make sure you' + echo 'have all of the latest updates and patches applied. Otherwise, you may have' + echo 'better luck with the Easy Install method.' + echo '' + exit 2 + } + ) || exit 2 + echo OK + echo + + # Clear the screen and draw the banner + echo -e '\033[2J\033[H\033[44m\033[37m\033[K\033[0m' + echo -e '\033[44m\033[37m\033[1m Citadel installation\033[K\033[0m' + echo -e '\033[44m\033[37m \033[K\033[0m' + echo + + # Locate the Citadel run directory + confirmed=0 + while [ ${confirmed} == 0 ] + do + echo -n In what directory will you run Citadel\? \[${CTDL_DIR}\]\ + read dir + if [ "${dir}" == "" ] + then + dir=${CTDL_DIR} + fi + if [ ! -d ${dir} ] + then + echo -n ${dir} does not exist. Do you want to create it\?\ + read yesno + if [ `echo ${yesno} | cut -c1` == 'y' ] + then + mkdir ${dir} + fi + fi + if [ -d ${dir} ] + then + confirmed=1 + fi + done + CTDL_DIR=${dir} + + # Check systemd + echo Checking this operating system for systemd... + systemctl --version >/dev/null 2>&1 || { + echo Automatic installation is only supported with systemd. + echo You can still run Citadel but you will need to start it some other way. + exit 3 + } | exit 3 + echo OK + echo + + # Remove old unit files + echo Checking for old startup files. + ls /etc/systemd/system/citadel* 2>/dev/null && { + rm -i /etc/systemd/system/citadel* + } + ls /etc/systemd/system/webcit* 2>/dev/null && { + rm -i /etc/systemd/system/webcit* + } + echo OK + echo + + # Clear the screen and draw the banner + echo -e '\033[2J\033[H\033[44m\033[37m\033[K\033[0m' + echo -e '\033[44m\033[37m\033[1m Citadel installation\033[K\033[0m' + echo -e '\033[44m\033[37m \033[K\033[0m' + echo + + echo Ready to install ${APPIMAGE} in ${CTDL_DIR} + echo Copying the AppImage... + rm -f ${CTDL_DIR}/citadel.appimage 2>/dev/null + cp ${APPIMAGE} ${CTDL_DIR}/citadel.appimage || { + echo Installation has failed with error code $? . + exit 4 + } | exit 4 + + echo Creating the systemd unit file... + ( + echo '# This unit file starts all Citadel services via the AppImage distribution.' + echo '# Automatically installed on' `date` + echo '' + echo '[Unit]' + echo 'Description=Citadel' + echo 'After=network.target' + echo '' + echo '[Service]' + echo 'ExecStart='${CTDL_DIR}'/citadel.appimage run -h '${CTDL_DIR}' -p '${HTTP_PORT}' -s '${HTTPS_PORT} + echo 'ExecStop=/bin/kill $MAINPID' + echo 'KillMode=process' + echo 'Restart=on-failure' + echo 'LimitCORE=infinity' + echo '' + echo '[Install]' + echo 'WantedBy=multi-user.target' + ) >/etc/systemd/system/citadel.service || { + echo Installation has failed with error code $? . + exit 5 + } | exit 5 + echo OK + echo + + echo Enabling the service... + systemctl enable citadel || { + echo Installation has failed with error code $? . + exit 6 + } | exit 6 + echo OK + echo + + echo Starting the service... + systemctl start citadel || { + echo Installation has failed with error code $? . + exit 6 + } || exit 6 + echo OK + echo + + # Clear the screen and draw the banner + echo -e '\033[2J\033[H\033[44m\033[37m\033[K\033[0m' + echo -e '\033[44m\033[37m\033[1m Citadel installation\033[K\033[0m' + echo -e '\033[44m\033[37m \033[K\033[0m' + echo + + echo -e '\033[32m\033[1mInstallation has completed.\033[0m' + echo Please continue by browsing to http://`hostname`:${HTTP_PORT} + echo + echo -e 'If this is a new installation, the default administrator' + echo -e 'will be named \033[7madmin\033[0m with password \033[7mcitadel\033[0m.' + exit +} + + PARSED_ARGUMENTS=$(getopt -o h:p:s: -- "$@") VALID_ARGUMENTS=$? if [ "$VALID_ARGUMENTS" != "0" ]; then - echo $0: usage: $0 '[-h data_directory] [-p http_port] [-s https_port] command' - echo 'command must be one of: run, test, install' + usage fi eval set -- ${PARSED_ARGUMENTS} @@ -55,8 +220,34 @@ case ${1} in test) export LD_LIBRARY_PATH=$APPDIR/usr/lib export PATH=$APPDIR/usr/bin - $APPDIR/usr/local/citadel/citserver -c - exit $? + exec $APPDIR/usr/local/citadel/citserver -c + ;; + install) + installation + ;; + database_cleanup) + export LD_LIBRARY_PATH=$APPDIR/usr/lib + export PATH=$APPDIR/usr/bin:$PATH + exec $APPDIR/usr/local/citadel/database_cleanup.sh -h $CTDL_DIR + ;; + migrate) + export APPDIR CTDL_DIR HTTP_PORT HTTPS_PORT + export LD_LIBRARY_PATH=$APPDIR/usr/lib + export PATH=$APPDIR/usr/bin + exec ctdlvisor -m + ;; + mount) + echo This mode of operation mounts the AppImage but does not run anything. + echo -n Kill it when you are finished... + while true + do + sleep 1 + done + ;; + debug) + export LD_LIBRARY_PATH=$APPDIR/usr/lib + export PATH=$APPDIR/usr/bin:$PATH + exec $APPDIR/usr/local/citadel/citserver -x9 -h $CTDL_DIR ;; *) echo Unexpected command: ${1} @@ -65,19 +256,3 @@ case ${1} in ;; esac exit 0 - - - - -# This unit file starts all Citadel services via the AppImage distribution. -[Unit] -Description=Citadel -After=network.target -[Service] -ExecStart=/root/citadel/appimage/Citadel-x86_64.AppImage run -h /usr/local/citadel -s 80 -s 443 -ExecStop=/bin/kill $MAINPID -KillMode=process -Restart=on-failure -LimitCORE=infinity -[Install] -WantedBy=multi-user.target