2019-06-24 23:57:49 +02:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# RaspAP installation functions.
|
|
|
|
# author: @billz
|
|
|
|
# license: GNU General Public License v3.0
|
|
|
|
|
2016-06-16 15:16:19 +02:00
|
|
|
raspap_dir="/etc/raspap"
|
|
|
|
raspap_user="www-data"
|
2019-06-24 23:57:49 +02:00
|
|
|
webroot_dir="/var/www/html"
|
2017-01-27 10:21:53 +01:00
|
|
|
version=`sed 's/\..*//' /etc/debian_version`
|
2020-03-09 13:11:11 +01:00
|
|
|
git_source_url="https://github.com/$repo" # $repo from install.raspap.com
|
2016-08-31 16:30:28 +02:00
|
|
|
|
2019-06-29 09:51:36 +02:00
|
|
|
# Determine Raspbian version, set default home location for lighttpd and
|
2017-11-16 02:24:02 +01:00
|
|
|
# php package to install
|
2019-11-11 10:17:35 +01:00
|
|
|
if [ "$version" -eq "10" ]; then
|
2019-06-29 09:51:36 +02:00
|
|
|
version_msg="Raspbian 10.0 (Buster)"
|
2019-06-25 09:40:02 +02:00
|
|
|
php_package="php7.1-cgi"
|
2019-11-11 10:17:35 +01:00
|
|
|
elif [ "$version" -eq "9" ]; then
|
2019-06-29 09:51:36 +02:00
|
|
|
version_msg="Raspbian 9.0 (Stretch)"
|
2017-11-16 02:24:02 +01:00
|
|
|
php_package="php7.0-cgi"
|
2019-11-11 10:17:35 +01:00
|
|
|
elif [ "$version" -eq "8" ]; then
|
2019-11-22 14:01:59 +01:00
|
|
|
install_error "Raspbian 8.0 (Jessie) and php5 are deprecated. Please upgrade."
|
|
|
|
elif [ "$version" -lt "8" ]; then
|
|
|
|
install_error "Raspbian ${version} is unsupported. Please upgrade."
|
2018-08-31 23:38:30 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
phpcgiconf=""
|
2019-06-25 09:40:02 +02:00
|
|
|
if [ "$php_package" = "php7.1-cgi" ]; then
|
|
|
|
phpcgiconf="/etc/php/7.1/cgi/php.ini"
|
|
|
|
elif [ "$php_package" = "php7.0-cgi" ]; then
|
2018-08-31 23:38:30 +02:00
|
|
|
phpcgiconf="/etc/php/7.0/cgi/php.ini"
|
|
|
|
fi
|
2016-06-16 15:16:19 +02:00
|
|
|
|
|
|
|
### NOTE: all the below functions are overloadable for system-specific installs
|
|
|
|
|
2019-11-18 12:51:59 +01:00
|
|
|
# Prompts user to set options for installation
|
2016-06-16 15:16:19 +02:00
|
|
|
function config_installation() {
|
|
|
|
install_log "Configure installation"
|
2017-05-19 18:33:01 +02:00
|
|
|
echo "Detected ${version_msg}"
|
2017-01-27 10:21:53 +01:00
|
|
|
echo "Install directory: ${raspap_dir}"
|
2019-11-18 12:51:59 +01:00
|
|
|
echo -n "Install to Lighttpd root directory: ${webroot_dir}? [Y/n]: "
|
|
|
|
if [ "$assume_yes" == 0 ]; then
|
2019-11-19 12:42:06 +01:00
|
|
|
read answer < /dev/tty
|
2019-11-18 12:51:59 +01:00
|
|
|
if [ "$answer" != "${answer#[Nn]}" ]; then
|
2019-11-19 12:42:06 +01:00
|
|
|
read -e -p < /dev/tty "Enter alternate Lighttpd directory: " -i "/var/www/html" webroot_dir
|
2019-11-05 08:25:48 +01:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo -e
|
|
|
|
fi
|
|
|
|
echo "Install to Lighttpd directory: ${webroot_dir}"
|
|
|
|
|
2019-11-18 12:51:59 +01:00
|
|
|
echo -n "Complete installation with these values? [Y/n]: "
|
|
|
|
if [ "$assume_yes" == 0 ]; then
|
2019-11-19 12:42:06 +01:00
|
|
|
read answer < /dev/tty
|
2019-11-18 12:51:59 +01:00
|
|
|
if [ "$answer" != "${answer#[Nn]}" ]; then
|
2019-09-30 19:42:04 +02:00
|
|
|
echo "Installation aborted."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo -e
|
2016-06-16 15:16:19 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Runs a system software update to make sure we're using all fresh packages
|
2019-11-07 09:39:33 +01:00
|
|
|
function install_dependencies() {
|
|
|
|
install_log "Installing required packages"
|
2020-02-26 18:51:04 +01:00
|
|
|
sudo apt-get install $apt_option lighttpd $php_package git hostapd dnsmasq vnstat qrencode || install_error "Unable to install dependencies"
|
2016-06-16 15:16:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Enables PHP for lighttpd and restarts service for settings to take effect
|
|
|
|
function enable_php_lighttpd() {
|
|
|
|
install_log "Enabling PHP for lighttpd"
|
|
|
|
|
2017-11-16 02:28:59 +01:00
|
|
|
sudo lighttpd-enable-mod fastcgi-php
|
2017-11-16 02:24:02 +01:00
|
|
|
sudo service lighttpd force-reload
|
2019-11-18 12:51:59 +01:00
|
|
|
sudo systemctl restart lighttpd.service || install_error "Unable to restart lighttpd"
|
2016-06-16 15:16:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Verifies existence and permissions of RaspAP directory
|
|
|
|
function create_raspap_directories() {
|
|
|
|
install_log "Creating RaspAP directories"
|
2016-10-21 23:28:00 +02:00
|
|
|
if [ -d "$raspap_dir" ]; then
|
2017-10-01 21:36:51 +02:00
|
|
|
sudo mv $raspap_dir "$raspap_dir.`date +%F-%R`" || install_error "Unable to move old '$raspap_dir' out of the way"
|
2016-06-16 15:16:19 +02:00
|
|
|
fi
|
2016-10-21 23:28:00 +02:00
|
|
|
sudo mkdir -p "$raspap_dir" || install_error "Unable to create directory '$raspap_dir'"
|
2017-10-27 20:40:30 +02:00
|
|
|
|
2017-10-01 14:54:16 +02:00
|
|
|
# Create a directory for existing file backups.
|
|
|
|
sudo mkdir -p "$raspap_dir/backups"
|
2016-06-16 15:16:19 +02:00
|
|
|
|
2017-10-27 20:40:30 +02:00
|
|
|
# Create a directory to store networking configs
|
|
|
|
sudo mkdir -p "$raspap_dir/networking"
|
|
|
|
# Copy existing dhcpcd.conf to use as base config
|
2017-11-08 09:23:02 +01:00
|
|
|
cat /etc/dhcpcd.conf | sudo tee -a /etc/raspap/networking/defaults
|
2017-10-27 20:40:30 +02:00
|
|
|
|
2016-06-16 15:16:19 +02:00
|
|
|
sudo chown -R $raspap_user:$raspap_user "$raspap_dir" || install_error "Unable to change file ownership for '$raspap_dir'"
|
|
|
|
}
|
|
|
|
|
2019-03-06 11:48:18 +01:00
|
|
|
# Generate hostapd logging and service control scripts
|
|
|
|
function create_hostapd_scripts() {
|
|
|
|
install_log "Creating hostapd logging & control scripts"
|
2017-11-16 23:38:03 +01:00
|
|
|
sudo mkdir $raspap_dir/hostapd || install_error "Unable to create directory '$raspap_dir/hostapd'"
|
|
|
|
|
2019-03-06 11:48:18 +01:00
|
|
|
# Move logging shell scripts
|
2019-08-01 15:07:26 +02:00
|
|
|
sudo cp "$webroot_dir/installers/"*log.sh "$raspap_dir/hostapd" || install_error "Unable to move logging scripts"
|
2019-03-06 11:48:18 +01:00
|
|
|
# Move service control shell scripts
|
2019-08-01 15:07:26 +02:00
|
|
|
sudo cp "$webroot_dir/installers/"service*.sh "$raspap_dir/hostapd" || install_error "Unable to move service control scripts"
|
2018-08-27 23:10:56 +02:00
|
|
|
# Make enablelog.sh and disablelog.sh not writable by www-data group.
|
2019-11-10 23:21:55 +01:00
|
|
|
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"
|
2017-11-02 15:43:41 +01:00
|
|
|
}
|
|
|
|
|
2019-11-10 23:21:55 +01:00
|
|
|
# Generate lighttpd service control scripts
|
|
|
|
function create_lighttpd_scripts() {
|
|
|
|
install_log "Creating lighttpd control scripts"
|
2019-11-18 12:51:59 +01:00
|
|
|
sudo mkdir $raspap_dir/lighttpd || install_error "Unable to create directory '$raspap_dir/lighttpd"
|
2019-11-10 23:21:55 +01:00
|
|
|
|
|
|
|
# Move service control shell scripts
|
|
|
|
sudo cp "$webroot_dir/installers/"configport.sh "$raspap_dir/lighttpd" || install_error "Unable to move service control scripts"
|
2019-11-18 12:51:59 +01:00
|
|
|
# Make configport.sh writable by www-data group
|
2019-11-10 23:21:55 +01:00
|
|
|
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"
|
|
|
|
}
|
2017-11-16 02:24:02 +01:00
|
|
|
|
2019-11-18 12:51:59 +01:00
|
|
|
# Prompt to install openvpn
|
|
|
|
function prompt_install_openvpn() {
|
|
|
|
install_log "Setting up OpenVPN support (beta)"
|
|
|
|
echo -n "Install OpenVPN and enable client configuration? [Y/n]: "
|
|
|
|
if [ "$assume_yes" == 0 ]; then
|
2019-11-19 12:42:06 +01:00
|
|
|
read answer < /dev/tty
|
2019-11-18 12:51:59 +01:00
|
|
|
if [ "$answer" != "${answer#[Nn]}" ]; then
|
|
|
|
echo -e
|
|
|
|
else
|
|
|
|
install_openvpn
|
|
|
|
fi
|
2019-11-22 15:05:49 +01:00
|
|
|
elif [ "$ovpn_option" == 1 ]; then
|
2019-11-18 12:51:59 +01:00
|
|
|
install_openvpn
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Install openvpn and enable client configuration option
|
|
|
|
function install_openvpn() {
|
|
|
|
install_log "Installing OpenVPN and enabling client configuration"
|
|
|
|
sudo apt-get install -y 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"
|
2019-11-22 13:41:19 +01:00
|
|
|
echo "Enabling openvpn-client service on boot"
|
2019-11-22 14:01:59 +01:00
|
|
|
sudo systemctl enable openvpn-client@client || install_error "Unable to enable openvpn-client daemon"
|
2019-11-18 12:51:59 +01:00
|
|
|
create_openvpn_scripts || install_error "Unable to create openvpn control scripts"
|
|
|
|
}
|
|
|
|
|
2019-11-15 09:57:17 +01:00
|
|
|
# Generate openvpn logging and auth control scripts
|
|
|
|
function create_openvpn_scripts() {
|
2019-11-18 12:51:59 +01:00
|
|
|
install_log "Creating OpenVPN control scripts"
|
2019-11-15 09:57:17 +01:00
|
|
|
sudo mkdir $raspap_dir/openvpn || install_error "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"
|
|
|
|
# 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"
|
|
|
|
}
|
|
|
|
|
2016-06-16 15:16:19 +02:00
|
|
|
# Fetches latest files from github to webroot
|
|
|
|
function download_latest_files() {
|
2019-11-05 08:25:48 +01:00
|
|
|
if [ ! -d "$webroot_dir" ]; then
|
|
|
|
sudo mkdir -p $webroot_dir || install_error "Unable to create new webroot directory"
|
|
|
|
fi
|
|
|
|
|
2016-10-23 17:39:33 +02:00
|
|
|
if [ -d "$webroot_dir" ]; then
|
2017-10-01 21:36:51 +02:00
|
|
|
sudo mv $webroot_dir "$webroot_dir.`date +%F-%R`" || install_error "Unable to remove old webroot directory"
|
2016-06-16 15:16:19 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
install_log "Cloning latest files from github"
|
2020-03-10 09:42:08 +01:00
|
|
|
git clone --branch $branch --depth 1 $git_source_url /tmp/raspap-webgui || install_error "Unable to download files from github"
|
2020-03-10 00:05:46 +01:00
|
|
|
|
2016-10-23 17:39:33 +02:00
|
|
|
sudo mv /tmp/raspap-webgui $webroot_dir || install_error "Unable to move raspap-webgui to web root"
|
2016-06-16 15:16:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Sets files ownership in web root directory
|
|
|
|
function change_file_ownership() {
|
|
|
|
if [ ! -d "$webroot_dir" ]; then
|
|
|
|
install_error "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'"
|
|
|
|
}
|
|
|
|
|
2017-10-01 14:54:16 +02:00
|
|
|
# Check for existing /etc/network/interfaces and /etc/hostapd/hostapd.conf files
|
|
|
|
function check_for_old_configs() {
|
|
|
|
if [ -f /etc/network/interfaces ]; then
|
2017-10-03 06:19:35 +02:00
|
|
|
sudo cp /etc/network/interfaces "$raspap_dir/backups/interfaces.`date +%F-%R`"
|
|
|
|
sudo ln -sf "$raspap_dir/backups/interfaces.`date +%F-%R`" "$raspap_dir/backups/interfaces"
|
2017-10-01 14:54:16 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f /etc/hostapd/hostapd.conf ]; then
|
2017-10-03 06:19:35 +02:00
|
|
|
sudo cp /etc/hostapd/hostapd.conf "$raspap_dir/backups/hostapd.conf.`date +%F-%R`"
|
|
|
|
sudo ln -sf "$raspap_dir/backups/hostapd.conf.`date +%F-%R`" "$raspap_dir/backups/hostapd.conf"
|
2017-10-01 21:34:14 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f /etc/dnsmasq.conf ]; then
|
2017-10-03 06:19:35 +02:00
|
|
|
sudo cp /etc/dnsmasq.conf "$raspap_dir/backups/dnsmasq.conf.`date +%F-%R`"
|
|
|
|
sudo ln -sf "$raspap_dir/backups/dnsmasq.conf.`date +%F-%R`" "$raspap_dir/backups/dnsmasq.conf"
|
2017-10-01 21:34:14 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f /etc/dhcpcd.conf ]; then
|
2017-10-03 06:19:35 +02:00
|
|
|
sudo cp /etc/dhcpcd.conf "$raspap_dir/backups/dhcpcd.conf.`date +%F-%R`"
|
|
|
|
sudo ln -sf "$raspap_dir/backups/dhcpcd.conf.`date +%F-%R`" "$raspap_dir/backups/dhcpcd.conf"
|
2017-10-01 14:54:16 +02:00
|
|
|
fi
|
2017-10-21 16:39:29 +02:00
|
|
|
|
|
|
|
if [ -f /etc/rc.local ]; then
|
|
|
|
sudo cp /etc/rc.local "$raspap_dir/backups/rc.local.`date +%F-%R`"
|
|
|
|
sudo ln -sf "$raspap_dir/backups/rc.local.`date +%F-%R`" "$raspap_dir/backups/rc.local"
|
|
|
|
fi
|
2020-03-08 18:16:05 +01:00
|
|
|
|
|
|
|
for file in /etc/systemd/network/raspap-*.net*; do
|
2020-03-10 09:42:08 +01:00
|
|
|
if [-f "${file}" ]; then
|
|
|
|
filename = $(basename $file)
|
|
|
|
sudo cp "$file" "${raspap_dir}/backups/${filename}.`date +%F-%R`"
|
|
|
|
sudo ln -sf "${raspap_dir}/backups/${filename}.`date +%F-%R`" "${raspap_dir}/backups/${filename}"
|
|
|
|
fi
|
2020-03-08 18:16:05 +01:00
|
|
|
done
|
2017-10-01 14:54:16 +02:00
|
|
|
}
|
|
|
|
|
2016-06-16 15:16:19 +02:00
|
|
|
# Move configuration file to the correct location
|
|
|
|
function move_config_file() {
|
|
|
|
if [ ! -d "$raspap_dir" ]; then
|
|
|
|
install_error "'$raspap_dir' directory doesn't exist"
|
|
|
|
fi
|
|
|
|
|
|
|
|
install_log "Moving configuration file to '$raspap_dir'"
|
2019-08-01 15:07:26 +02:00
|
|
|
sudo cp "$webroot_dir"/raspap.php "$raspap_dir" || install_error "Unable to move files to '$raspap_dir'"
|
2016-06-16 15:16:19 +02:00
|
|
|
sudo chown -R $raspap_user:$raspap_user "$raspap_dir" || install_error "Unable to change file ownership for '$raspap_dir'"
|
|
|
|
}
|
|
|
|
|
2016-10-23 17:39:33 +02:00
|
|
|
# Set up default configuration
|
|
|
|
function default_configuration() {
|
|
|
|
install_log "Setting up hostapd"
|
|
|
|
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"
|
|
|
|
fi
|
2019-08-01 15:07:26 +02:00
|
|
|
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 /etc/dnsmasq.conf || 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"
|
2017-11-16 02:24:02 +01:00
|
|
|
|
2020-02-26 02:48:29 +01:00
|
|
|
[ -d /etc/dnsmasq.d ] || sudo mkdir /etc/dnsmasq.d
|
|
|
|
|
2020-03-08 18:16:05 +01:00
|
|
|
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"
|
|
|
|
|
2019-11-05 15:30:08 +01:00
|
|
|
if [ ! -f "$webroot_dir/includes/config.php" ]; then
|
|
|
|
sudo cp "$webroot_dir/config/config.php" "$webroot_dir/includes/config.php"
|
|
|
|
fi
|
|
|
|
|
2017-10-21 16:39:29 +02:00
|
|
|
# Generate required lines for Rasp AP to place into rc.local file.
|
|
|
|
# #RASPAP is for removal script
|
|
|
|
lines=(
|
2018-03-19 12:43:24 +01:00
|
|
|
'echo 1 > \/proc\/sys\/net\/ipv4\/ip_forward #RASPAP'
|
2017-11-16 02:24:02 +01:00
|
|
|
'iptables -t nat -A POSTROUTING -j MASQUERADE #RASPAP'
|
2019-04-06 09:36:36 +02:00
|
|
|
'iptables -t nat -A POSTROUTING -s 192.168.50.0\/24 ! -d 192.168.50.0\/24 -j MASQUERADE #RASPAP'
|
2017-10-21 16:39:29 +02:00
|
|
|
)
|
2017-11-16 02:28:59 +01:00
|
|
|
|
2017-10-21 16:39:29 +02:00
|
|
|
for line in "${lines[@]}"; do
|
|
|
|
if grep "$line" /etc/rc.local > /dev/null; then
|
|
|
|
echo "$line: Line already added"
|
|
|
|
else
|
2018-03-19 12:43:24 +01:00
|
|
|
sudo sed -i "s/^exit 0$/$line\nexit 0/" /etc/rc.local
|
2017-10-21 16:39:29 +02:00
|
|
|
echo "Adding line $line"
|
|
|
|
fi
|
|
|
|
done
|
2019-04-06 09:52:36 +02:00
|
|
|
|
|
|
|
# Force a reload of new settings in /etc/rc.local
|
|
|
|
sudo systemctl restart rc-local.service
|
|
|
|
sudo systemctl daemon-reload
|
2019-04-19 13:36:09 +02:00
|
|
|
|
2019-09-30 19:42:04 +02:00
|
|
|
# Prompt to install RaspAP daemon
|
2019-04-21 12:59:36 +02:00
|
|
|
echo -n "Enable RaspAP control service (Recommended)? [Y/n]: "
|
2019-11-18 12:51:59 +01:00
|
|
|
if [ "$assume_yes" == 0 ]; then
|
2019-11-19 12:42:06 +01:00
|
|
|
read answer < /dev/tty
|
2019-11-18 12:51:59 +01:00
|
|
|
if [ "$answer" != "${answer#[Nn]}" ]; then
|
|
|
|
echo -e
|
|
|
|
else
|
2019-09-30 19:42:04 +02:00
|
|
|
enable_raspap_daemon
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo -e
|
|
|
|
enable_raspap_daemon
|
2019-04-21 12:59:36 +02:00
|
|
|
fi
|
2016-10-23 17:39:33 +02:00
|
|
|
}
|
|
|
|
|
2019-09-30 19:42:04 +02:00
|
|
|
# Install and enable RaspAP daemon
|
|
|
|
function enable_raspap_daemon() {
|
|
|
|
install_log "Enabling RaspAP daemon"
|
|
|
|
echo "Disable with: sudo systemctl disable raspap.service"
|
|
|
|
sudo cp $webroot_dir/installers/raspap.service /lib/systemd/system/ || install_error "Unable to move raspap.service file"
|
|
|
|
sudo systemctl enable raspap.service || install_error "Failed to enable raspap.service"
|
|
|
|
}
|
|
|
|
|
2016-09-18 18:00:27 +02:00
|
|
|
# Add a single entry to the sudoers file
|
|
|
|
function sudo_add() {
|
2019-10-10 09:34:40 +02:00
|
|
|
sudo bash -c "echo \"$raspap_user ALL=(ALL) NOPASSWD:$1\" | (EDITOR=\"tee -a\" visudo)" \
|
2016-09-18 18:00:27 +02:00
|
|
|
|| install_error "Unable to patch /etc/sudoers"
|
|
|
|
}
|
|
|
|
|
2016-06-16 15:16:19 +02:00
|
|
|
# Adds www-data user to the sudoers file with restrictions on what the user can execute
|
|
|
|
function patch_system_files() {
|
2019-11-18 12:51:59 +01:00
|
|
|
|
2017-10-01 21:34:14 +02:00
|
|
|
# Set commands array
|
|
|
|
cmds=(
|
2018-02-16 15:31:04 +01:00
|
|
|
"/sbin/ifdown"
|
|
|
|
"/sbin/ifup"
|
|
|
|
"/bin/cat /etc/wpa_supplicant/wpa_supplicant.conf"
|
2018-07-06 19:09:57 +02:00
|
|
|
"/bin/cat /etc/wpa_supplicant/wpa_supplicant-wlan[0-9].conf"
|
2018-02-16 15:31:04 +01:00
|
|
|
"/bin/cp /tmp/wifidata /etc/wpa_supplicant/wpa_supplicant.conf"
|
2018-07-06 19:09:57 +02:00
|
|
|
"/bin/cp /tmp/wifidata /etc/wpa_supplicant/wpa_supplicant-wlan[0-9].conf"
|
|
|
|
"/sbin/wpa_cli -i wlan[0-9] scan_results"
|
|
|
|
"/sbin/wpa_cli -i wlan[0-9] scan"
|
2018-11-13 23:21:02 +01:00
|
|
|
"/sbin/wpa_cli -i wlan[0-9] reconfigure"
|
2019-04-21 12:59:36 +02:00
|
|
|
"/sbin/wpa_cli -i wlan[0-9] select_network"
|
2018-02-16 15:31:04 +01:00
|
|
|
"/bin/cp /tmp/hostapddata /etc/hostapd/hostapd.conf"
|
2019-11-15 09:57:17 +01:00
|
|
|
"/bin/systemctl start hostapd.service"
|
|
|
|
"/bin/systemctl stop hostapd.service"
|
|
|
|
"/bin/systemctl start dnsmasq.service"
|
|
|
|
"/bin/systemctl stop dnsmasq.service"
|
2019-11-16 18:42:55 +01:00
|
|
|
"/bin/systemctl start openvpn-client@client"
|
2020-03-15 12:02:20 +01:00
|
|
|
"/bin/systemctl enable openvpn-client@client"
|
2019-11-16 18:42:55 +01:00
|
|
|
"/bin/systemctl stop openvpn-client@client"
|
2020-03-15 12:02:20 +01:00
|
|
|
"/bin/systemctl disable openvpn-client@client"
|
2019-11-17 19:17:46 +01:00
|
|
|
"/bin/cp /tmp/ovpnclient.ovpn /etc/openvpn/client/client.conf"
|
2019-11-17 19:46:39 +01:00
|
|
|
"/bin/cp /tmp/authdata /etc/openvpn/client/login.conf"
|
2019-08-13 01:11:10 +02:00
|
|
|
"/bin/cp /tmp/dnsmasqdata /etc/dnsmasq.conf"
|
2019-03-12 00:43:39 +01:00
|
|
|
"/bin/cp /tmp/dhcpddata /etc/dhcpcd.conf"
|
2018-02-16 15:31:04 +01:00
|
|
|
"/sbin/shutdown -h now"
|
|
|
|
"/sbin/reboot"
|
2018-07-06 19:09:57 +02:00
|
|
|
"/sbin/ip link set wlan[0-9] down"
|
|
|
|
"/sbin/ip link set wlan[0-9] up"
|
|
|
|
"/sbin/ip -s a f label wlan[0-9]"
|
2018-02-16 15:31:04 +01:00
|
|
|
"/bin/cp /etc/raspap/networking/dhcpcd.conf /etc/dhcpcd.conf"
|
|
|
|
"/etc/raspap/hostapd/enablelog.sh"
|
|
|
|
"/etc/raspap/hostapd/disablelog.sh"
|
2019-04-10 11:02:28 +02:00
|
|
|
"/etc/raspap/hostapd/servicestart.sh"
|
2019-11-10 23:21:55 +01:00
|
|
|
"/etc/raspap/lighttpd/configport.sh"
|
2019-11-15 09:57:17 +01:00
|
|
|
"/etc/raspap/openvpn/configauth.sh"
|
2020-03-13 07:08:11 +01:00
|
|
|
"/bin/chmod o+r /tmp/hostapd.log"
|
|
|
|
"/bin/chmod o+r /tmp/dnsmasq.log"
|
2017-10-01 21:34:14 +02:00
|
|
|
)
|
|
|
|
|
2018-02-16 15:31:04 +01:00
|
|
|
# Check if sudoers needs patching
|
2019-11-30 23:08:16 +01:00
|
|
|
if [ $(sudo grep -c $raspap_user /etc/sudoers) -ne ${#cmds[@]} ]
|
2018-02-16 15:31:04 +01:00
|
|
|
then
|
2017-10-01 21:34:14 +02:00
|
|
|
# Sudoers file has incorrect number of commands. Wiping them out.
|
2019-11-18 12:51:59 +01:00
|
|
|
install_log "Cleaning system sudoers file"
|
2019-10-10 09:34:40 +02:00
|
|
|
sudo sed -i "/$raspap_user/d" /etc/sudoers
|
2017-10-01 21:34:14 +02:00
|
|
|
install_log "Patching system sudoers file"
|
|
|
|
# patch /etc/sudoers file
|
2018-02-16 15:31:04 +01:00
|
|
|
for cmd in "${cmds[@]}"
|
|
|
|
do
|
2017-10-01 21:34:14 +02:00
|
|
|
sudo_add $cmd
|
2018-02-16 15:31:04 +01:00
|
|
|
IFS=$'\n'
|
2017-10-01 21:34:14 +02:00
|
|
|
done
|
|
|
|
else
|
|
|
|
install_log "Sudoers file already patched"
|
|
|
|
fi
|
2019-03-09 18:48:51 +01:00
|
|
|
|
2019-12-13 17:54:01 +01:00
|
|
|
# Add symlink to prevent wpa_cli cmds from breaking with multiple wlan interfaces
|
2019-11-18 12:51:59 +01:00
|
|
|
install_log "Symlinked wpa_supplicant hooks for multiple wlan interfaces"
|
2019-12-13 17:54:01 +01:00
|
|
|
if [ ! -f /usr/share/dhcpcd/hooks/10-wpa_supplicant ]; then
|
|
|
|
sudo ln -s /usr/share/dhcpcd/hooks/10-wpa_supplicant /etc/dhcp/dhclient-enter-hooks.d/
|
|
|
|
fi
|
|
|
|
|
2019-03-09 19:45:27 +01:00
|
|
|
# Unmask and enable hostapd.service
|
2019-11-18 12:51:59 +01:00
|
|
|
install_log "Unmasking and enabling hostapd service"
|
2019-03-09 18:48:51 +01:00
|
|
|
sudo systemctl unmask hostapd.service
|
2019-03-09 19:45:27 +01:00
|
|
|
sudo systemctl enable hostapd.service
|
2016-06-16 15:16:19 +02:00
|
|
|
}
|
|
|
|
|
2018-08-21 23:43:50 +02:00
|
|
|
|
2018-09-05 14:59:49 +02:00
|
|
|
# Optimize configuration of php-cgi.
|
|
|
|
function optimize_php() {
|
|
|
|
install_log "Optimize PHP configuration"
|
2018-08-31 23:38:30 +02:00
|
|
|
if [ ! -f "$phpcgiconf" ]; then
|
|
|
|
install_warning "PHP configuration could not be found."
|
|
|
|
return
|
2018-08-21 23:43:50 +02:00
|
|
|
fi
|
|
|
|
|
2018-08-31 23:38:30 +02:00
|
|
|
# Backup php.ini and create symlink for restoring.
|
|
|
|
datetimephpconf=$(date +%F-%R)
|
|
|
|
sudo cp "$phpcgiconf" "$raspap_dir/backups/php.ini.$datetimephpconf"
|
|
|
|
sudo ln -sf "$raspap_dir/backups/php.ini.$datetimephpconf" "$raspap_dir/backups/php.ini"
|
|
|
|
|
2018-09-05 14:59:49 +02:00
|
|
|
echo -n "Enable HttpOnly for session cookies (Recommended)? [Y/n]: "
|
2019-11-18 12:51:59 +01:00
|
|
|
if [ "$assume_yes" == 0 ]; then
|
2019-11-19 12:42:06 +01:00
|
|
|
read answer < /dev/tty
|
2019-11-18 12:51:59 +01:00
|
|
|
if [ "$answer" != "${answer#[Nn]}" ]; then
|
|
|
|
echo -e
|
|
|
|
else
|
|
|
|
php_session_cookie=1;
|
2019-09-30 19:42:04 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-11-05 08:25:48 +01:00
|
|
|
if [ "$assume_yes" == 1 ] || [ "$php_session_cookie" == 1 ]; then
|
2018-09-05 14:59:49 +02:00
|
|
|
echo "Php-cgi enabling session.cookie_httponly."
|
2018-08-23 00:44:12 +02:00
|
|
|
sudo sed -i -E 's/^session\.cookie_httponly\s*=\s*(0|([O|o]ff)|([F|f]alse)|([N|n]o))\s*$/session.cookie_httponly = 1/' "$phpcgiconf"
|
2018-08-31 23:38:30 +02:00
|
|
|
fi
|
|
|
|
|
2019-09-30 19:42:04 +02:00
|
|
|
if [ "$php_package" = "php7.1-cgi" ]; then
|
2019-04-21 12:59:36 +02:00
|
|
|
echo -n "Enable PHP OPCache (Recommended)? [Y/n]: "
|
2019-11-18 12:51:59 +01:00
|
|
|
if [ "$assume_yes" == 0 ]; then
|
2019-11-19 12:42:06 +01:00
|
|
|
read answer < /dev/tty
|
2019-11-18 12:51:59 +01:00
|
|
|
if [ "$answer" != "${answer#[Nn]}" ]; then
|
|
|
|
echo -e
|
|
|
|
else
|
2019-11-05 08:25:48 +01:00
|
|
|
php_opcache=1;
|
2019-09-30 19:42:04 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-11-05 08:25:48 +01:00
|
|
|
if [ "$assume_yes" == 1 ] || [ "$phpopcache" == 1 ]; then
|
2019-09-30 19:42:04 +02:00
|
|
|
echo -e "Php-cgi enabling opcache.enable."
|
2018-08-23 00:44:12 +02:00
|
|
|
sudo sed -i -E 's/^;?opcache\.enable\s*=\s*(0|([O|o]ff)|([F|f]alse)|([N|n]o))\s*$/opcache.enable = 1/' "$phpcgiconf"
|
|
|
|
# Make sure opcache extension is turned on.
|
|
|
|
if [ -f "/usr/sbin/phpenmod" ]; then
|
|
|
|
sudo phpenmod opcache
|
|
|
|
else
|
|
|
|
install_warning "phpenmod not found."
|
|
|
|
fi
|
|
|
|
fi
|
2018-08-21 23:43:50 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-06-16 15:16:19 +02:00
|
|
|
function install_complete() {
|
|
|
|
install_log "Installation completed!"
|
2017-10-01 21:34:14 +02:00
|
|
|
|
2019-11-18 12:51:59 +01:00
|
|
|
if [ "$assume_yes" == 0 ]; then
|
2019-09-30 19:42:04 +02:00
|
|
|
# Prompt to reboot if wired ethernet (eth0) is connected.
|
|
|
|
# With default_configuration this will create an active AP on restart.
|
|
|
|
if ip a | grep -q ': eth0:.*state UP'; then
|
|
|
|
echo -n "The system needs to be rebooted as a final step. Reboot now? [y/N]: "
|
2019-11-19 12:42:06 +01:00
|
|
|
read answer < /dev/tty
|
2019-11-18 12:51:59 +01:00
|
|
|
if [ "$answer" != "${answer#[Nn]}" ]; then
|
2019-09-30 19:42:04 +02:00
|
|
|
echo "Installation reboot aborted."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
sudo shutdown -r now || install_error "Unable to execute shutdown"
|
2019-04-08 00:13:05 +02:00
|
|
|
fi
|
2016-06-16 15:16:19 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function install_raspap() {
|
2017-05-19 18:33:01 +02:00
|
|
|
display_welcome
|
2016-06-16 15:16:19 +02:00
|
|
|
config_installation
|
|
|
|
update_system_packages
|
|
|
|
install_dependencies
|
|
|
|
enable_php_lighttpd
|
|
|
|
create_raspap_directories
|
2019-11-25 14:54:36 +01:00
|
|
|
optimize_php
|
2017-10-01 14:54:16 +02:00
|
|
|
check_for_old_configs
|
2016-06-16 15:16:19 +02:00
|
|
|
download_latest_files
|
|
|
|
change_file_ownership
|
2019-03-06 11:48:18 +01:00
|
|
|
create_hostapd_scripts
|
2019-11-10 23:21:55 +01:00
|
|
|
create_lighttpd_scripts
|
2016-06-16 15:16:19 +02:00
|
|
|
move_config_file
|
2016-10-23 17:39:33 +02:00
|
|
|
default_configuration
|
2019-11-18 12:51:59 +01:00
|
|
|
prompt_install_openvpn
|
2016-06-16 15:16:19 +02:00
|
|
|
patch_system_files
|
|
|
|
install_complete
|
2016-08-14 18:40:59 +02:00
|
|
|
}
|