Browse Source

update installer & uninstaller

master
Burathar 4 years ago
parent
commit
1e80380328
  1. 12
      biscd/config_example.yaml
  2. 16
      biscd/projects_example.yaml
  3. 25
      biscd/requirements.txt
  4. 35
      install.sh
  5. 13
      installation-files/logrotate-conf
  6. 2
      installation-files/uninstall.sh

12
biscd/config_example.yaml

@ -1,12 +0,0 @@ @@ -1,12 +0,0 @@
flask_development_server:
# Options: production, development
flask_env: production
# Options: 127.0.0.1 , 0.0.0.0
server_host: 127.0.0.1
port: 5000
logging:
log_to_sdout: true
logfile: info.log
message: Hoi

16
biscd/projects_example.yaml

@ -1,16 +0,0 @@ @@ -1,16 +0,0 @@
projects:
- The Hunt:
url: thehunt
git_repo: https://git.sciuro.org/Burathar/The-Hunt
branch: master
secret: thisissecret
requirements-file: requirements.txt
tests: tests.py
- Foo:
url: bar
git_repo: https://git.sciuro.org/Burathar/The-Hunt
branch: master
secret: thisissecret
requirements-file: requirements.txt
tests: tests.py

25
biscd/requirements.txt

@ -1,15 +1,20 @@ @@ -1,15 +1,20 @@
aniso8601==8.1.0
certifi==2020.12.5
chardet==4.0.0
astroid==2.5
click==7.1.2
confuse==1.4.0
dominate==2.6.0
Flask==1.1.2
Flask-RESTful==0.3.8
idna==2.10
Flask-Bootstrap==3.3.7.1
isort==5.7.0
itsdangerous==1.1.0
Jinja2==2.11.2
Jinja2==2.11.3
lazy-object-proxy==1.5.2
MarkupSafe==1.1.1
pytz==2020.5
requests==2.25.1
six==1.15.0
urllib3==1.26.3
mccabe==0.6.1
pkg-resources==0.0.0
pylint==2.7.1
PyYAML==5.4.1
toml==0.10.2
typed-ast==1.4.2
visitor==0.1.3
Werkzeug==1.0.1
wrapt==1.12.1

35
install.sh

