2017-10-03 07:09:55 +02:00
|
|
|
#!/bin/bash
|
|
|
|
raspap_dir="/etc/raspap"
|
|
|
|
raspap_user="www-data"
|
|
|
|
version=`sed 's/\..*//' /etc/debian_version`
|
|
|
|
|
|
|
|
# Determine version and set default home location for lighttpd
|
2018-08-31 23:38:30 +02:00
|
|
|
webroot_dir="/var/www/html"
|
|
|
|
if [ $version -eq 9 ]; then
|
|
|
|
version_msg="Raspian 9.0 (Stretch)"
|
|
|
|
php_package="php7.0-cgi"
|
|
|
|
elif [ $version -eq 8 ]; then
|
|
|
|
version_msg="Raspian 8.0 (Jessie)"
|
|
|
|
webroot_dir="/var/www"
|
|
|
|
php_package="php5-cgi"
|
|
|
|
else
|
|
|
|
version_msg="Raspian earlier than 8.0 (Wheezy)"
|
|
|
|
webroot_dir="/var/www"
|
|
|
|
php_package="php5-cgi"
|
2017-10-03 07:09:55 +02:00
|
|
|
fi
|
|
|
|
|
2018-08-31 23:38:30 +02:00
|
|
|
phpcgiconf=""
|
|
|
|
if [ "$php_package" = "php7.0-cgi" ]; then
|
|
|
|
phpcgiconf="/etc/php/7.0/cgi/php.ini"
|
|
|
|
elif [ "$php_package" = "php5-cgi" ]; then
|
|
|
|
phpcgiconf="/etc/php5/cgi/php.ini"
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2017-10-03 07:09:55 +02:00
|
|
|
# Outputs a RaspAP Install log line
|
|
|
|
function install_log() {
|
|
|
|
echo -e "\033[1;32mRaspAP Install: $*\033[m"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Outputs a RaspAP Install Error log line and exits with status code 1
|
|
|
|
function install_error() {
|
|
|
|
echo -e "\033[1;37;41mRaspAP Install Error: $*\033[m"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Checks to make sure uninstallation info is correct
|
|
|
|
function config_uninstallation() {
|
|
|
|
install_log "Configure installation"
|
|
|
|
echo "Detected ${version_msg}"
|
|
|
|
echo "Install directory: ${raspap_dir}"
|
|
|
|
echo "Lighttpd directory: ${webroot_dir}"
|
|
|
|
echo -n "Uninstall RaspAP with these values? [y/N]: "
|
|
|
|
read answer
|
|
|
|
if [[ $answer != "y" ]]; then
|
|
|
|
echo "Installation aborted."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Checks for/restore backup files
|
|
|
|
function check_for_backups() {
|
|
|
|
if [ -d "$raspap_dir/backups" ]; then
|
|
|
|
if [ -f "$raspap_dir/backups/interfaces" ]; then
|
|
|
|
echo -n "Restore the last interfaces file? [y/N]: "
|
|
|
|
read answer
|
|
|
|
if [[ $answer -eq 'y' ]]; then
|
|
|
|
sudo cp "$raspap_dir/backups/interfaces" /etc/network/interfaces
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ -f "$raspap_dir/backups/hostapd.conf" ]; then
|
|
|
|
echo -n "Restore the last hostapd configuration file? [y/N]: "
|
|
|
|
read answer
|
|
|
|
if [[ $answer -eq 'y' ]]; then
|
|
|
|
sudo cp "$raspap_dir/backups/hostapd.conf" /etc/hostapd/hostapd.conf
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ -f "$raspap_dir/backups/dnsmasq.conf" ]; then
|
|
|
|
echo -n "Restore the last dnsmasq configuration file? [y/N]: "
|
|
|
|
read answer
|
|
|
|
if [[ $answer -eq 'y' ]]; then
|
|
|
|
sudo cp "$raspap_dir/backups/dnsmasq.conf" /etc/dnsmasq.conf
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ -f "$raspap_dir/backups/dhcpcd.conf" ]; then
|
|
|
|
echo -n "Restore the last dhcpcd.conf file? [y/N]: "
|
2017-10-21 16:39:29 +02:00
|
|
|
read answer
|
2017-10-03 07:09:55 +02:00
|
|
|
if [[ $answer -eq 'y' ]]; then
|
|
|
|
sudo cp "$raspap_dir/backups/dhcpcd.conf" /etc/dhcpcd.conf
|
|
|
|
fi
|
|
|
|
fi
|
2018-08-31 23:38:30 +02:00
|
|
|
if [ -f "$raspap_dir/backups/php.ini" ] && [ -f "$phpcgiconf" ]; then
|
|
|
|
echo -n "Restore the last php.ini file? [y/N]: "
|
|
|
|
read answer
|
|
|
|
if [[ $answer -eq 'y' ]]; then
|
|
|
|
sudo cp "$raspap_dir/backups/php.ini" "$phpcgiconf"
|
|
|
|
fi
|
|
|
|
fi
|
2017-10-21 16:39:29 +02:00
|
|
|
if [ -f "$raspap_dir/backups/rc.local" ]; then
|
|
|
|
echo -n "Restore the last rc.local file? [y/N]: "
|
|
|
|
read answer
|
|
|
|
if [[ $answer -eq 'y' ]]; then
|
|
|
|
sudo cp "$raspap_dir/backups/rc.local" /etc/rc.local
|
|
|
|
else
|
|
|
|
echo -n "Remove RaspAP Lines from /etc/rc.local? [Y/n]: "
|
2018-08-31 23:38:30 +02:00
|
|
|
if [[ $answer -ne 'n' ]]; then
|
2017-10-21 16:39:29 +02:00
|
|
|
sed -i '/#RASPAP/d' /etc/rc.local
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
2017-10-03 07:09:55 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Removes RaspAP directories
|
|
|
|
function remove_raspap_directories() {
|
|
|
|
install_log "Removing RaspAP Directories"
|
|
|
|
if [ ! -d "$raspap_dir" ]; then
|
|
|
|
install_error "RaspAP Configuration directory not found. Exiting!"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d "$webroot_dir" ]; then
|
|
|
|
install_error "RaspAP Installation directory not found. Exiting!"
|
|
|
|
fi
|
|
|
|
|
2017-10-03 19:28:57 +02:00
|
|
|
sudo rm -rf "$webroot_dir"/*
|
2017-10-03 07:09:55 +02:00
|
|
|
sudo rm -rf "$raspap_dir"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-06-24 23:42:15 +02:00
|
|
|
# Removes installed packages
|
|
|
|
function remove_installed_packages() {
|
|
|
|
install_log "Removing installed packages"
|
|
|
|
echo -n "Remove the following installed packages? lighttpd $php_package git hostapd dnsmasq vnstat [y/N]: "
|
|
|
|
read answer
|
|
|
|
if [ "$answer" != 'n' ] && [ "$answer" != 'N' ]; then
|
|
|
|
echo "Removing packages."
|
|
|
|
sudo apt-get remove lighttpd $php_package git hostapd dnsmasq vnstat
|
|
|
|
sudo apt-get autoremove
|
|
|
|
else
|
|
|
|
echo "Leaving packages installed."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-10-03 07:09:55 +02:00
|
|
|
# Removes www-data from sudoers
|
|
|
|
function clean_sudoers() {
|
|
|
|
# should this check for only our commands?
|
|
|
|
sudo sed -i '/www-data/d' /etc/sudoers
|
|
|
|
}
|
|
|
|
|
|
|
|
function remove_raspap() {
|
|
|
|
config_uninstallation
|
|
|
|
check_for_backups
|
|
|
|
remove_raspap_directories
|
2019-06-24 23:42:15 +02:00
|
|
|
remove_installed_packages
|
2017-10-03 07:09:55 +02:00
|
|
|
clean_sudoers
|
|
|
|
}
|
|
|
|
|
|
|
|
remove_raspap
|