Merge pull request #1 from kay0u/new-standard

New standard
This commit is contained in:
Keoma Brun 2019-02-28 21:34:53 +01:00 committed by GitHub
commit 96d14e76e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 190 additions and 79 deletions

View File

@ -121,7 +121,9 @@ function vpnclient_deploy_files_and_services()
{
local domain=$1
local app=$2
local service_name=$3
local sysuser="${app}"
local service_checker_name="$service_name-checker"
# Ensure vpnclient_ynh has its own system user
if ! ynh_system_user_exists ${sysuser}
@ -138,7 +140,7 @@ function vpnclient_deploy_files_and_services()
install -o root -g root -m 0755 ../conf/ipv6_compressed /usr/local/bin/
# Install command-line cube file loader
install -o root -g root -m 0755 ../conf/ynh-vpnclient-loadcubefile.sh /usr/local/bin/
install -o root -g root -m 0755 ../conf/$service_name-loadcubefile.sh /usr/local/bin/
# Copy confs
mkdir -pm 0755 /var/log/nginx/
@ -183,16 +185,20 @@ function vpnclient_deploy_files_and_services()
ynh_replace_string "__PATH__" "${path_url}" "/var/www/${app}/config.php"
# Copy init script
install -o root -g root -m 0755 ../conf/ynh-vpnclient /usr/local/bin/
install -o root -g root -m 0644 ../conf/ynh-vpnclient.service /etc/systemd/system/
install -o root -g root -m 0755 ../conf/$service_name /usr/local/bin/
# Copy checker timer
install -o root -g root -m 0755 ../conf/ynh-vpnclient-checker.sh /usr/local/bin/
install -o root -g root -m 0644 ../conf/ynh-vpnclient-checker.service /etc/systemd/system/
install -o root -g root -m 0644 ../conf/ynh-vpnclient-checker.timer /etc/systemd/system/
install -o root -g root -m 0755 ../conf/$service_checker_name.sh /usr/local/bin/
install -o root -g root -m 0644 ../conf/$service_checker_name.timer /etc/systemd/system/
# Reload systemd configuration
systemctl daemon-reload
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_print_info "Configuring a systemd service..."
ynh_add_systemd_config $service_name "$service_name.service"
ynh_add_systemd_config $service_checker_name "$service_checker_name.service"
}
function service_is_managed_by_yunohost() {

View File

@ -1,3 +1,4 @@
#!/bin/bash
#=================================================
# GENERIC START
@ -5,16 +6,9 @@
# IMPORT GENERIC HELPERS
#=================================================
if [ ! -e _common.sh ]; then
# Get the _common.sh file if it's not in the current directory
cp ../settings/scripts/_common.sh ./_common.sh
chmod a+rx _common.sh
fi
source _common.sh
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
ynh_die "backup script is not implemented yet"
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
@ -25,54 +19,67 @@ ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info "Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path)
domain=$(ynh_app_setting_get $app domain)
db_name=$(ynh_app_setting_get $app db_name)
#=================================================
# STANDARD BACKUP STEPS
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path)
domain=$(ynh_app_setting_get $app domain)
service_name=$(ynh_app_setting_get $app service_name)
service_checker_name=$service_name"-checker"
#=================================================
# STANDARD BACKUP STEPS
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_print_info "Backing up the main app directory..."
ynh_backup "$final_path"
ynh_backup "/etc/sudoers.d/${app}_ynh"
ynh_backup "/usr/local/bin/ipv6_expanded"
ynh_backup "/usr/local/bin/ipv6_compressed"
ynh_backup "/usr/local/bin/$service_name-loadcubefile.sh"
ynh_backup "/etc/yunohost/hooks.d/90-vpnclient.tpl"
ynh_backup "/etc/openvpn/client.conf.tpl"
ynh_backup "/etc/openvpn/client.conf.tpl.restore"
ynh_backup "/etc/openvpn/keys/"
ynh_backup "/usr/local/bin/$service_name"
ynh_backup "/usr/local/bin/$service_checker_name.sh"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_print_info "Backing up nginx web server configuration..."
ynh_backup "/etc/nginx/conf.d/$domain.d/${app}.conf"
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP THE PHP-FPM CONFIGURATION
#=================================================
ynh_print_info "Backing up php-fpm configuration..."
ynh_backup "/etc/php5/fpm/pool.d/$app.conf"
ynh_backup "/etc/php/7.0/fpm/pool.d/$app.conf"
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP SYSTEMD
#=================================================
ynh_print_info "Backing up systemd configuration..."
ynh_backup "/etc/systemd/system/ynh-vpnclient.service"
ynh_backup "/etc/systemd/system/ynh-vpnclient-checker.service"
ynh_backup "/etc/systemd/system/ynh-vpnclient-checker.timer"
ynh_backup "/etc/systemd/system/$service_name.service"
ynh_backup "/etc/systemd/system/$service_checker_name.service"
ynh_backup "/etc/systemd/system/$service_checker_name.timer"
ynh_backup "/etc/systemd/system/openvpn@.service"
ynh_backup "/etc/cron.d/$app"
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View File