@ -4,6 +4,7 @@ script_dir="$(dirname $(readlink -f $0))" @@ -4,6 +4,7 @@ script_dir="$(dirname $(readlink -f $0))"
install_dir_parent="/opt"
default_app_name='biscd'
flask_module_name='biscd'
start_script='run.sh'
# exit when any command fails
@ -110,24 +111,26 @@ fi @@ -110,24 +111,26 @@ fi
echo_header "Copy over application files"
mkdir -vp "$install_dir"
cp -rv "$script_dir/$default_app_name/." "$install_dir"
sed -i "s+^app_name=.*+app_name='${flask_app_name}'+g" "$install_dir/run.sh"
sed -i "s+^app_name=.*+app_name='${flask_module_name}'+g" "$install_dir/run.sh"
sed -i "s+confuse.Configuration(*, __name__)+confuse.Configuration('$app_name', __name__)'+g" "$install_dir/{$flask_module_name}/__init__.py"
cp -v "$script_dir/$default_app_name/config_example.yml" "$install_dir/config.yml"
sed -i "s/^port =.*/port = $internal_port/g" "$install_dir/config.yml"
sed -i "s+^logfile :.*+logfile : $logging_dir/reports.log+g" "$install_dir/config.yml"
sed -i "s+^errorfile :.*+errorfile : $logging_dir/error.log+g" "$install_dir/config.yml"
cp -v "$script_dir/bin/uninstall.sh" "$install_dir"
cp -v "$script_dir/installation-files/uninstall.sh" "$install_dir"
sed -i "s+^app_name=.*+app_name='${app_name}'+g" "$install_dir/uninstall.sh"
sed -i "s+^install_dir=.*+install_dir='${install_dir}'+g" "$install_dir/uninstall.sh"
cp -v "$script_dir/version" "$install_dir"
cp -v "$script_dir/README.md" "$install_dir"
mkdir -vp "/etc/$app_name"
cp -v "$script_dir/$default_app_name/config_example.yaml" "/etc/$app_name/config.yaml"
sed -i "s/^port =.*/port = $internal_port/g" "$install_dir/config.yaml"
sed -i "s+^logfile :.*+logfile : $logging_dir/reports.log+g" "$install_dir/config.yaml"
sed -i "s+^errorfile :.*+errorfile : $logging_dir/error.log+g" "$install_dir/config.yaml"
echo_header "Copy over and enable apache vhost"
if [ "$use_wsgi" = 'true' ]; then
cp -v "$script_dir/bin/$default_app_name-wsgi.conf" "/etc/apache2/sites-available/$app_name.conf"
cp -v "$script_dir/installation-files/$default_app_name-wsgi.conf" "/etc/apache2/sites-available/$app_name.conf"
sed -i "s/APPNAME/$app_name/g" "/etc/apache2/sites-available/$app_name.conf"
sed -i "s/USER/$app_name/g" "/etc/apache2/sites-available/$app_name.conf"
sed -i "s/GROUP/$app_name/g" "/etc/apache2/sites-available/$app_name.conf"
@ -136,11 +139,11 @@ if [ "$use_wsgi" = 'true' ]; then @@ -136,11 +139,11 @@ if [ "$use_wsgi" = 'true' ]; then
echo_header "Installing wsgi-script"
mkdir -vp "/var/www/wsgi-scripts"
cp -v "$script_dir/bin/$default_app_name.wsgi" "/var/www/wsgi-scripts/app_name.wsgi"
cp -v "$script_dir/installation-files/$default_app_name.wsgi" "/var/www/wsgi-scripts/app_name.wsgi"
sed -i "s+INSTALLDIR+$install_dir+g" "/var/www/wsgi-scripts/$app_name.wsgi"
sed -i "s/APPNAME/$flask_app_name/g" "/var/www/wsgi-scripts/$app_name.wsgi"
sed -i "s/APPNAME/$flask_module_name/g" "/var/www/wsgi-scripts/$app_name.wsgi"
else
cp -v "$script_dir/bin/$default_app_name-proxy.conf" "/etc/apache2/sites-available/$app_name.conf"
cp -v "$script_dir/installation-files/$default_app_name-proxy.conf" "/etc/apache2/sites-available/$app_name.conf"
sed -i "s/PORT/$internal_port/g" "/etc/apache2/sites-available/$app_name.conf"
ln -sfv "/etc/apache2/sites-available/$app_name.conf" "/etc/apache2/sites-enabled/$app_name.conf"
@ -160,11 +163,6 @@ touch "$logging_dir/reports.log" @@ -160,11 +163,6 @@ touch "$logging_dir/reports.log"
chown -v --from=root:root "$app_name":"$app_name" "$logging_dir/reports.log"
echo_header "Install Logrotate config"
cp -v "$script_dir/bin/logrotate-conf" "/etc/logrotate.d/$app_name"
sed -i "s/log-dir/$logging_dir/g" "/etc/logrotate.d/$app_name"
echo_header "Make sure python3 and virtualenv are installed"
python3 --version || apt-get install -y python3
@ -179,7 +177,7 @@ pip install setuptools wheel @@ -179,7 +177,7 @@ pip install setuptools wheel
pip install -r "$script_dir/$default_app_name/requirements.txt"
python_version=`ls "$install_dir/venv/lib" | grep python3 | head -1`
echo "$install_dir/" > "$install_dir/venv/lib/$python_version/site-packages/$flask_app_name.pth"
echo "$install_dir/" > "$install_dir/venv/lib/$python_version/site-packages/$flask_module_name.pth"
[ "$use_wsgi" = 'true' ] && sed -i "s/PYTHON_VERSION/$python_version/g" "/var/www/wsgi-scripts/$default_app_name.wsgi"
@ -189,12 +187,11 @@ chown -v root:"$app_name" "$install_dir" @@ -189,12 +187,11 @@ chown -v root:"$app_name" "$install_dir"
chmod -v 775 "$install_dir"
chmod -v 754 "$install_dir/run.sh" "$install_dir/runserver.py"
chmod -v 744 "$install_dir/uninstall.sh"
#chmod -v 660 "$install_dir/config.yml"
if [ "$use_wsgi" != 'true' ] && [ "$use_systemd" = 'true' ]; then
echo_header "Enable as systemd service"
cp "$script_dir/bin/$default_app_name.service" "/etc/systemd/system/$app_name.service"
cp "$script_dir/installation-files/$default_app_name.service" "/etc/systemd/system/$app_name.service"
sed -i "s+^ExecStart=.*+ExecStart=${install_dir}/${start_script}+g" "/etc/systemd/system/$app_name.service"
sed -i "s+^User=.*+User=${app_name}+g" "/etc/systemd/system/$app_name.service"
systemctl daemon-reload

13
installation-files/logrotate-conf

@ -1,13 +0,0 @@ @@ -1,13 +0,0 @@
log-dir/info.log {
size 100k
rotate 2
compress
missingok
}
log-dir/error.log {
size 100k
rotate 2
compress
missingok
}

2
installation-files/uninstall.sh

@ -83,10 +83,10 @@ deluser -q "$app_name" @@ -83,10 +83,10 @@ deluser -q "$app_name"
delgroup -q "$app_name" && echo "group $app_name is removed, ignore previous warning" || true
echo_header "Removing application files"
rm -v "/etc/logrotate.d/$app_name"
rm -v "/etc/apache2/sites-available/$app_name.conf"
rm -v "/var/www/wsgi-scripts/$app_name.wsgi" || true
rm -vd "/var/www/wsgi-scripts/" || true
rm -vrf "/etc/$app_name"
rm -rf "$install_dir" && echo "removed '$install_dir'"
if [ "$delete_logs" = 'true' ]; then

Loading…
Cancel
Save