mirror of
https://github.com/YunoHost-Apps/hotspot_ynh.git
synced 2024-09-03 19:25:53 +02:00
[fix] Adapt install/remove/backup/restore scripts
This commit is contained in:
parent
c696a4ffac
commit
e8370e5527
7 changed files with 33 additions and 216 deletions
|
@ -1,16 +1,14 @@
|
|||
;; Test complet
|
||||
; Manifest
|
||||
domain="domain.tld" (DOMAIN)
|
||||
path="/path" (PATH)
|
||||
wifi_ssid="myNeutralNetwork"
|
||||
wifi_passphrase="VhegT8oev0jZI" (PASSWORD)
|
||||
firmware_nonfree="no"
|
||||
; Checks
|
||||
pkg_linter=1
|
||||
setup_sub_dir=1
|
||||
setup_root=1
|
||||
setup_nourl=0
|
||||
setup_private=1
|
||||
setup_sub_dir=0
|
||||
setup_root=0
|
||||
setup_nourl=1
|
||||
setup_private=0
|
||||
setup_public=0
|
||||
upgrade=1
|
||||
upgrade=1 from_commit=546fd17712c7a9df428a4f26e7f8e4394884aaaf
|
||||
|
|
|
@ -18,22 +18,9 @@
|
|||
"yunohost": ">= 4.3.0"
|
||||
},
|
||||
"multi_instance": false,
|
||||
"services": [
|
||||
"nginx",
|
||||
"php7.0-fpm"
|
||||
],
|
||||
"services": [],
|
||||
"arguments": {
|
||||
"install" : [
|
||||
{
|
||||
"name": "domain",
|
||||
"type": "domain",
|
||||
"example": "domain.org"
|
||||
},
|
||||
{
|
||||
"name": "path",
|
||||
"type": "path",
|
||||
"default": "/wifiadmin"
|
||||
},
|
||||
{
|
||||
"name": "wifi_ssid",
|
||||
"type": "string",
|
||||
|
|
|
@ -28,10 +28,8 @@ ynh_print_info --message="Loading installation settings..."
|
|||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||
firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree)
|
||||
service_name=$(ynh_app_setting_get --app=$app --key=service_name)
|
||||
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
|
||||
|
||||
#=================================================
|
||||
# DECLARE DATA AND CONF FILES TO BACKUP
|
||||
|
@ -42,8 +40,6 @@ ynh_print_info --message="Declaring files to be backed up..."
|
|||
# BACKUP THE APP MAIN DIR
|
||||
#=================================================
|
||||
|
||||
ynh_backup --src_path="$final_path"
|
||||
|
||||
ynh_backup --src_path="/etc/sudoers.d/${app}_ynh"
|
||||
|
||||
ynh_backup --src_path="/usr/local/bin/iw_multissid"
|
||||
|
@ -63,18 +59,6 @@ ynh_backup --src_path="/usr/local/bin/$service_name"
|
|||
|
||||
ynh_backup --src_path="/etc/init.d/hostapd"
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE PHP-FPM CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC BACKUP
|
||||
#=================================================
|
||||
|
|
|
@ -40,8 +40,6 @@ ynh_abort_if_errors
|
|||
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
||||
#=================================================
|
||||
|
||||
domain=$YNH_APP_ARG_DOMAIN
|
||||
path_url=$YNH_APP_ARG_PATH
|
||||
wifi_ssid=$YNH_APP_ARG_WIFI_SSID
|
||||
wifi_passphrase=$YNH_APP_ARG_WIFI_PASSPHRASE
|
||||
firmware_nonfree=$YNH_APP_ARG_FIRMWARE_NONFREE
|
||||
|
@ -56,12 +54,6 @@ service_name='ynh-hotspot'
|
|||
#=================================================
|
||||
ynh_script_progression --message="Validating installation parameters..."
|
||||
|
||||
final_path=/var/www/$app
|
||||
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
||||
|
||||
# Register (book) web path
|
||||
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
||||
|
||||
if [ $firmware_nonfree = "no" ]; then
|
||||
firmware_nonfree=0
|
||||
elif [ $firmware_nonfree = "yes" ]; then
|
||||
|
@ -186,7 +178,6 @@ ynh_app_setting_set --app=$app --key=vpnclient --value=no
|
|||
|
||||
if [[ -z $wifi_device ]]; then
|
||||
ynh_app_setting_set --app=$app --key=service_enabled --value=0
|
||||
wifi_device=none
|
||||
else
|
||||
ynh_app_setting_set --app=$app --key=service_enabled --value=1
|
||||
fi
|
||||
|
@ -205,36 +196,6 @@ install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq
|
|||
|
||||
# Copy init script
|
||||
install -o root -g root -m 0755 ../conf/$service_name /usr/local/bin/
|
||||
ynh_replace_string --match_string="__PHPVERSION__" --replace_string="${YNH_PHP_VERSION}" --target_file="/usr/local/bin/$service_name"
|
||||
|
||||
#=================================================
|
||||
# COPY WEB SOURCES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Setting up source files..."
|
||||
|
||||
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
||||
mkdir -pm 0755 $final_path
|
||||
cp -a ../sources/* ${final_path}/
|
||||
|
||||
chmod 750 "$final_path"
|
||||
chmod o-rwx "$final_path"
|
||||
chown -R $app:www-data "$final_path"
|
||||
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring NGINX web server..."
|
||||
|
||||
# Create a dedicated NGINX config
|
||||
ynh_add_nginx_config
|
||||
|
||||
#=================================================
|
||||
# PHP-FPM CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring PHP-FPM..."
|
||||
|
||||
# Create a dedicated PHP-FPM config
|
||||
ynh_add_fpm_config
|
||||
|
||||
#=================================================
|
||||
# CONFIGURE HOSTAPD
|
||||
|
@ -248,10 +209,6 @@ ynh_replace_string --match_string="^DAEMON_CONF=$" --replace_string="&/etc/hosta
|
|||
# isnt used ... instead the service is "pure systemd" ...
|
||||
echo "DAEMON_CONF=/etc/hostapd/hostapd.conf" > /etc/default/hostapd
|
||||
|
||||
# Apply configuration
|
||||
ynh_add_config --template="config.php.tpl" --destination="$final_path/config.php"
|
||||
chown $app:$app "$final_path/config.php"
|
||||
|
||||
# Set default inits
|
||||
# The boot order of these services are important, so they are disabled by default
|
||||
# and the ynh-hotspot service handles them.
|
||||
|
@ -276,7 +233,7 @@ ynh_script_progression --message="Configuring a systemd service..."
|
|||
ynh_add_systemd_config --service=$service_name
|
||||
|
||||
# Remove IPv6 address set if there is a VPN installed
|
||||
if [[ $ip6_addr != none ]]; then
|
||||
if [[ $ip6_addr != "" ]]; then
|
||||
if ip -6 address show dev tun0 2> /dev/null | grep -q "${ip6_addr}/"; then
|
||||
ip address delete "${ip6_addr}/128" dev tun0 &> /dev/null
|
||||
fi
|
||||
|
@ -295,7 +252,7 @@ yunohost service add $service_name --description "Creates a Wi-Fi access point"
|
|||
ynh_script_progression --message="Starting a systemd service..."
|
||||
|
||||
# Start a systemd service if device is present
|
||||
if [[ $wifi_device == none ]]; then
|
||||
if [[ $wifi_device == "" ]]; then
|
||||
echo "WARNING: Wifi Hotspot is not started because no wifi device was found (please, check the web admin)" >&2
|
||||
else
|
||||
ynh_systemd_action --service_name=$service_name --action="start" --log_path=systemd #--line_match="Started YunoHost Wifi Hotspot"
|
||||
|
|
|
@ -33,10 +33,8 @@ ynh_script_progression --message="Loading installation settings..."
|
|||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||
firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree)
|
||||
service_name=$(ynh_app_setting_get --app=$app --key=service_name)
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
|
||||
#=================================================
|
||||
# STANDARD REMOVE
|
||||
|
@ -74,8 +72,6 @@ ynh_remove_app_dependencies
|
|||
ynh_script_progression --message="Removing app main directory..."
|
||||
|
||||
# Remove the app directory securely
|
||||
ynh_secure_remove --file="$final_path"
|
||||
|
||||
ynh_secure_remove --file="/usr/local/bin/$service_name"
|
||||
|
||||
ynh_secure_remove --file="/usr/local/bin/iw_multissid"
|
||||
|
@ -99,22 +95,6 @@ do
|
|||
ynh_secure_remove --file="$FILE"
|
||||
done
|
||||
|
||||
#=================================================
|
||||
# REMOVE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing NGINX web server configuration..."
|
||||
|
||||
# Remove the dedicated NGINX config
|
||||
ynh_remove_nginx_config
|
||||
|
||||
#=================================================
|
||||
# REMOVE PHP-FPM CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing PHP-FPM configuration..."
|
||||
|
||||
# Remove the dedicated PHP-FPM config
|
||||
ynh_remove_fpm_config
|
||||
|
||||
#=================================================
|
||||
# CLOSE A PORT
|
||||
#=================================================
|
||||
|
@ -132,6 +112,19 @@ then
|
|||
ynh_exec_warn_less yunohost firewall disallow TCP 67
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# REMOVE LEGACY INTERFACES
|
||||
#=================================================
|
||||
if [ -d /etc/nginx/conf.d/*.d/$app.conf ]; then
|
||||
ynh_secure_remove /etc/nginx/conf.d/*.d/$app.conf
|
||||
fi
|
||||
if [ -d /etc/php/*/fpm/pool.d/$app.conf ]; then
|
||||
ynh_secure_remove /etc/php/*/fpm/pool.d/$app.conf
|
||||
fi
|
||||
if [ -d /var/www/$app ]; then
|
||||
ynh_secure_remove /var/www/$app
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
|
|
|
@ -27,51 +27,25 @@ ynh_script_progression --message="Loading installation settings..."
|
|||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree)
|
||||
service_name=$(ynh_app_setting_get --app=$app --key=service_name)
|
||||
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
|
||||
|
||||
#=================================================
|
||||
# CHECK IF THE APP CAN BE RESTORED
|
||||
#=================================================
|
||||
ynh_script_progression --message="Validating restoration parameters..."
|
||||
|
||||
ynh_webpath_available --domain=$domain --path_url=$path_url \
|
||||
|| ynh_die --message="Path not available: ${domain}${path_url}"
|
||||
test ! -d $final_path \
|
||||
|| ynh_die --message="There is already a directory: $final_path "
|
||||
|
||||
#=================================================
|
||||
# STANDARD RESTORATION STEPS
|
||||
#=================================================
|
||||
# RESTORE THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restoring the NGINX configuration..."
|
||||
|
||||
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
#=================================================
|
||||
# RECREATE THE DEDICATED USER
|
||||
#=================================================
|
||||
ynh_script_progression --message="Recreating the dedicated system user..."
|
||||
|
||||
# Create the dedicated user (if not existing)
|
||||
ynh_system_user_create --username=$app --home_dir=$final_path
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE APP MAIN DIR
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restoring the app main directory..."
|
||||
|
||||
ynh_restore_file --origin_path="$final_path"
|
||||
|
||||
# Restore permissions on app files
|
||||
chmod 750 "$final_path"
|
||||
chmod o-rwx "$final_path"
|
||||
chown -R $app:www-data "$final_path"
|
||||
ynh_system_user_create --username=$app
|
||||
|
||||
|
||||
if [[ $firmware_nonfree -eq 1 ]]; then
|
||||
|
@ -100,13 +74,6 @@ ynh_restore_file --origin_path="/usr/local/bin/$service_name"
|
|||
|
||||
ynh_restore_file --origin_path="/etc/init.d/hostapd"
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE PHP-FPM CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restoring the PHP-FPM configuration..."
|
||||
|
||||
ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC RESTORATION
|
||||
#=================================================
|
||||
|
@ -142,28 +109,17 @@ wifi_device=$(bash ../settings/conf/iw_devices | awk -F\| '{ print $1 }')
|
|||
|
||||
if [[ -z $wifi_device ]]; then
|
||||
ynh_app_setting_set --app=$app --key=service_enabled --value=0
|
||||
wifi_device=none
|
||||
else
|
||||
ynh_app_setting_set --app=$app --key=service_enabled --value=1
|
||||
fi
|
||||
|
||||
# Start a systemd service if device is present
|
||||
if [[ $wifi_device == none ]]; then
|
||||
if [[ $wifi_device == "" ]]; then
|
||||
echo "WARNING: Wifi Hotspot is not started because no wifi device was found (please, check the web admin)" >&2
|
||||
else
|
||||
ynh_systemd_action --service_name=$service_name --action="start" --log_path=systemd #--line_match="Started YunoHost Wifi Hotspot"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# RELOAD NGINX AND PHP-FPM
|
||||
#=================================================
|
||||
ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..."
|
||||
|
||||
ynh_systemd_action --service_name=php$phpversion-fpm --action=reload
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
|
|
@ -16,12 +16,8 @@ ynh_script_progression --message="Loading installation settings..."
|
|||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree)
|
||||
service_name=$(ynh_app_setting_get --app=$app --key=service_name)
|
||||
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
|
||||
|
||||
#=================================================
|
||||
# CHECK VERSION
|
||||
|
@ -58,22 +54,18 @@ ynh_systemd_action --service_name=$service_name --action="stop" --log_path=syste
|
|||
#=================================================
|
||||
ynh_script_progression --message="Ensuring downward compatibility..."
|
||||
|
||||
if [ -z $phpversion ]; then
|
||||
phpversion=$YNH_PHP_VERSION
|
||||
ynh_app_setting_set --app=$app --key=phpversion --value=$phpversion
|
||||
if [ -d /etc/nginx/conf.d/*.d/$app.conf ]; then
|
||||
ynh_secure_remove /etc/nginx/conf.d/*.d/$app.conf
|
||||
fi
|
||||
|
||||
# If final_path doesn't exist, create it
|
||||
if [ -z "$final_path" ]; then
|
||||
final_path=/var/www/$app
|
||||
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
||||
if [ -d /etc/php/*/fpm/pool.d/$app.conf ]; then
|
||||
ynh_secure_remove /etc/php/*/fpm/pool.d/$app.conf
|
||||
fi
|
||||
if [ -d /var/www/$app ]; then
|
||||
ynh_secure_remove /var/www/$app
|
||||
fi
|
||||
|
||||
if [ -d /var/www/wifiadmin/ ]; then
|
||||
mv /var/www/wifiadmin $final_path
|
||||
mv /etc/php/7.0/fpm/pool.d/wifiadmin.conf /etc/php/$phpversion/fpm/pool.d/$app.conf
|
||||
ynh_replace_string --match_string="wifiadmin" --replace_string="$app" --target_file=/etc/php/$phpversion/fpm/pool.d/$app.conf
|
||||
ynh_systemd_action --service_name=php$phpversion-fpm --action=reload
|
||||
ynh_secure_remove /var/www/wifiadmin/
|
||||
fi
|
||||
|
||||
if [ $firmware_nonfree = "yes" ]; then
|
||||
|
@ -95,32 +87,7 @@ fi
|
|||
ynh_script_progression --message="Making sure dedicated system user exists..."
|
||||
|
||||
# Create a dedicated user (if not existing)
|
||||
ynh_system_user_create --username=$app --home_dir=$final_path
|
||||
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
#=================================================
|
||||
|
||||
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
||||
then
|
||||
ynh_script_progression --message="Upgrading source files..."
|
||||
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
cp -a ../sources/* ${final_path}/
|
||||
fi
|
||||
|
||||
# Restore permissions on app files
|
||||
chmod 750 "$final_path"
|
||||
chmod o-rwx "$final_path"
|
||||
chown -R $app:www-data "$final_path"
|
||||
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Upgrading NGINX web server configuration..."
|
||||
|
||||
# Create a dedicated NGINX config
|
||||
ynh_add_nginx_config
|
||||
ynh_system_user_create --username=$app
|
||||
|
||||
#=================================================
|
||||
# UPGRADE DEPENDENCIES
|
||||
|
@ -136,14 +103,6 @@ fi
|
|||
|
||||
ynh_install_app_dependencies $pkg_dependencies
|
||||
|
||||
#=================================================
|
||||
# PHP-FPM CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Upgrading PHP-FPM configuration..."
|
||||
|
||||
# Create a dedicated PHP-FPM config
|
||||
ynh_add_fpm_config
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC UPGRADE
|
||||
#=================================================
|
||||
|
@ -162,16 +121,6 @@ install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq
|
|||
install -o root -g root -m 0755 ../conf/$service_name /usr/local/bin/
|
||||
ynh_replace_string --match_string="__PHPVERSION__" --replace_string="${phpversion}" --target_file="/usr/local/bin/$service_name"
|
||||
|
||||
#=================================================
|
||||
# UPDATE A CONFIG FILE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Updating a configuration file..."
|
||||
|
||||
ynh_add_config --template="config.php.tpl" --destination="$final_path/config.php"
|
||||
|
||||
chmod 400 "$final_path/config.php"
|
||||
chown $app:$app "$final_path/config.php"
|
||||
|
||||
#=================================================
|
||||
# SETUP SYSTEMD
|
||||
#=================================================
|
||||
|
@ -199,25 +148,18 @@ wifi_device=$(bash ../conf/iw_devices | awk -F\| '{ print $1 }')
|
|||
|
||||
if [[ -z $wifi_device ]]; then
|
||||
ynh_app_setting_set --app=$app --key=service_enabled --value=0
|
||||
wifi_device=none
|
||||
wifi_device=""
|
||||
else
|
||||
ynh_app_setting_set --app=$app --key=service_enabled --value=1
|
||||
fi
|
||||
|
||||
# Start a systemd service if device is present
|
||||
if [[ $wifi_device == none ]]; then
|
||||
if [[ $wifi_device == "" ]]; then
|
||||
echo "WARNING: Wifi Hotspot is not started because no wifi device was found (please, check the web admin)" >&2
|
||||
else
|
||||
ynh_systemd_action --service_name=$service_name --action="start" --log_path=systemd #--line_match="Started YunoHost Wifi Hotspot"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
ynh_script_progression --message="Reloading NGINX web server..."
|
||||
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
#=================================================
|
||||
|
|
Loading…
Reference in a new issue