echo' -p port: On which port the internal webserver runs. Default = 5000. Ignored in WSGI mode'
echo' -h display this output.'
echo''
echo"This script installs $default_app_name, by downloading dependancies when not present,"
echo'creating a python virtualenv, unpacking any necessary files and creates a systemd integration if the user wishes so.'
echo''
echo'For more info visit https://git.sciuro.org/Burathar/biscd'
exit1
}
function echo_header (){
echo -e "\e[33m== $1 ==\e[0;m"
}
unset use_wsgi
whilegetopts':uhdwp:' opt ;do
case"$opt" in
u)ignore_name='true';;
d)use_wsgi='false';;
w)use_wsgi='true';;
p)internal_port="${OPTARG}";;
h)help;;
:)
echo"$0: Must supply an argument to -$OPTARG." >&2
exit1
;;
?)
echo"Invalid option: -${OPTARG}."
exit2
;;
esac
done
arg_name=${@:$OPTIND:1}
if[ -n "$arg_name"];then
[[$arg_name=~ ^[a-zA-Z0-9][a-zA-Z0-9_-]*$ ]]||{echo"'$arg_name' is not allowed as an app name. Please only use letters, numbers, underscores(_) and dashes(-). The first character must be a letter or number."&&exit 1;}
if["$ignore_name" !='true'];then
compgen -G "/etc/systemd/system/$arg_name.*" >/dev/null &&echo"An app called '$arg_name' already exists. Please choose another name, or run with -u to update existing app with this name."&&exit1
id -u "$arg_name" >/dev/null 2>&1&&echo"A user called '$arg_name' already exists. Please choose another name."&&exit1
egrep "^$arg_name" /etc/group >/dev/null &&echo"A group called '$arg_name' already exists. Please choose another name."&&exit1
fi
app_name="$arg_name"
else
app_name="$default_app_name"
fi
install_dir="$install_dir_parent/$app_name"
logging_dir="/var/log/$app_name"
if[ -z "$use_wsgi"];then
echo"Should this application be installed as WSGI app (recommended), or as local daemon using flask's built-in webserver, with apache as a proxy?"
read -p "Use WSGI? (Y/n) " use_wsgi
[ -z "$use_wsgi"]&&use_wsgi='y'# if no input, assume yes
case${use_wsgi:0:1} in
y|Y|1)
use_wsgi='true';;
* )
use_wsgi='false';;
esac
fi
if["$use_wsgi" !='true'];then
echo"Do you want to daemonize this application using systemd? (you'll have to start it manually every login session if you choose no)"
read -p "Use Systemd? (Y/n) " use_systemd
[ -z "$use_systemd"]&&use_systemd='y'# if no input, assume yes
case${use_systemd:0:1} in
y|Y|1)
use_systemd='true';;
* )
use_systemd='false';;
esac
if[ -z "$internal_port"];then
echo"Please specify an internal port for the built-in webserver. This port will only be used locally."
read -p "Port [5000]" internal_port
[ -z "$internal_port"]&&internal_port=5000
fi
fi
echo_header "Check if Apache2 is installed"
which apache2 >/dev/null 2>&1&&echo"Apache OK"||{echo"Apache2 doesn't seem te be installed. Please fix this before installing this application."&&exit 1;}