You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
2.8 KiB
103 lines
2.8 KiB
#! /bin/bash |
|
|
|
script_dir="$(dirname $(readlink -f $0))" |
|
|
|
app_name='biscd' |
|
install_dir="/opt/$app_name" |
|
logging_dir="/var/log/$app_name" |
|
|
|
systemd_service=`systemctl list-unit-files | cut -d ' ' -f 1 | grep -swcF "$app_name.service"` > 0 |
|
|
|
# exit when any command fails |
|
set -e |
|
|
|
function help () { |
|
echo "Usage: $0 [OPTIONS]" |
|
echo " -f force uninstallation: Don't stop when something fails" |
|
echo ' -l remove logfiles and logdirectory as well' |
|
echo ' -h display this output.' |
|
echo '' |
|
echo "This script uninstalls $app_name. All application files will be removed," |
|
echo 'as will the logrotate and apache config(section).' |
|
echo 'Apache will be reloaded in this process.' |
|
echo '' |
|
echo 'For more info visit https://git.sciuro.org/Burathar/biscd' |
|
exit 1 |
|
} |
|
|
|
function echo_header () { |
|
echo -e "\e[33m== $1 ==\e[0;m" |
|
} |
|
|
|
while getopts 'flh' opt ; do |
|
case "$opt" in |
|
f) set +e; force='true';; |
|
l) delete_logs='true';; |
|
h) help ;; |
|
esac |
|
done |
|
|
|
# Make sure running as root |
|
if [ `id -u` -ne 0 ]; then |
|
echo 'Please run as root' |
|
exit 1 |
|
fi |
|
|
|
if [ "$force" != 'true' ]; then |
|
read -p "Are you sure you want to delete $app_name? Apache will be reloaded during this process (y/N) " confirm_delete |
|
[ -z "$confirm_delete" ] && confirm_delete='no' # if no input, assume no |
|
case ${confirm_delete:0:1} in |
|
n|N|0 ) |
|
exit 0;; |
|
esac |
|
fi |
|
|
|
if [ "$delete_logs" != 'true' ]; then |
|
read -p "Do you wish to delete any $app_name log files as well? (y/N) " delete_logs |
|
[ -z "$delete_logs" ] && delete_logs='no' # if no input, assume no |
|
case ${delete_logs:0:1} in |
|
n|N|0 ) |
|
delete_logs='false';; |
|
*) |
|
delete_logs='true';; |
|
esac |
|
fi |
|
|
|
echo_header "Removing Apache virtualhost" |
|
rm -v "/etc/apache2/sites-enabled/$app_name.conf" |
|
systemctl reload apache2.service |
|
|
|
|
|
if [ "$systemd_service" -eq 1 ]; then |
|
echo_header "Removing Systemd service" |
|
systemctl stop "$app_name.service" |
|
sleep 1s |
|
systemctl disable "$app_name.service" |
|
rm "/etc/systemd/system/$app_name.service" |
|
systemctl daemon-reload |
|
fi |
|
|
|
|
|
echo_header "Removing $app_name user and group==" |
|
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 -rf "$install_dir" && echo "removed '$install_dir'" |
|
|
|
if [ "$delete_logs" = 'true' ]; then |
|
echo_header "Removing logfiles" |
|
rm -vrf "$logging_dir" |
|
fi |
|
|
|
echo_header "Remaining artifacts(feel free to remove these manually)" |
|
dpkg -l | grep libapache2-mod-wsgi-py3 | awk '{print $2}' |
|
echo python3-venv |
|
|
|
echo_header "$app_name is uninstalled!" |
|
|
|
exit 0
|
|
|