mirror of
https://github.com/billz/raspap-webgui.git
synced 2023-10-10 13:37:24 +02:00
Replace err,warn,success functions w/ install_status
This commit is contained in:
parent
223ae3e11a
commit
512cde4fc3
@ -70,7 +70,7 @@ function _get_linux_distro() {
|
|||||||
CODENAME=$VERSION_CODENAME
|
CODENAME=$VERSION_CODENAME
|
||||||
DESC=$PRETTY_NAME
|
DESC=$PRETTY_NAME
|
||||||
else
|
else
|
||||||
_install_error "Unsupported Linux distribution"
|
_install_status 1 "Unsupported Linux distribution"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,9 +87,9 @@ function _set_php_package() {
|
|||||||
php_package="php7.0-cgi"
|
php_package="php7.0-cgi"
|
||||||
phpcgiconf="/etc/php/7.0/cgi/php.ini" ;;
|
phpcgiconf="/etc/php/7.0/cgi/php.ini" ;;
|
||||||
"8")
|
"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
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,8 +99,8 @@ function _install_dependencies() {
|
|||||||
_set_php_package
|
_set_php_package
|
||||||
if [ "$php_package" = "php7.4-cgi" ]; then
|
if [ "$php_package" = "php7.4-cgi" ]; then
|
||||||
echo "Adding apt-repository ppa:ondrej/php"
|
echo "Adding apt-repository ppa:ondrej/php"
|
||||||
sudo apt-get install software-properties-common || _install_error "Unable to install dependency"
|
sudo apt-get install software-properties-common || _install_status 1 "Unable to install dependency"
|
||||||
sudo add-apt-repository ppa:ondrej/php || _install_error "Unable to add-apt-repository ppa:ondrej/php"
|
sudo add-apt-repository ppa:ondrej/php || _install_status 1 "Unable to add-apt-repository ppa:ondrej/php"
|
||||||
fi
|
fi
|
||||||
if [ ${OS,,} = "debian" ] || [ ${OS,,} = "ubuntu" ]; then
|
if [ ${OS,,} = "debian" ] || [ ${OS,,} = "ubuntu" ]; then
|
||||||
dhcpcd_package="dhcpcd5"
|
dhcpcd_package="dhcpcd5"
|
||||||
@ -108,7 +108,8 @@ function _install_dependencies() {
|
|||||||
# Set dconf-set-selections
|
# Set dconf-set-selections
|
||||||
echo iptables-persistent iptables-persistent/autosave_v4 boolean true | sudo debconf-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
|
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
|
# Enables PHP for lighttpd and restarts service for settings to take effect
|
||||||
@ -116,16 +117,16 @@ function _enable_php_lighttpd() {
|
|||||||
_install_log "Enabling PHP for lighttpd"
|
_install_log "Enabling PHP for lighttpd"
|
||||||
sudo lighttpd-enable-mod fastcgi-php
|
sudo lighttpd-enable-mod fastcgi-php
|
||||||
sudo service lighttpd force-reload
|
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
|
# Verifies existence and permissions of RaspAP directory
|
||||||
function _create_raspap_directories() {
|
function _create_raspap_directories() {
|
||||||
_install_log "Creating RaspAP directories"
|
_install_log "Creating RaspAP directories"
|
||||||
if [ -d "$raspap_dir" ]; then
|
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
|
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.
|
# Create a directory for existing file backups.
|
||||||
sudo mkdir -p "$raspap_dir/backups"
|
sudo mkdir -p "$raspap_dir/backups"
|
||||||
@ -137,33 +138,37 @@ function _create_raspap_directories() {
|
|||||||
echo "Adding /etc/dhcpcd.conf as base configuration"
|
echo "Adding /etc/dhcpcd.conf as base configuration"
|
||||||
cat /etc/dhcpcd.conf | sudo tee -a /etc/raspap/networking/defaults > /dev/null
|
cat /etc/dhcpcd.conf | sudo tee -a /etc/raspap/networking/defaults > /dev/null
|
||||||
echo "Changing file ownership of $raspap_dir"
|
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
|
# Generate hostapd logging and service control scripts
|
||||||
function _create_hostapd_scripts() {
|
function _create_hostapd_scripts() {
|
||||||
_install_log "Creating hostapd logging & control 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
|
# 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
|
# 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.
|
# 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 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_error "Unable to change file permissions"
|
sudo chmod 750 "$raspap_dir/hostapd/"*.sh || _install_status 1 "Unable to change file permissions"
|
||||||
|
_install_status 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# Generate lighttpd service control scripts
|
# Generate lighttpd service control scripts
|
||||||
function _create_lighttpd_scripts() {
|
function _create_lighttpd_scripts() {
|
||||||
_install_log "Creating lighttpd control 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
|
# 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
|
# 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"
|
echo "Changing file ownership"
|
||||||
sudo chmod 750 "$raspap_dir/lighttpd/"*.sh || _install_error "Unable to change file permissions"
|
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 adblock
|
||||||
@ -193,39 +198,39 @@ function _install_adblock() {
|
|||||||
if [ ! -f /tmp/hostnames.txt ]; then
|
if [ ! -f /tmp/hostnames.txt ]; then
|
||||||
echo "Fetching latest hostnames list"
|
echo "Fetching latest hostnames list"
|
||||||
wget ${notracking_url}hostnames.txt -q --show-progress --progress=bar:force -O /tmp/hostnames.txt 2>&1 \
|
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
|
fi
|
||||||
if [ ! -f /tmp/domains.txt ]; then
|
if [ ! -f /tmp/domains.txt ]; then
|
||||||
echo "Fetching latest domains list"
|
echo "Fetching latest domains list"
|
||||||
wget ${notracking_url}domains.txt -q --show-progress --progress=bar:force -O /tmp/domains.txt 2>&1 \
|
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
|
fi
|
||||||
echo "Adding blocklists to $raspap_dir/adblock"
|
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/hostnames.txt $raspap_dir/adblock || _install_status 1 "Unable to move notracking hostnames"
|
||||||
sudo cp /tmp/domains.txt $raspap_dir/adblock || _install_error "Unable to move notracking domains"
|
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"
|
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
|
# 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"
|
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
|
# Create 090_adblock.conf and write values to /etc/dnsmasq.d
|
||||||
if [ ! -f "$raspap_adblock" ]; then
|
if [ ! -f "$raspap_adblock" ]; then
|
||||||
echo "Adding 090_addblock.conf to /etc/dnsmasq.d"
|
echo "Adding 090_addblock.conf to /etc/dnsmasq.d"
|
||||||
sudo touch "$raspap_adblock"
|
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 "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_error "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
|
fi
|
||||||
|
|
||||||
# Remove dhcp-option=6 in dnsmasq.d/090_raspap.conf to force local DNS resolution for DHCP clients
|
# 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"
|
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"
|
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"
|
sudo sed -i "s/\('RASPI_ADBLOCK_ENABLED', \)false/\1true/g" "$webroot_dir/includes/config.php" || _install_status 1 "Unable to modify config.php"
|
||||||
echo "Done."
|
_install_status 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# Prompt to install openvpn
|
# Prompt to install openvpn
|
||||||
@ -247,49 +252,51 @@ function _prompt_install_openvpn() {
|
|||||||
# Install openvpn and enable client configuration option
|
# Install openvpn and enable client configuration option
|
||||||
function _install_openvpn() {
|
function _install_openvpn() {
|
||||||
_install_log "Installing OpenVPN and enabling client configuration"
|
_install_log "Installing OpenVPN and enabling client configuration"
|
||||||
sudo apt-get install -y openvpn || _install_error "Unable to install openvpn"
|
sudo apt-get install -y openvpn || _install_status 1 "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 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"
|
echo "Enabling openvpn-client service on boot"
|
||||||
sudo systemctl enable openvpn-client@client || _install_error "Unable to enable openvpn-client daemon"
|
sudo systemctl enable openvpn-client@client || _install_status 1 "Unable to enable openvpn-client daemon"
|
||||||
_create_openvpn_scripts || _install_error "Unable to create openvpn control scripts"
|
_create_openvpn_scripts || _install_status 1 "Unable to create openvpn control scripts"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Generate openvpn logging and auth control scripts
|
# Generate openvpn logging and auth control scripts
|
||||||
function _create_openvpn_scripts() {
|
function _create_openvpn_scripts() {
|
||||||
_install_log "Creating OpenVPN control 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
|
# 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
|
# 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 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_error "Unable to change file permissions"
|
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
|
# Fetches latest files from github to webroot
|
||||||
function _download_latest_files() {
|
function _download_latest_files() {
|
||||||
if [ ! -d "$webroot_dir" ]; then
|
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
|
fi
|
||||||
|
|
||||||
if [ -d "$webroot_dir" ]; then
|
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
|
fi
|
||||||
|
|
||||||
_install_log "Cloning latest files from github"
|
_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
|
# Sets files ownership in web root directory
|
||||||
function _change_file_ownership() {
|
function _change_file_ownership() {
|
||||||
if [ ! -d "$webroot_dir" ]; then
|
if [ ! -d "$webroot_dir" ]; then
|
||||||
_install_error "Web root directory doesn't exist"
|
_install_status 1 "Web root directory doesn't exist"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_install_log "Changing file ownership in web root directory"
|
_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
|
# Check for existing configuration files
|
||||||
@ -321,58 +328,63 @@ function _check_for_old_configs() {
|
|||||||
sudo ln -sf "${raspap_dir}/backups/${filename}.`date +%F-%R`" "${raspap_dir}/backups/${filename}"
|
sudo ln -sf "${raspap_dir}/backups/${filename}.`date +%F-%R`" "${raspap_dir}/backups/${filename}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
_install_status 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# Move configuration file to the correct location
|
# Move configuration file to the correct location
|
||||||
function _move_config_file() {
|
function _move_config_file() {
|
||||||
if [ ! -d "$raspap_dir" ]; then
|
if [ ! -d "$raspap_dir" ]; then
|
||||||
_install_error "'$raspap_dir' directory doesn't exist"
|
_install_status 1 "'$raspap_dir' directory doesn't exist"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_install_log "Moving configuration file to '$raspap_dir'"
|
_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 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_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'"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Set up default configuration
|
# Set up default configuration
|
||||||
function _default_configuration() {
|
function _default_configuration() {
|
||||||
_install_log "Applying default configuration to installed services"
|
_install_log "Applying default configuration to installed services"
|
||||||
if [ -f /etc/default/hostapd ]; then
|
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
|
fi
|
||||||
sudo cp $webroot_dir/config/default_hostapd /etc/default/hostapd || _install_error "Unable to move hostapd defaults 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_error "Unable to move hostapd configuration 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_error "Unable to move dnsmasq 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_error "Unable to move dhcpcd 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
|
[ -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 stop systemd-networkd
|
||||||
sudo systemctl disable 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-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_error "Unable to move br0 member 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
|
if [ ! -f "$webroot_dir/includes/config.php" ]; then
|
||||||
sudo cp "$webroot_dir/config/config.php" "$webroot_dir/includes/config.php"
|
sudo cp "$webroot_dir/config/config.php" "$webroot_dir/includes/config.php"
|
||||||
fi
|
fi
|
||||||
|
_install_status 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# Install and enable RaspAP daemon
|
# Install and enable RaspAP daemon
|
||||||
function _enable_raspap_daemon() {
|
function _enable_raspap_daemon() {
|
||||||
_install_log "Enabling RaspAP daemon"
|
_install_log "Enabling RaspAP daemon"
|
||||||
echo "Disable with: sudo systemctl disable raspapd.service"
|
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 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
|
# Configure IP forwarding, set IP tables rules, prompt to install RaspAP daemon
|
||||||
function _configure_networking() {
|
function _configure_networking() {
|
||||||
_install_log "Configuring networking"
|
_install_log "Configuring networking"
|
||||||
echo "Enabling IP forwarding"
|
echo "Enabling IP forwarding"
|
||||||
echo "net.ipv4.ip_forward=1" | sudo tee $raspap_sysctl > /dev/null || _install_error "Unable to set IP forwarding"
|
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_error "Unable to execute sysctl"
|
sudo sysctl -p $raspap_sysctl || _install_status 1 "Unable to execute sysctl"
|
||||||
sudo /etc/init.d/procps restart || _install_error "Unable to execute procps"
|
sudo /etc/init.d/procps restart || _install_status 1 "Unable to execute procps"
|
||||||
|
|
||||||
echo "Checking iptables rules"
|
echo "Checking iptables rules"
|
||||||
rules=(
|
rules=(
|
||||||
@ -385,14 +397,14 @@ function _configure_networking() {
|
|||||||
else
|
else
|
||||||
rule=$(sed -e 's/^\(-A POSTROUTING\)/-t nat \1/' <<< $rule)
|
rule=$(sed -e 's/^\(-A POSTROUTING\)/-t nat \1/' <<< $rule)
|
||||||
echo "Adding rule: ${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
|
added=true
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
# Persist rules if added
|
# Persist rules if added
|
||||||
if [ "$added" = true ]; then
|
if [ "$added" = true ]; then
|
||||||
echo "Persisting IP tables rules"
|
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
|
fi
|
||||||
|
|
||||||
# Prompt to install RaspAP daemon
|
# Prompt to install RaspAP daemon
|
||||||
@ -408,6 +420,7 @@ function _configure_networking() {
|
|||||||
echo -e
|
echo -e
|
||||||
_enable_raspap_daemon
|
_enable_raspap_daemon
|
||||||
fi
|
fi
|
||||||
|
_install_status 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add sudoers file to /etc/sudoers.d/ and set file permissions
|
# Add sudoers file to /etc/sudoers.d/ and set file permissions
|
||||||
@ -416,8 +429,8 @@ function _patch_system_files() {
|
|||||||
# Create sudoers if not present
|
# Create sudoers if not present
|
||||||
if [ ! -f $raspap_sudoers ]; then
|
if [ ! -f $raspap_sudoers ]; then
|
||||||
_install_log "Adding raspap.sudoers to ${raspap_sudoers}"
|
_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 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_error "Unable to change file permissions for $raspap_sudoers"
|
sudo chmod 0440 $raspap_sudoers || _install_status 1 "Unable to change file permissions for $raspap_sudoers"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Add symlink to prevent wpa_cli cmds from breaking with multiple wlan interfaces
|
# Add symlink to prevent wpa_cli cmds from breaking with multiple wlan interfaces
|
||||||
@ -430,6 +443,7 @@ function _patch_system_files() {
|
|||||||
_install_log "Unmasking and enabling hostapd service"
|
_install_log "Unmasking and enabling hostapd service"
|
||||||
sudo systemctl unmask hostapd.service
|
sudo systemctl unmask hostapd.service
|
||||||
sudo systemctl enable hostapd.service
|
sudo systemctl enable hostapd.service
|
||||||
|
_install_status 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -479,7 +493,7 @@ function _optimize_php() {
|
|||||||
if [ -f "/usr/sbin/phpenmod" ]; then
|
if [ -f "/usr/sbin/phpenmod" ]; then
|
||||||
sudo phpenmod opcache
|
sudo phpenmod opcache
|
||||||
else
|
else
|
||||||
_install_warning "phpenmod not found."
|
_install_status 2 "phpenmod not found."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@ -497,7 +511,7 @@ function _install_complete() {
|
|||||||
echo "Installation reboot aborted."
|
echo "Installation reboot aborted."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
sudo shutdown -r now || _install_error "Unable to execute shutdown"
|
sudo shutdown -r now || _install_status 1 "Unable to execute shutdown"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,16 @@ repo="billz/raspap-webgui"
|
|||||||
branch="master"
|
branch="master"
|
||||||
assume_yes=0
|
assume_yes=0
|
||||||
ovpn_option=1
|
ovpn_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.*?(?=")' )
|
readonly RASPAP_LATEST=$(curl -s "https://api.github.com/repos/$repo/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")' )
|
||||||
|
|
||||||
# Define usage notes
|
# Define usage notes
|
||||||
@ -81,9 +91,9 @@ while :; do
|
|||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
-v|--version)
|
-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
|
exit 1
|
||||||
;;
|
;;
|
||||||
-*|--*)
|
-*|--*)
|
||||||
echo "Unknown option: $1"
|
echo "Unknown option: $1"
|
||||||
printf "$usage"
|
printf "$usage"
|
||||||
@ -100,10 +110,7 @@ UPDATE_URL="https://raw.githubusercontent.com/$repo/$branch/"
|
|||||||
|
|
||||||
# Outputs a welcome message
|
# Outputs a welcome message
|
||||||
function _display_welcome() {
|
function _display_welcome() {
|
||||||
raspberry='\033[0;35m'
|
echo -e "${ANSI_RASPBERRY}\n"
|
||||||
green='\033[1;32m'
|
|
||||||
|
|
||||||
echo -e "${raspberry}\n"
|
|
||||||
echo -e " 888888ba .d888888 888888ba"
|
echo -e " 888888ba .d888888 888888ba"
|
||||||
echo -e " 88 8b d8 88 88 8b"
|
echo -e " 88 8b d8 88 88 8b"
|
||||||
echo -e "a88aaaa8P' .d8888b. .d8888b. 88d888b. 88aaaaa88a a88aaaa8P"
|
echo -e "a88aaaa8P' .d8888b. .d8888b. 88d888b. 88aaaaa88a a88aaaa8P"
|
||||||
@ -112,29 +119,28 @@ function _display_welcome() {
|
|||||||
echo -e " dP dP 88888P8 88888P 88Y888P 88 88 dP"
|
echo -e " dP dP 88888P8 88888P 88Y888P 88 88 dP"
|
||||||
echo -e " 88"
|
echo -e " 88"
|
||||||
echo -e " dP version ${RASPAP_LATEST}"
|
echo -e " dP version ${RASPAP_LATEST}"
|
||||||
echo -e "${green}"
|
echo -e "${ANSI_GREEN}"
|
||||||
echo -e "The Quick Installer will guide you through a few easy steps\n\n"
|
echo -e "The Quick Installer will guide you through a few easy steps${ANSI_RESET}\n\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Outputs a RaspAP Install log line
|
# Outputs a RaspAP Install log line
|
||||||
function _install_log() {
|
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
|
# Outputs a RaspAP status indicator
|
||||||
function _install_error() {
|
function _install_status() {
|
||||||
echo -e "\033[1;37;41mRaspAP Install Error: $*\033[m"
|
case $1 in
|
||||||
exit 1
|
0)
|
||||||
}
|
echo -e "[$ANSI_GREEN \U2713 ok $ANSI_RESET] $2"
|
||||||
|
;;
|
||||||
# Outputs a RaspAP Warning line
|
1)
|
||||||
function _install_warning() {
|
echo -e "[$ANSI_RED \U2718 error $ANSI_RESET] $ANSI_ERROR $2 $ANSI_RESET"
|
||||||
echo -e "\033[1;33mWarning: $*\033[m"
|
;;
|
||||||
}
|
2)
|
||||||
|
echo -e "[$ANSI_YELLOW \U26A0 warning $ANSI_RESET] $2"
|
||||||
# Outputs a RaspAP divider
|
;;
|
||||||
function _install_divider() {
|
esac
|
||||||
echo -e "\033[1;32m***************************************************************$*\033[m"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _update_system_packages() {
|
function _update_system_packages() {
|
||||||
|
Loading…
Reference in New Issue
Block a user