look at me , i am a build monkey , see what I can type
[citadel.git] / appimage / citadel.AppDir / AppRun
1 #!/bin/bash
2
3 ## This is an AppImage control script for the Citadel system.
4 ##
5 ## Copyright (c) 2021 by the citadel.org team
6 ##
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.
11 ##
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.
16
17 # Default values
18 HTTP_PORT=80
19 HTTPS_PORT=443
20 CTDL_DIR=/usr/local/citadel
21 export APPDIR
22
23 usage() {
24         echo ${APPIMAGE}: usage: ${APPIMAGE} '[-h data_directory] [-p http_port] [-s https_port] command'
25         echo 'command must be one of: run, test, install'
26         exit 2
27 }
28
29
30 # Permanently install the Citadel AppImage to this system
31 installation() {
32
33         # First ... check to make sure Citadel isn't runnings
34         if ps ax | grep citserver | grep -v grep ; then
35                 echo Installation cannot proceed while Citadel is running.
36                 echo Stop your services and try again.
37                 exit 1
38         fi
39
40         echo Hi
41         exit
42 }
43
44
45 PARSED_ARGUMENTS=$(getopt -o h:p:s: -- "$@")
46 VALID_ARGUMENTS=$?
47 if [ "$VALID_ARGUMENTS" != "0" ]; then
48         usage
49 fi
50
51 eval set -- ${PARSED_ARGUMENTS}
52 while :
53 do
54         case ${1} in
55                 -h)     CTDL_DIR=${2}   ; shift 2 ;;
56                 -p)     HTTP_PORT=${2}  ; shift 2 ;;
57                 -s)     HTTPS_PORT=${2} ; shift 2 ;;
58                 --)     shift; break;;
59                 *)      echo Unexpected option: ${1}
60                         usage;
61         esac
62 done
63
64 case ${1} in
65         run)
66                 export APPDIR CTDL_DIR HTTP_PORT HTTPS_PORT
67                 export LD_LIBRARY_PATH=$APPDIR/usr/lib
68                 export PATH=$APPDIR/usr/bin
69                 exec ctdlvisor $*
70                 ;;
71         test)
72                 export LD_LIBRARY_PATH=$APPDIR/usr/lib
73                 export PATH=$APPDIR/usr/bin
74                 exec $APPDIR/usr/local/citadel/citserver -c
75                 ;;
76         install)
77                 installation
78                 ;;
79         *)
80                 echo Unexpected command: ${1} 
81                 usage
82                 exit 1
83                 ;;
84 esac
85 exit 0
86
87
88
89
90 # This unit file starts all Citadel services via the AppImage distribution.
91 [Unit]
92 Description=Citadel
93 After=network.target
94 [Service]
95 ExecStart=/root/citadel/appimage/Citadel-x86_64.AppImage run -h /usr/local/citadel -s 80 -s 443
96 ExecStop=/bin/kill $MAINPID
97 KillMode=process
98 Restart=on-failure
99 LimitCORE=infinity
100 [Install]
101 WantedBy=multi-user.target