diff --git a/conf/sudoers b/conf/sudoers index 4f92b76..6c98bb8 100644 --- a/conf/sudoers +++ b/conf/sudoers @@ -1,5 +1,5 @@ # Grant sudo permissions to the user to manage his own systemd service -__NAME__ ALL=(ALL) NOPASSWD: /bin/systemctl stop __NAME__@__NAME__.service -__NAME__ ALL=(ALL) NOPASSWD: /bin/systemctl start __NAME__@__NAME__.service -__NAME__ ALL=(ALL) NOPASSWD: /bin/systemctl restart __NAME__@__NAME__.service -__NAME__ ALL=(ALL) NOPASSWD: /bin/systemctl status __NAME__@__NAME__.service +__APP__ ALL=(ALL) NOPASSWD: /bin/systemctl stop __APP__.service +__APP__ ALL=(ALL) NOPASSWD: /bin/systemctl start __APP__.service +__APP__ ALL=(ALL) NOPASSWD: /bin/systemctl restart __APP__.service +__APP__ ALL=(ALL) NOPASSWD: /bin/systemctl status __APP__.service diff --git a/scripts/backup b/scripts/backup index c8e6a74..02d2ff8 100644 --- a/scripts/backup +++ b/scripts/backup @@ -11,12 +11,12 @@ ynh_abort_if_errors # retrieve arguments app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app="$app" --key=domain) - -# definie useful vars -final_path="/opt/yunohost/$app" -data_path="/home/yunohost.app/$app" -log_file="/var/log/$app/$app.log" -path_url="/" +port=$(ynh_app_setting_get --app="$app" --key=port) +final_path=$(ynh_app_setting_get --app="$app" --key=final_path) +data_path=$(ynh_app_setting_get --app="$app" --key=data_path) +log_file=$(ynh_app_setting_get --app="$app" --key=log_file) +path_url=$(ynh_app_setting_get --app="$app" --key=path_url) +python=$(ynh_app_setting_get --app="$app" --key=python) # backup source & conf files ynh_print_info --message="Declaring files to be backed up..." diff --git a/scripts/install b/scripts/install index 6b258b1..85253e9 100644 --- a/scripts/install +++ b/scripts/install @@ -25,24 +25,28 @@ ynh_script_progression --message="Validating installation parameters..." [ ! -d "$final_path" ] || ynh_die --message="This path already contains a folder" ynh_webpath_register --app="$app" --domain="$domain" --path_url="$path_url" -# save app settings -ynh_script_progression --message="Storing installation settings..." -ynh_app_setting_set --app="$app" --key=domain --value="$domain" - # find a free port & open it ynh_script_progression --message="Looking for a free port and opening it..." port=$(ynh_find_port 8123) -ynh_app_setting_set --app="$app" --key=port --value="$port" ynh_exec_fully_quiet yunohost firewall allow TCP "$port" -# create a dedicated system user -ynh_script_progression --message="Creating dedicated user, rights and folders..." -ynh_system_user_create --username="$app" +# save app settings +ynh_script_progression --message="Storing installation settings..." +ynh_app_setting_set --app="$app" --key=domain --value="$domain" +ynh_app_setting_set --app="$app" --key=port --value="$port" +ynh_app_setting_set --app="$app" --key=final_path --value="$final_path" +ynh_app_setting_set --app="$app" --key=data_path --value="$data_path" +ynh_app_setting_set --app="$app" --key=log_file --value="$log_file" +ynh_app_setting_set --app="$app" --key=path_url --value="$path_url" # grant sudo permissions to the user to manage his own systemd service myynh_create_dir "/etc/sudoers.d" ynh_add_config --template="../conf/sudoers" --destination="/etc/sudoers.d/$app" +# create a dedicated system user +ynh_script_progression --message="Creating dedicated user, rights and folders..." +ynh_system_user_create --username="$app" + # create a directory for the installation of Home Assistant myynh_create_dir "$final_path" chown $app: "$final_path" diff --git a/scripts/remove b/scripts/remove index ec11286..9fb0765 100644 --- a/scripts/remove +++ b/scripts/remove @@ -9,12 +9,11 @@ source /usr/share/yunohost/helpers app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) port=$(ynh_app_setting_get --app=$app --key=port) - -# definie useful vars -final_path="/opt/yunohost/$app" -data_path="/home/yunohost.app/$app" -log_file="/var/log/$app/$app.log" -path_url="/" +final_path=$(ynh_app_setting_get --app="$app" --key=final_path) +data_path=$(ynh_app_setting_get --app="$app" --key=data_path) +log_file=$(ynh_app_setting_get --app="$app" --key=log_file) +path_url=$(ynh_app_setting_get --app="$app" --key=path_url) +python=$(ynh_app_setting_get --app="$app" --key=python) # Remove a service from the admin panel, added by `yunohost service add` if ynh_exec_warn_less yunohost service status "$app" >/dev/null ; then diff --git a/scripts/restore b/scripts/restore index c8db173..864278e 100644 --- a/scripts/restore +++ b/scripts/restore @@ -18,14 +18,12 @@ ynh_abort_if_errors app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app="$app" --key=domain) port=$(ynh_app_setting_get --app="$app" --key=port) +final_path=$(ynh_app_setting_get --app="$app" --key=final_path) +data_path=$(ynh_app_setting_get --app="$app" --key=data_path) +log_file=$(ynh_app_setting_get --app="$app" --key=log_file) +path_url=$(ynh_app_setting_get --app="$app" --key=path_url) python=$(ynh_app_setting_get --app="$app" --key=python) -# definie useful vars -final_path="/opt/yunohost/$app" -data_path="/home/yunohost.app/$app" -log_file="/var/log/$app/$app.log" -path_url="/" - # check domain/path availability ynh_script_progression --message="Validating recovery parameters..." [ ! -d "$final_path" ] || ynh_die --message="This path already contains a folder" diff --git a/scripts/upgrade b/scripts/upgrade index 916c10d..d20a702 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -15,10 +15,22 @@ domain=$(ynh_app_setting_get --app="$app" --key=domain) port=$(ynh_app_setting_get --app="$app" --key=port) # definie useful vars -final_path="/opt/yunohost/$app" -data_path="/home/yunohost.app/$app" -log_file="/var/log/$app/$app.log" -path_url="/" +if [ -z $(ynh_app_setting_get --app="$app" --key=final_path) ]; then + final_path="/opt/yunohost/$app" + data_path="/home/yunohost.app/$app" + log_file="/var/log/$app/$app.log" + path_url="/" + ynh_app_setting_set --app="$app" --key=final_path --value="$final_path" + ynh_app_setting_set --app="$app" --key=data_path --value="$data_path" + ynh_app_setting_set --app="$app" --key=log_file --value="$log_file" + ynh_app_setting_set --app="$app" --key=path_url --value="$path_url" +else + final_path=$(ynh_app_setting_get --app="$app" --key=final_path) + data_path=$(ynh_app_setting_get --app="$app" --key=data_path) + log_file=$(ynh_app_setting_get --app="$app" --key=log_file) + path_url=$(ynh_app_setting_get --app="$app" --key=path_url) + python=$(ynh_app_setting_get --app="$app" --key=python) +fi # use prior backup and restore on error only if backup feature exists on installed instance ynh_script_progression --message="Creating backup in case of failure..."