jilo-web/doc/install.sh

145 lines
4.3 KiB
Bash
Raw Permalink Normal View History

#!/usr/bin/env bash
2024-07-24 13:50:48 +00:00
# first we check the privileges, we need root or sudo
if [ "$EUID" -ne 0 ] && [ -z "$SUDO_USER" ]; then
echo "This script needs administrative privileges. Either run as root or with sudo."
exit 1
fi
2024-08-16 06:35:21 +00:00
VERSION=`grep version ../app/config/jilo-web.conf.php | cut -d "'" -f 4`
2024-07-19 08:20:08 +00:00
# main install function
2024-07-19 08:14:30 +00:00
function install() {
# enter domain
read -p "Domain name for the web service [localhost]: " DOMAIN
DOMAIN=${DOMAIN:-localhost}
# enter folder
read -p "Web subfolder [jilo-web]: " WEB_DIR
WEB_DIR=${WEB_DIR:-jilo-web}
INSTALL_DIR="/opt/jilo-web/public_html"
2024-08-16 06:35:21 +00:00
APP_DIR="/opt/jilo-web/app"
2024-07-19 08:14:30 +00:00
DOC_DIR="/opt/jilo-web/doc"
ETC_DIR="/opt/jilo-web/etc"
mkdir -p $INSTALL_DIR
2024-08-16 06:35:21 +00:00
cp -r ../public_html/* $INSTALL_DIR
2024-07-19 08:14:30 +00:00
mkdir -p $DOC_DIR
2024-08-16 06:35:21 +00:00
cp ../CHANGELOG.md $DOC_DIR
cp ../LICENSE $DOC_DIR
cp ../README.md $DOC_DIR
cp ../TODO.md $DOC_DIR
cp ../license-bootstrap $DOC_DIR
cp ../license-jquery $DOC_DIR
cp -r ../doc/ $DOC_DIR
2024-07-19 08:14:30 +00:00
mkdir -p $ETC_DIR
2024-08-16 06:35:21 +00:00
cp ../app/config/jilo-web.conf.php $ETC_DIR
2024-07-19 08:14:30 +00:00
#FIXME
#mkdir -p "jilo-web-$VERSION/usr/share/man/man8"
#cp ../man-jilo-web.8 "jilo-web-$VERSION/usr/share/man/man8/jilo-web.8"
2024-07-17 16:51:49 +00:00
2024-07-19 08:14:30 +00:00
# we need a webserver, check for Apache and Nginx
WEB_SERVER=""
2024-07-17 16:51:49 +00:00
2024-07-19 08:14:30 +00:00
# install and enable apache vhost
if dpkg-query -W -f='${status}' apache2 2>/dev/null | grep -q "ok installed"; then
WEB_SERVER="apache2"
cp "${DOC_DIR}/config.apache" /etc/apache2/sites-available/jilo-web.conf
sed -i -e "s/\$DOMAIN/$DOMAIN/g" /etc/apache2/sites-available/jilo-web.conf
# there is '/' in INSTALL_DIR, we use '%'
sed -i -e "s%\$INSTALL_DIR%$INSTALL_DIR%g" /etc/apache2/sites-available/jilo-web.conf
a2ensite jilo-web.conf
/etc/init.d/apache2 reload
# install and enable nginx vhost
elif dpkg-query -W -f='${status}' nginx 2>/dev/null | grep -q "ok installed"; then
WEB_SERVER="nginx"
cp "${DOC_DIR}/config.nginx" /etc/nginx/sites-available/jilo-web
sed -i -e "s/\$DOMAIN/$DOMAIN/g" /etc/nginx/sites-available/jilo-web
# there is '/' in INSTALL_DIR, we use '%'
sed -i -e "s%\$INSTALL_DIR%$INSTALL_DIR%g" /etc/nginx/sites-available/jilo-web
ln -s /etc/nginx/sites-available/jilo-web /etc/nginx/sites-enabled/
/etc/init.d/nginx reload
else
echo "Nginx or Apache is needed, please install one of them first."
exit 1
fi
# permissions for web folder
chown -R www-data:www-data "$INSTALL_DIR"
chmod -R ug+rw "$INSTALL_DIR"
2024-07-24 13:50:48 +00:00
# etc configs (we use % because the variables contain paths with "/")
2024-07-24 13:46:20 +00:00
sed -i -e "s%\('domain'[[:space:]]*=>[[:space:]]*'\)[^']*\('.*\)%\1$DOMAIN\2%g" "$ETC_DIR/jilo-web.conf.php"
sed -i -e "s%\('folder'[[:space:]]*=>[[:space:]]*'\)[^']*\('.*\)%\1$WEB_DIR\2%g" "$ETC_DIR/jilo-web.conf.php"
sed -i -e "s%\('database'[[:space:]]*=>[[:space:]]*'\)[^']*\('.*\)%\1$ETC_DIR\/jilo-web.db\2%g" "$ETC_DIR/jilo-web.conf.php"
sed -i -e "s%\('jilo_database'[[:space:]]*=>[[:space:]]*'\)[^']*\('.*\)%\1$ETC_DIR\/jilo.db\2%g" "$ETC_DIR/jilo-web.conf.php"
2024-07-19 08:14:30 +00:00
echo 'Install finished.'
}
2024-07-19 08:24:38 +00:00
help="Jilo-Web deployment script
Usage:
2024-07-19 08:14:30 +00:00
$0 [OPTION]
Options:
--install|-i - install Jilo-Web
--help|-h - show this help message
--version|-v - show version"
2024-07-19 08:24:38 +00:00
version="version $VERSION"
2024-07-19 08:14:30 +00:00
2024-07-19 08:20:08 +00:00
# called with an option
2024-07-19 08:14:30 +00:00
if [[ $1 ]]; then
case $1 in
-i | --install)
2024-07-20 08:27:15 +00:00
install
exit 0
2024-07-19 08:14:30 +00:00
;;
-h | --help)
echo -e "$help"
exit 0
;;
-v | --version)
echo -e "$version"
exit 0
;;
*)
echo "Invalid option: $1" >&2
echo -e "$help"
exit 1
;;
esac
2024-07-19 08:20:08 +00:00
# called without any options, ask how to proceed
else
read -p "Choose an option, blank for \"install\" [install | help | version]: " OPTION
OPTION=${OPTION:-install}
case $OPTION in
install)
2024-07-20 08:27:15 +00:00
install
exit 0
2024-07-19 08:20:08 +00:00
;;
help)
echo -e "$help"
exit 0
;;
version)
echo -e "$version"
exit 0
;;
*)
echo "Invalid option: $1" >&2
echo -e "$help"
exit 1
;;
esac
2024-07-19 08:14:30 +00:00
fi