@ -38,8 +38,8 @@ ynh_abort_if_errors
#=================================================
# Retrieve arguments
domain=$1
path_url=$(ynh_normalize_url_path "$2")
domain=$YNH_APP_ARG_DOMAIN
path_url=$(ynh_normalize_url_path "$YNH_APP_ARG_PATH")
app=$YNH_APP_INSTANCE_NAME
final_path="/var/www/$app"
@ -64,6 +64,7 @@ ynh_print_info "Storing installation settings..."
ynh_app_setting_set "$app" domain "$domain"
ynh_app_setting_set "$app" final_path "$final_path"
ynh_app_setting_set "$app" service_name "$service_name"
#=================================================
# STANDARD MODIFICATIONS
@ -79,7 +80,7 @@ ynh_install_app_dependencies "$pkg_dependencies"
#=================================================
ynh_print_info "Deploy files from package..."
vpnclient_deploy_files_and_services "${domain}" "${app}"
vpnclient_deploy_files_and_services "${domain}" "${app}" "${service_name}"
#=================================================
# RELOAD SERVICES
@ -92,19 +93,17 @@ ynh_print_info "Reloading services..."
systemctl disable openvpn
systemctl stop openvpn
systemctl enable php5-fpm
systemctl restart php5-fpm
systemctl restart php7.0-fpm
systemctl reload nginx
# main service
yunohost service add $service_name --description "tunnels the internet traffic through a VPN" --need_lock
yunohost service add $service_name --description "Tunnels the internet traffic through a VPN" --need_lock
yunohost service enable $service_name
# checker service
yunohost service add $service_checker_name --description "makes sure that the VPN service is running" --need_lock
yunohost service add $service_checker_name --description "Makes sure that the VPN service is running" --need_lock
yunohost service start $service_checker_name
yunohost service enable $service_checker_name
systemctl start $service_checker_name.timer

View File

@ -33,8 +33,7 @@ ynh_print_info "Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
service_name="ynh-vpnclient"
service_name=$(ynh_app_setting_get $app service_name)
service_checker_name=$service_name"-checker"
#=================================================
@ -107,7 +106,7 @@ systemctl daemon-reload
# Restart services
# (this must happen before deleting the user, otherwise the user is
# being used by one of the php pool process)
systemctl restart php5-fpm
systemctl restart php7.0-fpm
systemctl reload nginx
#=================================================

View File

@ -1,19 +1,14 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
if [ ! -e _common.sh ]; then
# Fetch helpers file if not in current directory
cp ../settings/scripts/_common.sh ./_common.sh
chmod a+rx _common.sh
fi
source _common.sh
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
ynh_die "restore script is not implemented yet"
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
@ -21,23 +16,122 @@ ynh_die "restore script is not implemented yet"
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#sysuser="${app}"
sysuser="vpnclient" # XXX hard-coded variable
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info "Loading settings..."
backup_dir="${1}/apps/vpnclient"
app=$YNH_APP_INSTANCE_NAME
mkdir -p /etc/openvpn/
cp -a "${backup_dir}/keys/" /etc/openvpn/
cp -a "${backup_dir}/client.conf.tpl" /etc/openvpn/
chown -R root:${sysuser} /etc/openvpn/keys/
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
final_path=$(ynh_app_setting_get $app final_path)
service_name=$(ynh_app_setting_get $app service_name)
service_checker_name=$service_name"-checker"
gitcommit=$(grep revision /etc/yunohost/apps/vpnclient/status.json | sed 's/.*"revision": "\([^"]\+\)".*/\1/')
tmpdir=$(mktemp -dp /tmp/ vpnclient-restore-XXXXX)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_print_info "Validating restoration parameters..."
git clone https://github.com/labriqueinternet/vpnclient_ynh.git "${tmpdir}/"
git --work-tree "${tmpdir}/" --git-dir "${tmpdir}/.git/" reset --hard "${gitcommit}"
ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "
cd "${tmpdir}/scripts/"
bash ./upgrade
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
rm -r "${tmpdir}/"
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_print_info "Restoring the app main directory..."
ynh_restore_file "$final_path"
ynh_restore_file "/etc/sudoers.d/${app}_ynh"
ynh_restore_file "/usr/local/bin/ipv6_expanded"
ynh_restore_file "/usr/local/bin/ipv6_compressed"
ynh_restore_file "/usr/local/bin/$service_name-loadcubefile.sh"
ynh_restore_file "/etc/yunohost/hooks.d/90-vpnclient.tpl"
ynh_restore_file "/etc/openvpn/client.conf.tpl"
ynh_restore_file "/etc/openvpn/client.conf.tpl.restore"
ynh_restore_file "/etc/openvpn/keys/"
ynh_restore_file "/usr/local/bin/$service_name"
ynh_restore_file "/usr/local/bin/$service_checker_name.sh"
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_print_info "Recreating the dedicated system user..."
# Create the dedicated user (if not existing)
ynh_system_user_create $app
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Restore permissions on app files
chown -R $app: $final_path
#=================================================
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf"
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_print_info "Reinstalling dependencies..."
# Define and install dependencies
ynh_install_app_dependencies "$pkg_dependencies"
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_print_info "Restoring the systemd configuration..."
ynh_restore_file "/etc/systemd/system/$service_name.service"
ynh_restore_file "/etc/systemd/system/$service_checker_name.service"
ynh_restore_file "/etc/systemd/system/$service_checker_name.timer"
ynh_restore_file "/etc/systemd/system/openvpn@.service"
systemctl enable "$service_name.service"
systemctl enable "$service_checker_name.service"
systemctl enable "openvpn@.service"
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
yunohost service add $service_name --description "Tunnels the internet traffic through a VPN" --need_lock
yunohost service add $service_checker_name --description "Makes sure that the VPN service is running" --need_lock
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
ynh_print_info "Reloading nginx web server and php-fpm..."
systemctl restart php7.0-fpm
systemctl reload nginx
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info "Restoration completed for $app"

