using apt_option everywhere

This commit is contained in:
Steven Foerster
2020-04-19 01:30:23 -04:00
46 changed files with 4306 additions and 1128 deletions

View File

@@ -22,6 +22,7 @@ readonly raspap_dnsmasq="/etc/dnsmasq.d/090_raspap.conf"
readonly raspap_adblock="/etc/dnsmasq.d/090_adblock.conf"
readonly raspap_sysctl="/etc/sysctl.d/90_raspap.conf"
readonly rulesv4="/etc/iptables/rules.v4"
readonly notracking_url="https://raw.githubusercontent.com/notracking/hosts-blocklists/master/"
webroot_dir="/var/www/html"
git_source_url="https://github.com/$repo" # $repo from install.raspap.com
@@ -70,7 +71,7 @@ function _get_linux_distro() {
CODENAME=$VERSION_CODENAME
DESC=$PRETTY_NAME
else
_install_error "Unsupported Linux distribution"
_install_status 1 "Unsupported Linux distribution"
fi
}
@@ -87,9 +88,9 @@ function _set_php_package() {
php_package="php7.0-cgi"
phpcgiconf="/etc/php/7.0/cgi/php.ini" ;;
"8")
_install_error "${DESC} and php5 are not supported. Please upgrade." ;;
_install_status 1 "${DESC} and php5 are not supported. Please upgrade." ;;
*)
_install_error "${DESC} is unsupported. Please install on a supported distro." ;;
_install_status 1 "${DESC} is unsupported. Please install on a supported distro." ;;
esac
}
@@ -99,8 +100,8 @@ function _install_dependencies() {
_set_php_package
if [ "$php_package" = "php7.4-cgi" ]; then
echo "Adding apt-repository ppa:ondrej/php"
sudo apt-get install $apt_option software-properties-common || _install_error "Unable to install dependency"
sudo add-apt-repository $apt_option ppa:ondrej/php || _install_error "Unable to add-apt-repository ppa:ondrej/php"
sudo apt-get install $apt_option software-properties-common || _install_status 1 "Unable to install dependency"
sudo add-apt-repository $apt_option ppa:ondrej/php || _install_status 1 "Unable to add-apt-repository ppa:ondrej/php"
fi
if [ ${OS,,} = "debian" ] || [ ${OS,,} = "ubuntu" ]; then
dhcpcd_package="dhcpcd5"
@@ -108,7 +109,8 @@ function _install_dependencies() {
# Set dconf-set-selections
echo iptables-persistent iptables-persistent/autosave_v4 boolean true | sudo debconf-set-selections
echo iptables-persistent iptables-persistent/autosave_v6 boolean true | sudo debconf-set-selections
sudo apt-get install $apt_option lighttpd git hostapd dnsmasq iptables-persistent $php_package $dhcpcd_package vnstat qrencode || _install_error "Unable to install dependencies"
sudo apt-get install $apt_option lighttpd git hostapd dnsmasq iptables-persistent $php_package $dhcpcd_package vnstat qrencode || _install_status 1 "Unable to install dependencies"
_install_status 0
}
# Enables PHP for lighttpd and restarts service for settings to take effect
@@ -116,16 +118,16 @@ function _enable_php_lighttpd() {
_install_log "Enabling PHP for lighttpd"
sudo lighttpd-enable-mod fastcgi-php
sudo service lighttpd force-reload
sudo systemctl restart lighttpd.service || _install_error "Unable to restart lighttpd"
sudo systemctl restart lighttpd.service || _install_status 1 "Unable to restart lighttpd"
}
# Verifies existence and permissions of RaspAP directory
function _create_raspap_directories() {
_install_log "Creating RaspAP directories"
if [ -d "$raspap_dir" ]; then
sudo mv $raspap_dir "$raspap_dir.`date +%F-%R`" || _install_error "Unable to move old '$raspap_dir' out of the way"
sudo mv $raspap_dir "$raspap_dir.`date +%F-%R`" || _install_status 1 "Unable to move old '$raspap_dir' out of the way"
fi
sudo mkdir -p "$raspap_dir" || _install_error "Unable to create directory '$raspap_dir'"
sudo mkdir -p "$raspap_dir" || _install_status 1 "Unable to create directory '$raspap_dir'"
# Create a directory for existing file backups.
sudo mkdir -p "$raspap_dir/backups"
@@ -137,55 +139,60 @@ function _create_raspap_directories() {
echo "Adding /etc/dhcpcd.conf as base configuration"
cat /etc/dhcpcd.conf | sudo tee -a /etc/raspap/networking/defaults > /dev/null
echo "Changing file ownership of $raspap_dir"
sudo chown -R $raspap_user:$raspap_user "$raspap_dir" || _install_error "Unable to change file ownership for '$raspap_dir'"
sudo chown -R $raspap_user:$raspap_user "$raspap_dir" || _install_status 1 "Unable to change file ownership for '$raspap_dir'"
}
# Generate hostapd logging and service control scripts
function _create_hostapd_scripts() {
_install_log "Creating hostapd logging & control scripts"
sudo mkdir $raspap_dir/hostapd || _install_error "Unable to create directory '$raspap_dir/hostapd'"
sudo mkdir $raspap_dir/hostapd || _install_status 1 "Unable to create directory '$raspap_dir/hostapd'"
# Move logging shell scripts
sudo cp "$webroot_dir/installers/"*log.sh "$raspap_dir/hostapd" || _install_error "Unable to move logging scripts"
sudo cp "$webroot_dir/installers/"*log.sh "$raspap_dir/hostapd" || _install_status 1 "Unable to move logging scripts"
# Move service control shell scripts
sudo cp "$webroot_dir/installers/"service*.sh "$raspap_dir/hostapd" || _install_error "Unable to move service control scripts"
sudo cp "$webroot_dir/installers/"service*.sh "$raspap_dir/hostapd" || _install_status 1 "Unable to move service control scripts"
# Make enablelog.sh and disablelog.sh not writable by www-data group.
sudo chown -c root:"$raspap_user" "$raspap_dir/hostapd/"*.sh || _install_error "Unable change owner and/or group"
sudo chmod 750 "$raspap_dir/hostapd/"*.sh || _install_error "Unable to change file permissions"
sudo chown -c root:"$raspap_user" "$raspap_dir/hostapd/"*.sh || _install_status 1 "Unable change owner and/or group"
sudo chmod 750 "$raspap_dir/hostapd/"*.sh || _install_status 1 "Unable to change file permissions"
_install_status 0
}
# Generate lighttpd service control scripts
function _create_lighttpd_scripts() {
_install_log "Creating lighttpd control scripts"
sudo mkdir $raspap_dir/lighttpd || _install_error "Unable to create directory '$raspap_dir/lighttpd"
sudo mkdir $raspap_dir/lighttpd || _install_status 1 "Unable to create directory '$raspap_dir/lighttpd"
# Move service control shell scripts
sudo cp "$webroot_dir/installers/"configport.sh "$raspap_dir/lighttpd" || _install_error "Unable to move service control scripts"
echo "Copying configport.sh to $raspap_dir/lighttpd"
sudo cp "$webroot_dir/installers/"configport.sh "$raspap_dir/lighttpd" || _install_status 1 "Unable to move service control scripts"
# Make configport.sh writable by www-data group
sudo chown -c root:"$raspap_user" "$raspap_dir/lighttpd/"*.sh || _install_error "Unable change owner and/or group"
sudo chmod 750 "$raspap_dir/lighttpd/"*.sh || _install_error "Unable to change file permissions"
echo "Changing file ownership"
sudo chown -c root:"$raspap_user" "$raspap_dir/lighttpd/"*.sh || _install_status 1 "Unable change owner and/or group"
sudo chmod 750 "$raspap_dir/lighttpd/"*.sh || _install_status 1 "Unable to change file permissions"
_install_status 0
}
# Prompt to install adblock
# Prompt to install ad blocking
function _prompt_install_adblock() {
if [ "$install_adblock" == 1 ]; then
_install_log "Configure ad blocking (Beta)"
echo -n "Download blocklists and enable ad blocking? [Y/n]: "
if [ "$assume_yes" == 0 ]; then
read answer < /dev/tty
if [ "$answer" != "${answer#[Nn]}" ]; then
echo -e
else
_install_adblock
fi
_install_log "Configure ad blocking (Beta)"
echo -n "Install ad blocking and enable list management? [Y/n]: "
if [ "$assume_yes" == 0 ]; then
read answer < /dev/tty
if [ "$answer" != "${answer#[Nn]}" ]; then
echo -e
else
_install_adblock
fi
elif [ "$adblock_option" == 1 ]; then
_install_adblock
else
echo "(Skipped)"
fi
}
# Download notracking adblock lists and enable option
function _install_adblock() {
_install_log "Creating ad block base configuration (Beta)"
notracking_url="https://raw.githubusercontent.com/notracking/hosts-blocklists/master/"
_install_log "Creating ad blocking base configuration (Beta)"
if [ ! -d "$raspap_dir/adblock" ]; then
echo "Creating $raspap_dir/adblock"
sudo mkdir -p "$raspap_dir/adblock"
@@ -193,44 +200,44 @@ function _install_adblock() {
if [ ! -f /tmp/hostnames.txt ]; then
echo "Fetching latest hostnames list"
wget ${notracking_url}hostnames.txt -q --show-progress --progress=bar:force -O /tmp/hostnames.txt 2>&1 \
|| _install_error "Unable to download notracking hostnames"
|| _install_status 1 "Unable to download notracking hostnames"
fi
if [ ! -f /tmp/domains.txt ]; then
echo "Fetching latest domains list"
wget ${notracking_url}domains.txt -q --show-progress --progress=bar:force -O /tmp/domains.txt 2>&1 \
|| _install_error "Unable to download notracking domains"
|| _install_status 1 "Unable to download notracking domains"
fi
echo "Adding blocklists to $raspap_dir/adblock"
sudo cp /tmp/hostnames.txt $raspap_dir/adblock || _install_error "Unable to move notracking hostnames"
sudo cp /tmp/domains.txt $raspap_dir/adblock || _install_error "Unable to move notracking domains"
sudo cp /tmp/hostnames.txt $raspap_dir/adblock || _install_status 1 "Unable to move notracking hostnames"
sudo cp /tmp/domains.txt $raspap_dir/adblock || _install_status 1 "Unable to move notracking domains"
echo "Moving and setting permissions for blocklist update script"
sudo cp "$webroot_dir/installers/"update_blocklist.sh "$raspap_dir/adblock" || _install_error "Unable to move blocklist update script"
sudo cp "$webroot_dir/installers/"update_blocklist.sh "$raspap_dir/adblock" || _install_status 1 "Unable to move blocklist update script"
# Make blocklists and update script writable by www-data group
sudo chown -c root:"$raspap_user" "$raspap_dir/adblock/"*.* || _install_error "Unable to change owner/group"
sudo chown -c root:"$raspap_user" "$raspap_dir/adblock/"*.* || _install_status 1 "Unable to change owner/group"
sudo chmod 750 "$raspap_dir/adblock/"*.sh || install_error "Unable to change file permissions"
# Create 090_adblock.conf and write values to /etc/dnsmasq.d
if [ ! -f "$raspap_adblock" ]; then
echo "Adding 090_addblock.conf to /etc/dnsmasq.d"
sudo touch "$raspap_adblock"
echo "conf-file=$raspap_dir/adblock/domains.txt" | sudo tee -a "$raspap_adblock" > /dev/null || _install_error "Unable to write to $raspap_adblock"
echo "addn-hosts=$raspap_dir/adblock/hostnames.txt" | sudo tee -a "$raspap_adblock" > /dev/null || _install_error "Unable to write to $raspap_adblock"
echo "conf-file=$raspap_dir/adblock/domains.txt" | sudo tee -a "$raspap_adblock" > /dev/null || _install_status 1 "Unable to write to $raspap_adblock"
echo "addn-hosts=$raspap_dir/adblock/hostnames.txt" | sudo tee -a "$raspap_adblock" > /dev/null || _install_status 1 "Unable to write to $raspap_adblock"
fi
# Remove dhcp-option=6 in dnsmasq.d/090_raspap.conf to force local DNS resolution for DHCP clients
echo "Enabling local DNS name resolution for DHCP clients"
sudo sed -i '/dhcp-option=6/d' $raspap_dnsmasq || _install_error "Unable to modify $raspap_dnsmasq"
sudo sed -i '/dhcp-option=6/d' $raspap_dnsmasq || _install_status 1 "Unable to modify $raspap_dnsmasq"
echo "Enabling ad blocking management option"
sudo sed -i "s/\('RASPI_ADBLOCK_ENABLED', \)false/\1true/g" "$webroot_dir/includes/config.php" || _install_error "Unable to modify config.php"
echo "Done."
sudo sed -i "s/\('RASPI_ADBLOCK_ENABLED', \)false/\1true/g" "$webroot_dir/includes/config.php" || _install_status 1 "Unable to modify config.php"
_install_status 0
}
# Prompt to install openvpn
function _prompt_install_openvpn() {
_install_log "Setting up OpenVPN support"
_install_log "Configure OpenVPN support"
echo -n "Install OpenVPN and enable client configuration? [Y/n]: "
if [ "$assume_yes" == 0 ]; then
read answer < /dev/tty
@@ -241,55 +248,59 @@ function _prompt_install_openvpn() {
fi
elif [ "$ovpn_option" == 1 ]; then
_install_openvpn
else
echo "(Skipped)"
fi
}
# Install openvpn and enable client configuration option
function _install_openvpn() {
_install_log "Installing OpenVPN and enabling client configuration"
sudo apt-get install $apt_option openvpn || _install_error "Unable to install openvpn"
sudo sed -i "s/\('RASPI_OPENVPN_ENABLED', \)false/\1true/g" "$webroot_dir/includes/config.php" || _install_error "Unable to modify config.php"
sudo apt-get install $apt_option openvpn || _install_status 1 "Unable to install openvpn"
sudo sed -i "s/\('RASPI_OPENVPN_ENABLED', \)false/\1true/g" "$webroot_dir/includes/config.php" || _install_status 1 "Unable to modify config.php"
echo "Enabling openvpn-client service on boot"
sudo systemctl enable openvpn-client@client || _install_error "Unable to enable openvpn-client daemon"
_create_openvpn_scripts || _install_error "Unable to create openvpn control scripts"
sudo systemctl enable openvpn-client@client || _install_status 1 "Unable to enable openvpn-client daemon"
_create_openvpn_scripts || _install_status 1 "Unable to create openvpn control scripts"
}
# Generate openvpn logging and auth control scripts
function _create_openvpn_scripts() {
_install_log "Creating OpenVPN control scripts"
sudo mkdir $raspap_dir/openvpn || _install_error "Unable to create directory '$raspap_dir/openvpn'"
sudo mkdir $raspap_dir/openvpn || _install_status 1 "Unable to create directory '$raspap_dir/openvpn'"
# Move service auth control shell scripts
sudo cp "$webroot_dir/installers/"configauth.sh "$raspap_dir/openvpn" || _install_error "Unable to move auth control script"
sudo cp "$webroot_dir/installers/"configauth.sh "$raspap_dir/openvpn" || _install_status 1 "Unable to move auth control script"
# Make configauth.sh writable by www-data group
sudo chown -c root:"$raspap_user" "$raspap_dir/openvpn/"*.sh || _install_error "Unable change owner and/or group"
sudo chmod 750 "$raspap_dir/openvpn/"*.sh || _install_error "Unable to change file permissions"
sudo chown -c root:"$raspap_user" "$raspap_dir/openvpn/"*.sh || _install_status 1 "Unable change owner and/or group"
sudo chmod 750 "$raspap_dir/openvpn/"*.sh || _install_status 1 "Unable to change file permissions"
_install_status 0
}
# Fetches latest files from github to webroot
function _download_latest_files() {
if [ ! -d "$webroot_dir" ]; then
sudo mkdir -p $webroot_dir || _install_error "Unable to create new webroot directory"
sudo mkdir -p $webroot_dir || _install_status 1 "Unable to create new webroot directory"
fi
if [ -d "$webroot_dir" ]; then
sudo mv $webroot_dir "$webroot_dir.`date +%F-%R`" || _install_error "Unable to remove old webroot directory"
sudo mv $webroot_dir "$webroot_dir.`date +%F-%R`" || _install_status 1 "Unable to remove old webroot directory"
fi
_install_log "Cloning latest files from github"
git clone --branch $branch --depth 1 $git_source_url /tmp/raspap-webgui || _install_error "Unable to download files from github"
git clone --branch $branch --depth 1 $git_source_url /tmp/raspap-webgui || _install_status 1 "Unable to download files from github"
sudo mv /tmp/raspap-webgui $webroot_dir || _install_error "Unable to move raspap-webgui to web root"
sudo mv /tmp/raspap-webgui $webroot_dir || _install_status 1 "Unable to move raspap-webgui to web root"
_install_status 0
}
# Sets files ownership in web root directory
function _change_file_ownership() {
if [ ! -d "$webroot_dir" ]; then
_install_error "Web root directory doesn't exist"
_install_status 1 "Web root directory doesn't exist"
fi
_install_log "Changing file ownership in web root directory"
sudo chown -R $raspap_user:$raspap_user "$webroot_dir" || _install_error "Unable to change file ownership for '$webroot_dir'"
sudo chown -R $raspap_user:$raspap_user "$webroot_dir" || _install_status 1 "Unable to change file ownership for '$webroot_dir'"
}
# Check for existing configuration files
@@ -321,58 +332,63 @@ function _check_for_old_configs() {
sudo ln -sf "${raspap_dir}/backups/${filename}.`date +%F-%R`" "${raspap_dir}/backups/${filename}"
fi
done
_install_status 0
}
# Move configuration file to the correct location
function _move_config_file() {
if [ ! -d "$raspap_dir" ]; then
_install_error "'$raspap_dir' directory doesn't exist"
_install_status 1 "'$raspap_dir' directory doesn't exist"
fi
_install_log "Moving configuration file to '$raspap_dir'"
sudo cp "$webroot_dir"/raspap.php "$raspap_dir" || _install_error "Unable to move files to '$raspap_dir'"
sudo chown -R $raspap_user:$raspap_user "$raspap_dir" || _install_error "Unable to change file ownership for '$raspap_dir'"
_install_log "Moving configuration file to $raspap_dir"
sudo cp "$webroot_dir"/raspap.php "$raspap_dir" || _install_status 1 "Unable to move files to '$raspap_dir'"
sudo chown -R $raspap_user:$raspap_user "$raspap_dir" || _install_status 1 "Unable to change file ownership for '$raspap_dir'"
}
# Set up default configuration
function _default_configuration() {
_install_log "Applying default configuration to installed services"
if [ -f /etc/default/hostapd ]; then
sudo mv /etc/default/hostapd /tmp/default_hostapd.old || _install_error "Unable to remove old /etc/default/hostapd file"
sudo mv /etc/default/hostapd /tmp/default_hostapd.old || _install_status 1 "Unable to remove old /etc/default/hostapd file"
fi
sudo cp $webroot_dir/config/default_hostapd /etc/default/hostapd || _install_error "Unable to move hostapd defaults file"
sudo cp $webroot_dir/config/hostapd.conf /etc/hostapd/hostapd.conf || _install_error "Unable to move hostapd configuration file"
sudo cp $webroot_dir/config/dnsmasq.conf $raspap_dnsmasq || _install_error "Unable to move dnsmasq configuration file"
sudo cp $webroot_dir/config/dhcpcd.conf /etc/dhcpcd.conf || _install_error "Unable to move dhcpcd configuration file"
sudo cp $webroot_dir/config/default_hostapd /etc/default/hostapd || _install_status 1 "Unable to move hostapd defaults file"
sudo cp $webroot_dir/config/hostapd.conf /etc/hostapd/hostapd.conf || _install_status 1 "Unable to move hostapd configuration file"
sudo cp $webroot_dir/config/dnsmasq.conf $raspap_dnsmasq || _install_status 1 "Unable to move dnsmasq configuration file"
sudo cp $webroot_dir/config/dhcpcd.conf /etc/dhcpcd.conf || _install_status 1 "Unable to move dhcpcd configuration file"
echo "Checking for existence of /etc/dnsmasq.d"
[ -d /etc/dnsmasq.d ] || sudo mkdir /etc/dnsmasq.d
echo "Copying bridged AP config to /etc/systemd/network"
sudo systemctl stop systemd-networkd
sudo systemctl disable systemd-networkd
sudo cp $webroot_dir/config/raspap-bridge-br0.netdev /etc/systemd/network/raspap-bridge-br0.netdev || _install_error "Unable to move br0 netdev file"
sudo cp $webroot_dir/config/raspap-br0-member-eth0.network /etc/systemd/network/raspap-br0-member-eth0.network || _install_error "Unable to move br0 member file"
sudo cp $webroot_dir/config/raspap-bridge-br0.netdev /etc/systemd/network/raspap-bridge-br0.netdev || _install_status 1 "Unable to move br0 netdev file"
sudo cp $webroot_dir/config/raspap-br0-member-eth0.network /etc/systemd/network/raspap-br0-member-eth0.network || _install_status 1 "Unable to move br0 member file"
echo "Copying primary RaspAP config to includes/config.php"
if [ ! -f "$webroot_dir/includes/config.php" ]; then
sudo cp "$webroot_dir/config/config.php" "$webroot_dir/includes/config.php"
fi
_install_status 0
}
# Install and enable RaspAP daemon
function _enable_raspap_daemon() {
_install_log "Enabling RaspAP daemon"
echo "Disable with: sudo systemctl disable raspapd.service"
sudo cp $webroot_dir/installers/raspapd.service /lib/systemd/system/ || _install_error "Unable to move raspap.service file"
sudo cp $webroot_dir/installers/raspapd.service /lib/systemd/system/ || _install_status 1 "Unable to move raspap.service file"
sudo systemctl daemon-reload
sudo systemctl enable raspapd.service || _install_error "Failed to enable raspap.service"
sudo systemctl enable raspapd.service || _install_status 1 "Failed to enable raspap.service"
}
# Configure IP forwarding, set IP tables rules, prompt to install RaspAP daemon
function _configure_networking() {
_install_log "Configuring networking"
echo "Enabling IP forwarding"
echo "net.ipv4.ip_forward=1" | sudo tee $raspap_sysctl > /dev/null || _install_error "Unable to set IP forwarding"
sudo sysctl -p $raspap_sysctl || _install_error "Unable to execute sysctl"
sudo /etc/init.d/procps restart || _install_error "Unable to execute procps"
echo "net.ipv4.ip_forward=1" | sudo tee $raspap_sysctl > /dev/null || _install_status 1 "Unable to set IP forwarding"
sudo sysctl -p $raspap_sysctl || _install_status 1 "Unable to execute sysctl"
sudo /etc/init.d/procps restart || _install_status 1 "Unable to execute procps"
echo "Checking iptables rules"
rules=(
@@ -385,14 +401,14 @@ function _configure_networking() {
else
rule=$(sed -e 's/^\(-A POSTROUTING\)/-t nat \1/' <<< $rule)
echo "Adding rule: ${rule}"
sudo iptables $rule || _install_error "Unable to execute iptables"
sudo iptables $rule || _install_status 1 "Unable to execute iptables"
added=true
fi
done
# Persist rules if added
if [ "$added" = true ]; then
echo "Persisting IP tables rules"
sudo iptables-save | sudo tee $rulesv4 > /dev/null || _install_error "Unable to execute iptables-save"
sudo iptables-save | sudo tee $rulesv4 > /dev/null || _install_status 1 "Unable to execute iptables-save"
fi
# Prompt to install RaspAP daemon
@@ -408,6 +424,7 @@ function _configure_networking() {
echo -e
_enable_raspap_daemon
fi
_install_status 0
}
# Add sudoers file to /etc/sudoers.d/ and set file permissions
@@ -416,8 +433,8 @@ function _patch_system_files() {
# Create sudoers if not present
if [ ! -f $raspap_sudoers ]; then
_install_log "Adding raspap.sudoers to ${raspap_sudoers}"
sudo cp "$webroot_dir/installers/raspap.sudoers" $raspap_sudoers || _install_error "Unable to apply raspap.sudoers to $raspap_sudoers"
sudo chmod 0440 $raspap_sudoers || _install_error "Unable to change file permissions for $raspap_sudoers"
sudo cp "$webroot_dir/installers/raspap.sudoers" $raspap_sudoers || _install_status 1 "Unable to apply raspap.sudoers to $raspap_sudoers"
sudo chmod 0440 $raspap_sudoers || _install_status 1 "Unable to change file permissions for $raspap_sudoers"
fi
# Add symlink to prevent wpa_cli cmds from breaking with multiple wlan interfaces
@@ -430,6 +447,7 @@ function _patch_system_files() {
_install_log "Unmasking and enabling hostapd service"
sudo systemctl unmask hostapd.service
sudo systemctl enable hostapd.service
_install_status 0
}
@@ -479,7 +497,7 @@ function _optimize_php() {
if [ -f "/usr/sbin/phpenmod" ]; then
sudo phpenmod opcache
else
_install_warning "phpenmod not found."
_install_status 2 "phpenmod not found."
fi
fi
fi
@@ -497,7 +515,7 @@ function _install_complete() {
echo "Installation reboot aborted."
exit 0
fi
sudo shutdown -r now || _install_error "Unable to execute shutdown"
sudo shutdown -r now || _install_status 1 "Unable to execute shutdown"
fi
fi
}
@@ -518,8 +536,8 @@ function _install_raspap() {
_move_config_file
_default_configuration
_configure_networking
_prompt_install_openvpn
_prompt_install_adblock
_prompt_install_openvpn
_patch_system_files
_install_complete
}

View File

@@ -12,6 +12,8 @@
# Installs mkcert and generates an SSL certificate for lighttpd
# -o, --openvpn <flag>
# Used with -y, --yes, sets OpenVPN install option (0=no install)
# -a, --adblock <flag>
# Used with -y, --yes, sets Adblock install option (0=no install)
# -r, --repo, --repository <name>
# Overrides the default GitHub repo (billz/raspap-webgui)
# -b, --branch <name>
@@ -36,6 +38,17 @@ repo="billz/raspap-webgui"
branch="master"
assume_yes=0
ovpn_option=1
adblock_option=1
# Define colors
readonly ANSI_RED="\033[0;31m"
readonly ANSI_GREEN="\033[0;32m"
readonly ANSI_YELLOW="\033[0;33m"
readonly ANSI_RASPBERRY="\033[0;35m"
readonly ANSI_ERROR="\033[1;37;41m"
readonly ANSI_RESET="\033[m"
# Fetch latest release from GitHub API
readonly RASPAP_LATEST=$(curl -s "https://api.github.com/repos/$repo/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")' )
# Define usage notes
@@ -44,6 +57,7 @@ Usage: raspbian.sh [OPTION]\n
-y, --yes, --assume-yes\n\tAssumes "yes" as an answer to all prompts
-c, --cert, --certificate\n\tInstalls an SSL certificate for lighttpd
-o, --openvpn <flag>\n\tUsed with -y, --yes, sets OpenVPN install option (0=no install)
-a, --adblock <flag>\n\tUsed with -y, --yes, sets Adblock install option (0=no install)
-r, --repo, --repository <name>\n\tOverrides the default GitHub repo (billz/raspap-webgui)
-b, --branch <name>\n\tOverrides the default git branch (master)
-h, --help\n\tOutputs usage notes and exits
@@ -63,7 +77,8 @@ while :; do
shift
;;
-a|--adblock)
install_adblock=1
adblock_option="$2"
shift
;;
-c|--cert|--certificate)
install_cert=1
@@ -81,9 +96,9 @@ while :; do
exit 1
;;
-v|--version)
printf "RaspAP v${RASPAP_LATEST} - simple AP setup and wifi mangement for the RaspberryPi\n"
printf "RaspAP v${RASPAP_LATEST} - Simple AP setup & WiFi management for Debian-based devices\n"
exit 1
;;
;;
-*|--*)
echo "Unknown option: $1"
printf "$usage"
@@ -100,10 +115,7 @@ UPDATE_URL="https://raw.githubusercontent.com/$repo/$branch/"
# Outputs a welcome message
function _display_welcome() {
raspberry='\033[0;35m'
green='\033[1;32m'
echo -e "${raspberry}\n"
echo -e "${ANSI_RASPBERRY}\n"
echo -e " 888888ba .d888888 888888ba"
echo -e " 88 8b d8 88 88 8b"
echo -e "a88aaaa8P' .d8888b. .d8888b. 88d888b. 88aaaaa88a a88aaaa8P"
@@ -112,29 +124,28 @@ function _display_welcome() {
echo -e " dP dP 88888P8 88888P 88Y888P 88 88 dP"
echo -e " 88"
echo -e " dP version ${RASPAP_LATEST}"
echo -e "${green}"
echo -e "The Quick Installer will guide you through a few easy steps\n\n"
echo -e "${ANSI_GREEN}"
echo -e "The Quick Installer will guide you through a few easy steps${ANSI_RESET}\n\n"
}
# Outputs a RaspAP Install log line
function _install_log() {
echo -e "\033[1;32mRaspAP Install: $*\033[m"
echo -e "${ANSI_GREEN}RaspAP Install: $1${ANSI_RESET}"
}
# 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
}
# Outputs a RaspAP Warning line
function _install_warning() {
echo -e "\033[1;33mWarning: $*\033[m"
}
# Outputs a RaspAP divider
function _install_divider() {
echo -e "\033[1;32m***************************************************************$*\033[m"
# Outputs a RaspAP status indicator
function _install_status() {
case $1 in
0)
echo -e "[$ANSI_GREEN \U2713 ok $ANSI_RESET] $2"
;;
1)
echo -e "[$ANSI_RED \U2718 error $ANSI_RESET] $ANSI_ERROR $2 $ANSI_RESET"
;;
2)
echo -e "[$ANSI_YELLOW \U26A0 warning $ANSI_RESET] $2"
;;
esac
}
function _update_system_packages() {

View File

@@ -1,66 +1,95 @@
#!/bin/bash
raspap_dir="/etc/raspap"
raspap_user="www-data"
version=`sed 's/\..*//' /etc/debian_version`
#
# RaspAP uninstall functions
# Author: @billz <billzimmerman@gmail.com>
# License: GNU General Public License v3.0
#
# You are not obligated to bundle the LICENSE file with your RaspAP projects as long
# as you leave these references intact in the header comments of your source files.
# Determine Raspbian version and set default home location for lighttpd
webroot_dir="/var/www/html"
if [ $version -eq 10 ]; then
version_msg="Raspbian 10.0 (Buster)"
php_package="php7.1-cgi"
elif [ $version -eq 9 ]; then
version_msg="Raspbian 9.0 (Stretch)"
php_package="php7.0-cgi"
else
version_msg="Raspbian 8.0 (Jessie) or earlier"
webroot_dir="/var/www"
php_package="php5-cgi"
fi
# Exit on error
set -o errexit
# Exit on error inside functions
set -o errtrace
# Turn on traces, disabled by default
# set -o xtrace
phpcgiconf=""
if [ "$php_package" = "php7.1-cgi" ]; then
phpcgiconf="/etc/php/7.1/cgi/php.ini"
elif [ "$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
# Set defaults
readonly raspap_dir="/etc/raspap"
readonly raspap_user="www-data"
readonly raspap_sudoers="/etc/sudoers.d/090_raspap"
readonly raspap_dnsmasq="/etc/dnsmasq.d/090_raspap.conf"
readonly raspap_sysctl="/etc/sysctl.d/90_raspap.conf"
readonly rulesv4="/etc/iptables/rules.v4"
webroot_dir="/var/www/html"
# Determines host Linux distrubtion details
function _get_linux_distro() {
if type lsb_release >/dev/null 2>&1; then # linuxbase.org
OS=$(lsb_release -si)
RELEASE=$(lsb_release -sr)
CODENAME=$(lsb_release -sc)
DESC=$(lsb_release -sd)
elif [ -f /etc/os-release ]; then # freedesktop.org
. /etc/os-release
OS=$ID
RELEASE=$VERSION_ID
CODENAME=$VERSION_CODENAME
DESC=$PRETTY_NAME
else
_install_error "Unsupported Linux distribution"
fi
}
# Sets php package option based on Linux version, abort if unsupported distro
function _set_php_package() {
case $RELEASE in
"18.04"|"19.10") # Ubuntu Server
php_package="php7.4-cgi"
phpcgiconf="/etc/php/7.4/cgi/php.ini" ;;
"10")
php_package="php7.3-cgi"
phpcgiconf="/etc/php/7.3/cgi/php.ini" ;;
"9")
php_package="php7.0-cgi"
phpcgiconf="/etc/php/7.0/cgi/php.ini" ;;
esac
}
# Outputs a RaspAP Install log line
function install_log() {
echo -e "\033[1;32mRaspAP Install: $*\033[m"
function _install_log() {
echo -e "\033[1;32mRaspAP Uninstall: $*\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"
function _install_error() {
echo -e "\033[1;37;41mRaspAP Uninstall 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]: "
function _config_uninstallation() {
_install_log "Configure uninstall of RaspAP"
_get_linux_distro
echo "Detected ${DESC}"
echo "RaspAP install directory: ${raspap_dir}"
echo -n "Lighttpd install directory: ${webroot_dir}? [Y/n]: "
read answer
if [[ $answer != "y" ]]; then
if [ "$answer" != "${answer#[Nn]}" ]; then
read -e -p "Enter alternate lighttpd directory: " -i "/var/www/html" webroot_dir
fi
echo "Uninstall from lighttpd directory: ${webroot_dir}"
echo -n "Uninstall RaspAP with these values? [Y/n]: "
read answer
if [[ "$answer" != "${answer#[Nn]}" ]]; then
echo "Installation aborted."
exit 0
fi
}
# Checks for/restore backup files
function check_for_backups() {
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
@@ -89,63 +118,101 @@ function check_for_backups() {
sudo cp "$raspap_dir/backups/php.ini" "$phpcgiconf"
fi
fi
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]: "
if [[ $answer -ne 'n' ]]; then
sed -i '/#RASPAP/d' /etc/rc.local
fi
fi
fi
fi
}
# Removes RaspAP directories
function remove_raspap_directories() {
install_log "Removing RaspAP Directories"
function _remove_raspap_directories() {
_install_log "Removing RaspAP Directories"
if [ ! -d "$raspap_dir" ]; then
install_error "RaspAP Configuration directory not found. Exiting!"
_install_error "RaspAP Configuration directory not found. Exiting."
fi
if [ ! -d "$webroot_dir" ]; then
install_error "RaspAP Installation directory not found. Exiting!"
_install_error "RaspAP Installation directory not found. Exiting."
fi
sudo rm -rf "$webroot_dir"/* || _install_error "Unable to remove $webroot_dir"
sudo rm -rf "$raspap_dir" || _install_error "Unable to remove $raspap_dir"
}
sudo rm -rf "$webroot_dir"/*
sudo rm -rf "$raspap_dir"
# Removes raspapd.service
function _remove_raspap_service() {
_install_log "Removing raspapd.service"
sudo rm /lib/systemd/system/raspapd.service || _install_error "Unable to remove raspap.service file"
sudo systemctl daemon-reload
sudo systemctl disable raspapd.service || _install_error "Failed to disable raspap.service"
echo "Done."
}
# Restores networking config to pre-install defaults
function _restore_networking() {
_install_log "Restoring networking config to pre-install defaults"
echo "Disabling IP forwarding in $raspap_sysctl"
sudo rm $raspap_sysctl || _install_error "Unable to remove $raspap_sysctl"
sudo /etc/init.d/procps restart || _install_error "Unable to execute procps"
echo "Checking iptables rules"
rules=(
"-A POSTROUTING -j MASQUERADE"
"-A POSTROUTING -s 192.168.50.0/24 ! -d 192.168.50.0/24 -j MASQUERADE"
)
for rule in "${rules[@]}"; do
if grep -- "$rule" $rulesv4 > /dev/null; then
rule=$(sed -e 's/^\(-A POSTROUTING\)/-t nat -D POSTROUTING/' <<< $rule)
echo "Removing rule: ${rule}"
sudo iptables $rule || _install_error "Unable to execute iptables"
removed=true
fi
done
# Persist rules if removed
if [ "$removed" = true ]; then
echo "Removing persistent iptables rules"
sudo iptables-save | sudo tee $rulesv4 > /dev/null || _install_error "Unable to execute iptables-save"
fi
echo "Done."
}
# 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]: "
function _remove_installed_packages() {
_install_log "Removing installed packages"
_set_php_package
if [ ${OS,,} = "debian" ] || [ ${OS,,} = "ubuntu" ]; then
dhcpcd_package="dhcpcd5"
else
dhcpcd_package="dnsmasq"
fi
echo -n "Remove the following installed packages? lighttpd hostapd iptables-persistent $php_package $dhcpcd_package vnstat qrencode [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
sudo apt-get remove lighttpd hostapd iptables-persistent $php_package $dhcpcd_package vnstat qrencode || _install_error "Unable to remove installed packages"
sudo apt-get autoremove || _install_error "Unable to run apt autoremove"
else
echo "Leaving packages installed."
fi
}
# 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_sudoers() {
_install_log "Removing sudoers permissions"
echo "Removing ${raspap_sudoers}"
sudo rm "$raspap_sudoers" || _install_error "Unable to remove $raspap_sudoers"
echo "Done."
}
function remove_raspap() {
config_uninstallation
check_for_backups
remove_raspap_directories
remove_installed_packages
clean_sudoers
function _uninstall_complete() {
_install_log "Uninstall completed"
echo "It is recommended that you reboot your system as a final step."
}
remove_raspap
function _remove_raspap() {
_config_uninstallation
_check_for_backups
_remove_raspap_service
_restore_networking
_remove_raspap_directories
_remove_installed_packages
_remove_sudoers
_uninstall_complete
}
_remove_raspap