Skip to content

Commit

Permalink
Move to helpers 2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Sylvain committed Sep 14, 2024
1 parent 02a496b commit f4e912d
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 173 deletions.
11 changes: 5 additions & 6 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ id = "scrutiny"
name = "Scrutiny"
description.en = "WebUI for smartd S.M.A.R.T monitoring"

version = "0.8.1~ynh1"
version = "0.8.1~ynh2"

maintainers = ["ewilly"]

Expand All @@ -15,7 +15,8 @@ code = "https://github.com/AnalogJ/scrutiny"
fund = "https://paypal.me/analogj/usd10"

[integration]
yunohost = ">= 11.2"
yunohost = ">= 11.2.18"
helpers_version = "2.1"
architectures = ["amd64", "arm64"]
multi_instance = false
ldap = "not_relevant"
Expand All @@ -41,7 +42,7 @@ ram.runtime = "50M"
[resources]
[resources.sources]

[resources.sources.main]
[resources.sources.scrutiny-web-linux]
in_subdir = false
rename = "scrutiny-web-linux"
amd64.url = "https://github.com/AnalogJ/scrutiny/releases/download/v0.8.1/scrutiny-web-linux-amd64"
Expand All @@ -55,6 +56,7 @@ ram.runtime = "50M"

[resources.sources.scrutiny-collector-metrics-linux]
in_subdir = false
rename = "scrutiny-collector-metrics-linux"
amd64.url = "https://github.com/AnalogJ/scrutiny/releases/download/v0.8.1/scrutiny-collector-metrics-linux-amd64"
amd64.sha256 = "904056ddc4e0bd3455a0db45d56f98084135a967eef018d18bfc8e4c0ef6887e"
arm64.url = "https://github.com/AnalogJ/scrutiny/releases/download/v0.8.1/scrutiny-collector-metrics-linux-arm64"
Expand All @@ -75,9 +77,6 @@ ram.runtime = "50M"
[resources.system_user]

[resources.install_dir]
dir = "/var/www/__APP__"
owner = "__APP__:rwx"
group = "__APP__:rx"

[resources.permissions]
main.url = "/"
Expand Down
26 changes: 8 additions & 18 deletions scripts/_common.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
#!/bin/bash

#=================================================
# COMMON VARIABLES
#=================================================
ynh_arch="$YNH_ARCH"

#=================================================
# PERSONAL HELPERS
# COMMON VARIABLES AND CUSTOM HELPERS
#=================================================

myynh_set_permissions () {
chown -R $app: "$install_dir"
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chmod -R +x "$install_dir/bin/"
}

#=================================================
# EXPERIMENTAL HELPERS
#=================================================
chown -R $app: "$install_dir"
chmod u=rwX,g=rX,o= "$install_dir"
chmod -R o-rwx "$install_dir"
chmod -R +x "$install_dir/bin/"

#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================
chown $app:root "/var/log/$app"
chmod -R u=rwX,g=rX,o= "/var/log/$app"
}
27 changes: 9 additions & 18 deletions scripts/backup
Original file line number Diff line number Diff line change
@@ -1,50 +1,41 @@
#!/bin/bash

#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================

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..."

#=================================================
# BACKUP THE APP MAIN DIR
#=================================================

ynh_backup --src_path="$install_dir"
ynh_backup "$install_dir"

#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================

ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"

#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP LOGROTATE
#=================================================

ynh_backup --src_path="/etc/logrotate.d/$app"
ynh_backup --src_path="/var/log/$app"
ynh_backup "/etc/logrotate.d/$app"
ynh_backup "/var/log/$app"

#=================================================
# BACKUP SYSTEMD
#=================================================

ynh_backup --src_path="/etc/systemd/system/scrutiny-web-server.service"
ynh_backup --src_path="/etc/systemd/system/scrutiny-collector.service"
ynh_backup --src_path="/etc/systemd/system/scrutiny-collector.timer"
ynh_backup "/etc/systemd/system/scrutiny-web-server.service"
ynh_backup "/etc/systemd/system/scrutiny-collector.service"
ynh_backup "/etc/systemd/system/scrutiny-collector.timer"

