diff --git a/.gitignore b/.gitignore index 783a4ae..8f144f3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *~ *.sw[op] +.DS_Store diff --git a/manifest.toml b/manifest.toml index c3386e9..6056b95 100644 --- a/manifest.toml +++ b/manifest.toml @@ -20,7 +20,8 @@ code = "https://github.com/canonical/lxd" cpe = "cpe:2.3:a:canonical:lxd" [integration] -yunohost = ">= 11.2" +yunohost = ">= 11.2.18" +helpers_version = "2.1" architectures = "all" multi_instance = false ldap = "not_relevant" diff --git a/scripts/_common.sh b/scripts/_common.sh index 7cee4c8..623f11d 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,17 +1,13 @@ #!/bin/bash #================================================= -# COMMON VARIABLES -#================================================= - -#================================================= -# PERSONAL HELPERS +# COMMON VARIABLES AND CUSTOM HELPERS #================================================= # Create a dedicated systemd socket config # -# usage: ynh_add_systemd_config [--socket=socket] [--template=template] -# usage: ynh_add_systemd_config [--socket=socket] [--template=template] [--others_var="list of others variables to replace"] +# usage: ynh_config_add_systemd [--socket=socket] [--template=template] +# usage: ynh_config_add_systemd [--socket=socket] [--template=template] [--others_var="list of others variables to replace"] # | arg: -s, --socket= - socket name (optionnal, $app by default) # | arg: -t, --template= - Name of template file (optionnal, this is 'systemd' by default, meaning ./conf/systemd.socket will be used as template) # | arg: -v, --others_var= - List of others variables to replace separated by a space. For example: 'var_1 var_2 ...' @@ -30,7 +26,7 @@ # ynh_add_systemd_socket_config () { # Declare an array to define the options of this helper. - local legacy_args=stv + #REMOVEME? local legacy_args=stv local -A args_array=( [s]=socket= [t]=template= [v]=others_var= ) local socket local template @@ -42,16 +38,16 @@ ynh_add_systemd_socket_config () { others_var="${others_var:-}" finalsystemdconf="/etc/systemd/system/$socket.socket" - ynh_backup_if_checksum_is_different --file="$finalsystemdconf" + ynh_backup_if_checksum_is_different "$finalsystemdconf" cp ../conf/$template "$finalsystemdconf" # To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable. # Substitute in a nginx config file only if the variable is not empty if [ -n "${final_path:-}" ]; then - ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$finalsystemdconf" + ynh_replace --match="__FINALPATH__" --replace="$final_path" --file="$finalsystemdconf" fi if [ -n "${app:-}" ]; then - ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$finalsystemdconf" + ynh_replace --match="__APP__" --replace="$app" --file="$finalsystemdconf" fi # Replace all other variables given as arguments @@ -59,10 +55,10 @@ ynh_add_systemd_socket_config () { do # ${var_to_replace^^} make the content of the variable on upper-cases # ${!var_to_replace} get the content of the variable named $var_to_replace - ynh_replace_string --match_string="__${var_to_replace^^}__" --replace_string="${!var_to_replace}" --target_file="$finalsystemdconf" + ynh_replace --match="__${var_to_replace^^}__" --replace="${!var_to_replace}" --file="$finalsystemdconf" done - ynh_store_file_checksum --file="$finalsystemdconf" + ynh_store_file_checksum "$finalsystemdconf" chown root: "$finalsystemdconf" systemctl enable "$socket.socket" --quiet @@ -71,12 +67,12 @@ ynh_add_systemd_socket_config () { # Remove the dedicated systemd socket config # -# usage: ynh_remove_systemd_config [--socket=socket] +# usage: ynh_config_remove_systemd [--socket=socket] # | arg: -s, --socket= - socket name (optionnal, $app by default) # ynh_remove_systemd_socket_config () { # Declare an array to define the options of this helper. - local legacy_args=s + #REMOVEME? local legacy_args=s local -A args_array=( [s]=socket= ) local socket # Manage arguments with getopts @@ -86,33 +82,33 @@ ynh_remove_systemd_socket_config () { local finalsystemdconf="/etc/systemd/system/$socket.socket" if [ -e "$finalsystemdconf" ] then - ynh_systemd_action --service_name="$socket.socket" --action=stop + ynh_systemctl --service="$socket.socket" --action=stop systemctl disable $socket.socket --quiet - ynh_secure_remove --file="$finalsystemdconf" + ynh_safe_rm "$finalsystemdconf" systemctl daemon-reload fi } _ynh_add_dnsmasq() { - ynh_add_config --template="dnsmasq.conf" --destination="/etc/dnsmasq.d/$app" + ynh_config_add --template="dnsmasq.conf" --destination="/etc/dnsmasq.d/$app" - ynh_systemd_action --service_name=dnsmasq --action=restart + ynh_systemctl --service=dnsmasq --action=restart } _ynh_remove_dnsmasq() { - ynh_secure_remove --file="/etc/dnsmasq.d/$app" + ynh_safe_rm "/etc/dnsmasq.d/$app" - ynh_systemd_action --service_name=dnsmasq --action=restart + ynh_systemctl --service=dnsmasq --action=restart } _ynh_add_ld_so() { - ynh_add_config --template="ld.so.conf" --destination="/etc/ld.so.conf.d/$app.conf" + ynh_config_add --template="ld.so.conf" --destination="/etc/ld.so.conf.d/$app.conf" ldconfig } _ynh_remove_ld_so() { - ynh_secure_remove --file="/etc/ld.so.conf.d/$app.conf" + ynh_safe_rm "/etc/ld.so.conf.d/$app.conf" ldconfig } @@ -124,11 +120,3 @@ _ynh_set_subuid_subgid() { _ynh_unset_subuid_subgid() { sed -i "/# Added by lxd$/{N;/root:100000:65536/d}" /etc/sub{u,g}id } - -#================================================= -# EXPERIMENTAL HELPERS -#================================================= - -#================================================= -# FUTURE OFFICIAL HELPERS -#================================================= diff --git a/scripts/backup b/scripts/backup index 70cf656..12e4179 100755 --- a/scripts/backup +++ b/scripts/backup @@ -1,19 +1,10 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# DECLARE DATA AND CONF FILES TO BACKUP -#================================================= -ynh_print_info --message="Declaring files to be backed up..." +ynh_print_info "Declaring files to be backed up..." #================================================= # SPECIFIC BACKUP @@ -21,33 +12,33 @@ ynh_print_info --message="Declaring files to be backed up..." # BACKUP SYSTEMD #================================================= -ynh_backup --src_path="/etc/systemd/system/$app.service" -ynh_backup --src_path="/etc/systemd/system/$app.socket" +ynh_backup "/etc/systemd/system/$app.service" +ynh_backup "/etc/systemd/system/$app.socket" #================================================= # BACKUP VARIOUS FILES #================================================= -ynh_backup --src_path="/var/log/$app/" +ynh_backup "/var/log/$app/" -ynh_backup --src_path="/usr/local/lib/$app/" +ynh_backup "/usr/local/lib/$app/" -ynh_backup --src_path="/usr/local/bin/fuidshift" -ynh_backup --src_path="/usr/local/bin/lxc" -ynh_backup --src_path="/usr/local/bin/lxc-to-lxd" -ynh_backup --src_path="/usr/local/bin/lxd" -ynh_backup --src_path="/usr/local/bin/lxd-agent" -ynh_backup --src_path="/usr/local/bin/lxd-benchmark" -ynh_backup --src_path="/usr/local/bin/lxd-migrate" -ynh_backup --src_path="/usr/local/bin/lxd-user" -ynh_backup --src_path="/etc/bash_completion.d/lxd-client" +ynh_backup "/usr/local/bin/fuidshift" +ynh_backup "/usr/local/bin/lxc" +ynh_backup "/usr/local/bin/lxc-to-lxd" +ynh_backup "/usr/local/bin/lxd" +ynh_backup "/usr/local/bin/lxd-agent" +ynh_backup "/usr/local/bin/lxd-benchmark" +ynh_backup "/usr/local/bin/lxd-migrate" +ynh_backup "/usr/local/bin/lxd-user" +ynh_backup "/etc/bash_completion.d/lxd-client" -ynh_backup --src_path="/etc/dnsmasq.d/lxd" +ynh_backup "/etc/dnsmasq.d/lxd" -ynh_backup --src_path="/etc/ld.so.conf.d/$app.conf" +ynh_backup "/etc/ld.so.conf.d/$app.conf" #================================================= # END OF SCRIPT #================================================= -ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." +ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/install b/scripts/install index d07fc41..86fa568 100755 --- a/scripts/install +++ b/scripts/install @@ -1,18 +1,12 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." --weight=5 +ynh_script_progression "Setting up source files..." # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --source_id="go" --dest_dir="$install_dir/go" @@ -23,7 +17,7 @@ ynh_setup_source --source_id="main" --dest_dir="$install_dir/lxd" #================================================= # BUILD FROM SOURCES #================================================= -ynh_script_progression --message="Building lxd from sources..." --weight=60 +ynh_script_progression "Building lxd from sources..." pushd "$install_dir/lxd" ( @@ -31,13 +25,13 @@ pushd "$install_dir/lxd" export GOPATH="$install_dir/lxd/vendor/" export HOME=${HOME:-"/root/"} - ynh_exec_warn_less make deps + ynh_hide_warnings make deps export CGO_CFLAGS="-I${GOPATH}dqlite/include/" export CGO_LDFLAGS="-L${GOPATH}dqlite/.libs/" export LD_LIBRARY_PATH="${GOPATH}dqlite/.libs/" export CGO_LDFLAGS_ALLOW="(-Wl,-wrap,pthread_create)|(-Wl,-z,now)" - ynh_exec_warn_less make + ynh_hide_warnings make mkdir -p /usr/local/lib/$app mkdir -p /var/log/$app @@ -47,18 +41,18 @@ pushd "$install_dir/lxd" ) popd -ynh_secure_remove --file="$install_dir/go" -ynh_secure_remove --file="$install_dir/lxd" +ynh_safe_rm "$install_dir/go" +ynh_safe_rm "$install_dir/lxd" #================================================= # SYSTEM CONFIGURATION #================================================= -ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 +ynh_script_progression "Adding system configurations related to $app..." # Create a dedicated systemd config ynh_add_systemd_socket_config -ynh_add_systemd_config +ynh_config_add_systemd yunohost service add "$app" --log="/var/log/$app/$app.log" _ynh_add_dnsmasq @@ -70,13 +64,13 @@ _ynh_set_subuid_subgid #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression "Starting $app's systemd service..." # Start a systemd service -ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemctl --service="$app" --action="start" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" --last +ynh_script_progression "Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index 93b7f3f..1661364 100755 --- a/scripts/remove +++ b/scripts/remove @@ -1,31 +1,25 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers #================================================= # REMOVE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 +ynh_script_progression "Removing system configurations related to $app..." # Remove the service from the list of services known by YunoHost (added from `yunohost service add`) -if ynh_exec_warn_less yunohost service status "$app" >/dev/null; then +if ynh_hide_warnings yunohost service status "$app" >/dev/null; then yunohost service remove "$app" fi # Remove the dedicated systemd config -ynh_exec_warn_less ynh_remove_systemd_socket_config -ynh_exec_warn_less ynh_remove_systemd_config +ynh_hide_warnings ynh_remove_systemd_socket_config +ynh_hide_warnings ynh_config_remove_systemd # Stop LXC systemd services for dnsmasq. -ynh_systemd_action --service_name="lxc-net" --action="stop" -ynh_systemd_action --service_name="lxc" --action="stop" +ynh_systemctl --service="lxc-net" --action="stop" +ynh_systemctl --service="lxc" --action="stop" _ynh_remove_ld_so @@ -38,16 +32,16 @@ _ynh_remove_dnsmasq #================================================= # Remove the data directory if --purge option is used if [ "${YNH_APP_PURGE:-0}" -eq 1 ]; then - ynh_script_progression --message="Removing containers..." - ynh_secure_remove --file="/var/lib/lxd" + ynh_script_progression "Removing containers..." + ynh_safe_rm "/var/lib/lxd" fi #================================================= # CLOSE A PORT #================================================= if yunohost firewall list | grep -q "\- 67$"; then - ynh_script_progression --message="Closing port 67..." - ynh_exec_warn_less yunohost firewall disallow Both 67 + ynh_script_progression "Closing port 67..." + ynh_hide_warnings yunohost firewall disallow Both 67 fi #================================================= @@ -55,24 +49,24 @@ fi #================================================= # REMOVE VARIOUS FILES #================================================= -ynh_script_progression --message="Removing various files..." +ynh_script_progression "Removing various files..." -ynh_secure_remove --file="/usr/local/lib/$app" +ynh_safe_rm "/usr/local/lib/$app" # Remove the log files -ynh_secure_remove --file="/usr/local/bin/fuidshift" -ynh_secure_remove --file="/usr/local/bin/lxc" -ynh_secure_remove --file="/usr/local/bin/lxc-to-lxd" -ynh_secure_remove --file="/usr/local/bin/lxd" -ynh_secure_remove --file="/usr/local/bin/lxd-agent" -ynh_secure_remove --file="/usr/local/bin/lxd-benchmark" -ynh_secure_remove --file="/usr/local/bin/lxd-migrate" -ynh_secure_remove --file="/usr/local/bin/lxd-user" -ynh_secure_remove --file="/etc/bash_completion.d/lxd-client" +ynh_safe_rm "/usr/local/bin/fuidshift" +ynh_safe_rm "/usr/local/bin/lxc" +ynh_safe_rm "/usr/local/bin/lxc-to-lxd" +ynh_safe_rm "/usr/local/bin/lxd" +ynh_safe_rm "/usr/local/bin/lxd-agent" +ynh_safe_rm "/usr/local/bin/lxd-benchmark" +ynh_safe_rm "/usr/local/bin/lxd-migrate" +ynh_safe_rm "/usr/local/bin/lxd-user" +ynh_safe_rm "/etc/bash_completion.d/lxd-client" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" --last +ynh_script_progression "Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index cb917d4..0136d2a 100755 --- a/scripts/restore +++ b/scripts/restore @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers @@ -13,37 +7,37 @@ source /usr/share/yunohost/helpers #================================================= # RESTORE VARIOUS FILES #================================================= -ynh_script_progression --message="Restoring various files..." +ynh_script_progression "Restoring various files..." -ynh_restore_file --origin_path="/var/log/$app/" +ynh_restore "/var/log/$app/" -ynh_restore_file --origin_path="/usr/local/lib/$app/" +ynh_restore "/usr/local/lib/$app/" -ynh_restore_file --origin_path="/usr/local/bin/fuidshift" -ynh_restore_file --origin_path="/usr/local/bin/lxc" -ynh_restore_file --origin_path="/usr/local/bin/lxc-to-lxd" -ynh_restore_file --origin_path="/usr/local/bin/lxd" -ynh_restore_file --origin_path="/usr/local/bin/lxd-agent" -ynh_restore_file --origin_path="/usr/local/bin/lxd-benchmark" -ynh_restore_file --origin_path="/usr/local/bin/lxd-migrate" -ynh_restore_file --origin_path="/usr/local/bin/lxd-user" -ynh_restore_file --origin_path="/etc/bash_completion.d/lxd-client" +ynh_restore "/usr/local/bin/fuidshift" +ynh_restore "/usr/local/bin/lxc" +ynh_restore "/usr/local/bin/lxc-to-lxd" +ynh_restore "/usr/local/bin/lxd" +ynh_restore "/usr/local/bin/lxd-agent" +ynh_restore "/usr/local/bin/lxd-benchmark" +ynh_restore "/usr/local/bin/lxd-migrate" +ynh_restore "/usr/local/bin/lxd-user" +ynh_restore "/etc/bash_completion.d/lxd-client" #================================================= # RESTORE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Restoring system configurations related to $app..." +ynh_script_progression "Restoring system configurations related to $app..." -ynh_restore_file --origin_path="/etc/systemd/system/$app.service" -ynh_restore_file --origin_path="/etc/systemd/system/$app.socket" +ynh_restore "/etc/systemd/system/$app.service" +ynh_restore "/etc/systemd/system/$app.socket" systemctl enable "$app.service" --quiet yunohost service add "$app" --log="/var/log/$app/$app.log" -ynh_restore_file --origin_path="/etc/dnsmasq.d/lxd" +ynh_restore "/etc/dnsmasq.d/lxd" systemctl restart dnsmasq -ynh_restore_file --origin_path="/etc/ld.so.conf.d/$app.conf" +ynh_restore "/etc/ld.so.conf.d/$app.conf" ldconfig _ynh_set_subuid_subgid @@ -51,12 +45,12 @@ _ynh_set_subuid_subgid #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression "Starting $app's systemd service..." -ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemctl --service="$app" --action="start" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" --last +ynh_script_progression "Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index b78fd6b..f839541 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,32 +1,24 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers -#================================================= -# STANDARD UPGRADE STEPS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." +ynh_script_progression "Stopping $app's systemd service..." -ynh_systemd_action --service_name="$app.socket" --action="stop" -ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log" +ynh_systemctl --service="$app.socket" --action="stop" +ynh_systemctl --service="$app" --action="stop" #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensuring downward compatibility..." +ynh_script_progression "Ensuring downward compatibility..." # Remove old file if [ -f "/usr/local/bin/lxd-p2c" ]; then - ynh_secure_remove --file="/usr/local/bin/lxd-p2c" + ynh_safe_rm "/usr/local/bin/lxd-p2c" fi sed -i "/root:1000000:65536 # Added by lxd#/d" /etc/sub{u,g}id @@ -34,34 +26,32 @@ sed -i "/root:1000000:65536 # Added by lxd#/d" /etc/sub{u,g}id #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." +ynh_script_progression "Setting up source files..." # Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source --source_id="go" --dest_dir="$install_dir/go" --full_replace=1 +ynh_setup_source --source_id="go" --dest_dir="$install_dir/go" --full_replace export PATH="$install_dir/go/bin:$PATH" -ynh_setup_source --source_id="main" --dest_dir="$install_dir/lxd" --full_replace=1 +ynh_setup_source --source_id="main" --dest_dir="$install_dir/lxd" --full_replace export GOPATH="$install_dir/lxd/vendor/" -#================================================= -# SPECIFIC UPGRADE #================================================= # BUILD FROM SOURCES #================================================= -ynh_script_progression --message="Building lxd from sources..." --weight=60 +ynh_script_progression "Building lxd from sources..." pushd "$install_dir/lxd" export HOME=${HOME:-"/root/"} - ynh_exec_warn_less make deps + ynh_hide_warnings make deps export CGO_CFLAGS="-I${GOPATH}dqlite/include/" export CGO_LDFLAGS="-L${GOPATH}dqlite/.libs/" export LD_LIBRARY_PATH="${GOPATH}dqlite/.libs/" export CGO_LDFLAGS_ALLOW="(-Wl,-wrap,pthread_create)|(-Wl,-z,now)" - ynh_exec_warn_less make + ynh_hide_warnings make mkdir -p /usr/local/lib/$app mkdir -p /var/log/$app @@ -70,18 +60,18 @@ pushd "$install_dir/lxd" cp $install_dir/lxd/scripts/bash/lxd-client /etc/bash_completion.d/ popd -ynh_secure_remove --file="$install_dir/go" -ynh_secure_remove --file="$install_dir/lxd" +ynh_safe_rm "$install_dir/go" +ynh_safe_rm "$install_dir/lxd" #================================================= # REAPPLY SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 +ynh_script_progression "Upgrading system configurations related to $app..." # Create a dedicated systemd config ynh_add_systemd_socket_config -ynh_add_systemd_config +ynh_config_add_systemd yunohost service add "$app" --log="/var/log/$app/$app.log" _ynh_add_dnsmasq @@ -93,12 +83,12 @@ _ynh_set_subuid_subgid #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression "Starting $app's systemd service..." -ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemctl --service="$app" --action="start" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --last +ynh_script_progression "Upgrade of $app completed"