View File

@ -21,27 +21,33 @@ path_url=$(ynh_app_setting_get $app path)
is_public=$(ynh_app_setting_get $app is_public)
final_path=$(ynh_app_setting_get $app final_path)
server_name=$(ynh_app_setting_get $app server_name)
service_name="ynh-vpnclient"
service_name=$(ynh_app_setting_get $app service_name)
service_checker_name=$service_name"-checker"
#=================================================
# SPECIAL UPGRADE FOR VERSIONS < 1.2.0
#=================================================
# Apply renaming that occured in v1.2.0 ("vpnadmin" -> "${app}")
if [ -f /etc/nginx/conf.d/${domain}.d/vpnadmin.conf ]; then
sed "s|/var/www/vpnadmin/|/var/www/${app}/|g" -i "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
sed "s|vpnadmin.sock|${app}.sock|g" -i "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
ynh_replace_string "/var/www/vpnadmin/" "/var/www/${app}/" "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
ynh_replace_string "vpnadmin.sock" "${app}.sock" "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
mv /etc/nginx/conf.d/${domain}.d/vpnadmin.conf /etc/nginx/conf.d/${domain}.d/${app}.conf
fi
if [ -f /etc/php5/fpm/pool.d/vpnadmin.conf ]; then
sed "s|/var/www/vpnadmin/|/var/www/${app}/|g" -i /etc/php5/fpm/pool.d/vpnadmin.conf
sed "s|vpnadmin.sock|${app}.sock|g" -i /etc/php5/fpm/pool.d/vpnadmin.conf
mv /etc/php5/fpm/pool.d/vpnadmin.conf /etc/php5/fpm/pool.d/${app}.conf
ynh_replace_string "/var/www/vpnadmin/" "/var/www/${app}/" /etc/php/7.0/fpm/pool.d/vpnadmin.conf
ynh_replace_string "vpnadmin.sock" "${app}.sock" /etc/php/7.0/fpm/pool.d/vpnadmin.conf
mv /etc/php5/fpm/pool.d/vpnadmin.conf /etc/php/7.0/fpm/pool.d/${app}.conf
fi
test -d /var/www/vpnadmin && mv /var/www/vpnadmin /var/www/${app}
if [ -z $service_name ]; then
service_name="ynh-vpnclient"
service_checker_name=$service_name"-checker"
ynh_app_setting_set "$app" service_name "$service_name"
fi
## Versions known to have a buggy backup script
#buggy_versions="1.0.0 1.0.1 1.1.0"
#curr_version=$(read_manifest version)
@ -78,7 +84,7 @@ tmpdir=$(mktemp -d /tmp/vpnclient-upgrade-XXX)
cp -r /etc/openvpn/client* ${tmpdir}
# Deploy files from package
vpnclient_deploy_files_and_services "${domain}" "${app}"
vpnclient_deploy_files_and_services "${domain}" "${app}" "${service_name}"
# Restore previously existing config files
cp -r ${tmpdir}/client* /etc/openvpn/
@ -100,7 +106,7 @@ if service_is_managed_by_yunohost $service_name
then
yunohost service remove $service_name
fi
yunohost service add $service_name --description "tunnels the internet traffic through a VPN" --need_lock
yunohost service add $service_name --description "Tunnels the internet traffic through a VPN" --need_lock
# checker service
@ -108,7 +114,7 @@ if service_is_managed_by_yunohost $service_checker_name
then
yunohost service remove $service_checker_name
fi
yunohost service add $service_checker_name --description "makes sure that the VPN service is running" --need_lock
yunohost service add $service_checker_name --description "Makes sure that the VPN service is running" --need_lock
# Reload systemd configuration