#=================================================
# 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)."
40 changes: 15 additions & 25 deletions scripts/change_url
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@
#!/bin/bash

#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================

source _common.sh
source /usr/share/yunohost/helpers

#=================================================
# STANDARD MODIFICATIONS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_script_progression "Stopping $app's systemd service..."

ynh_systemd_action --service_name="influxdb" --action="stop"
ynh_systemd_action --service_name="scrutiny-web-server.service" --action="stop" --log_path="/var/log/$app/web-server.log"
ynh_systemctl --service="influxdb" --action="stop"
ynh_systemctl --service="scrutiny-web-server.service" --action="stop" --log_path="/var/log/$app/web-server.log"
if [ $collector -eq 1 ]
then
ynh_systemd_action --service_name="scrutiny-collector.timer" --action="stop" --log_path="/var/log/$app/collector.log"
ynh_systemctl --service="scrutiny-collector.timer" --action="stop" --log_path="/var/log/$app/collector.log"
fi

#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1
ynh_script_progression "Updating NGINX web server configuration..."

ynh_change_url_nginx_config
ynh_config_change_url_nginx

#=================================================
# SPECIFIC MODIFICATIONS
Expand All @@ -48,34 +40,32 @@ then
key="basepath"
new_value="'$new_base_path'"
sed --regexp-extended "s/^(\s*${key}:\s*).*/\1${new_value}/" --in-place "$install_dir/config/scrutiny.yaml"
ynh_store_file_checksum --file="$install_dir/config/scrutiny.yaml"
ynh_store_file_checksum "$install_dir/config/scrutiny.yaml"

# Update collector.yaml
port=$(ynh_app_setting_get --app=$app --key=port)
port=$(ynh_app_setting_get --key=port)
key="endpoint"
new_value="'http:\/\/127.0.0.1:${port}${new_base_path}\/'"
sed --regexp-extended "s/^(\s*${key}:\s*).*/\1${new_value}/" --in-place "$install_dir/config/collector.yaml"
ynh_store_file_checksum --file="$install_dir/config/collector.yaml"
ynh_store_file_checksum "$install_dir/config/collector.yaml"
fi

#=================================================
# GENERIC FINALISATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_script_progression "Starting $app's systemd service..."

systemctl daemon-reload

ynh_systemd_action --service_name="influxdb" --action="start"
ynh_systemd_action --service_name="scrutiny-web-server.service" --action="start" --log_path="/var/log/$app/web-server.log"
ynh_systemctl --service="influxdb" --action="start"
ynh_systemctl --service="scrutiny-web-server.service" --action="start" --log_path="/var/log/$app/web-server.log"
if [ $collector -eq 1 ]
then
ynh_systemd_action --service_name="scrutiny-collector.timer" --action="start" --log_path="/var/log/$app/collector.log"
ynh_systemctl --service="scrutiny-collector.timer" --action="start" --log_path="/var/log/$app/collector.log"
fi

#=================================================
# END OF SCRIPT
#=================================================

ynh_script_progression --message="Change of URL completed for $app" --last
ynh_script_progression "Change of URL completed for $app"
46 changes: 19 additions & 27 deletions scripts/install
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
#!/bin/bash

#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================

source _common.sh
source /usr/share/yunohost/helpers

Expand All @@ -14,10 +8,10 @@ source /usr/share/yunohost/helpers
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=1
ynh_script_progression "Setting up source files..."

mkdir -p "$install_dir/bin"
ynh_setup_source --source_id="main" --dest_dir="$install_dir/bin"
ynh_setup_source --source_id="scrutiny-web-linux" --dest_dir="$install_dir/bin"
ynh_setup_source --source_id="scrutiny-collector-metrics-linux" --dest_dir="$install_dir/bin"

mkdir -p "$install_dir/web"
Expand All @@ -26,30 +20,30 @@ ynh_setup_source --source_id="scrutiny-web-frontend" --dest_dir="$install_dir/we
#=================================================
# 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 NGINX config using the conf/nginx.conf template
ynh_add_nginx_config
ynh_config_add_nginx

# Create a dedicated systemd config
ynh_add_systemd_config --service="scrutiny-web-server" --template="systemd-scrutiny-web-server.service"
ynh_config_add_systemd --service="scrutiny-web-server" --template="systemd-scrutiny-web-server.service"
yunohost service add "scrutiny-web-server" --description="WebUI for smartd S.M.A.R.T monitoring" --log="/var/log/$app/web-server.log" --test_status="systemctl show scrutiny-web-server.service -p ActiveState --value | grep -v failed"

ynh_add_config --template="systemd-scrutiny-collector.service" --destination="/etc/systemd/system/scrutiny-collector.service"
ynh_config_add --template="systemd-scrutiny-collector.service" --destination="/etc/systemd/system/scrutiny-collector.service"
if [ $collector -eq 1 ]
then
yunohost service add "scrutiny-collector" --description="Collector running on timer (daily) for smartd S.M.A.R.T monitoring" --log="/var/log/$app/collector.log" --test_status="systemctl show scrutiny-collector.service -p ActiveState --value | grep -v failed"
fi

# Use logrotate to manage application logfile(s)
ynh_use_logrotate --specific_user="$app"
ynh_config_add_logrotate

#=================================================
# APP INITIAL CONFIGURATION
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=1
ynh_script_progression "Adding $app's configuration..."

mkdir -p "$install_dir/config"
if [ "${path}" == "/" ]
Expand All @@ -58,37 +52,35 @@ then
else
base_path="${path}"
fi
ynh_add_config --template="config/scrutiny.yaml" --destination="$install_dir/config/scrutiny.yaml"
ynh_config_add --template="config/scrutiny.yaml" --destination="$install_dir/config/scrutiny.yaml"

ynh_add_config --template="systemd-scrutiny-collector.timer" --destination="/etc/systemd/system/scrutiny-collector.timer"
ynh_add_config --template="config/collector.yaml" --destination="$install_dir/config/collector.yaml"
ynh_config_add --template="systemd-scrutiny-collector.timer" --destination="/etc/systemd/system/scrutiny-collector.timer"
ynh_config_add --template="config/collector.yaml" --destination="$install_dir/config/collector.yaml"

#=================================================
# SET FILE OWNERSHIP / PERMISSIONS
#=================================================

myynh_set_permissions

#=================================================
# GENERIC FINALIZATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name="influxdb" --action="enable"
ynh_systemd_action --service_name="influxdb" --action="start"
ynh_script_progression "Starting $app's systemd service..."
ynh_systemctl --service="influxdb" --action="enable"
ynh_systemctl --service="influxdb" --action="start"

ynh_systemd_action --service_name="scrutiny-web-server.service" --action="enable"
ynh_systemd_action --service_name="scrutiny-web-server.service" --action="start" --log_path="/var/log/$app/web-server.log"
ynh_systemctl --service="scrutiny-web-server.service" --action="enable"
ynh_systemctl --service="scrutiny-web-server.service" --action="start" --log_path="/var/log/$app/web-server.log"

if [ $collector -eq 1 ]
then
systemctl daemon-reload
ynh_systemd_action --service_name="scrutiny-collector.timer" --action="enable"
ynh_systemd_action --service_name="scrutiny-collector.timer" --action="start" --log_path="/var/log/$app/collector.log"
ynh_systemctl --service="scrutiny-collector.timer" --action="enable"
ynh_systemctl --service="scrutiny-collector.timer" --action="start" --log_path="/var/log/$app/collector.log"
fi

#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last
ynh_script_progression "Installation of $app completed"
Loading

0 comments on commit f4e912d

Please sign in to comment.