From 319ffd33a5866f2ec3010143c44af17e37e6742f Mon Sep 17 00:00:00 2001 From: tituspijean Date: Sun, 6 Feb 2022 18:05:38 +0000 Subject: [PATCH] Fix Go installation for multiple architectures --- conf/systemd.service | 5 ++++- scripts/_common.sh | 2 ++ scripts/install | 42 ++++++++++++++++++++---------------------- scripts/remove | 4 ++++ scripts/restore | 15 +++++---------- scripts/upgrade | 36 ++++++++++++++++++------------------ 6 files changed, 53 insertions(+), 51 deletions(-) diff --git a/conf/systemd.service b/conf/systemd.service index 996a086..861b72d 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -7,7 +7,10 @@ Type=simple User=__APP__ Group=__APP__ WorkingDirectory=__FINALPATH__/ -ExecStart=__FINALPATH__/./bin/dendrite-monolith-server --tls-cert=/etc/yunohost/certs/__DOMAIN__/crt.pem --tls-key=/etc/yunohost/certs/__DOMAIN__/key.pem --config=dendrite.yaml --http-bind-address=:__PORT__ --https-bind-address=:__TLS_PORT__ >> /var/log/__APP__/__APP__.log 2>&1 +Environment="__YNH_GO_LOAD_PATH__" +ExecStart=__FINALPATH__/bin/dendrite-monolith-server --tls-cert=/etc/yunohost/certs/__DOMAIN__/crt.pem --tls-key=/etc/yunohost/certs/__DOMAIN__/key.pem --config=dendrite.yaml --http-bind-address=:__PORT__ --https-bind-address=:__TLS_PORT__ +StandardOutput=append:/var/log/__APP__/__APP__.log +StandardError=inherit # Sandboxing options to harden security # Depending on specificities of your service/app, you may need to tweak these diff --git a/scripts/_common.sh b/scripts/_common.sh index c0220ac..c974660 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -7,6 +7,8 @@ # dependencies used by the app pkg_dependencies="postgresql postgresql-contrib" +go_version="1.16" + #================================================= # PERSONAL HELPERS #================================================= diff --git a/scripts/install b/scripts/install index d03d6b6..e2d21dc 100644 --- a/scripts/install +++ b/scripts/install @@ -7,6 +7,7 @@ #================================================= source _common.sh +source ynh_install_go source /usr/share/yunohost/helpers #================================================= @@ -67,6 +68,15 @@ ynh_exec_warn_less yunohost firewall allow TCP $tls_port ynh_app_setting_set --app=$app --key=port --value=$port ynh_app_setting_set --app=$app --key=tls_port --value=$tls_port +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user..." --weight=1 + +# Create a system user +# It needs to be created before using the ynh_install_go helper +ynh_system_user_create --username=$app --use_shell --groups="ssl-cert" + #================================================= # INSTALL DEPENDENCIES #================================================= @@ -74,15 +84,8 @@ ynh_script_progression --message="Installing dependencies..." --weight=3 ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies -# Install Go if needed -if ! command -v /usr/local/go/bin/go &> /dev/null -then - ynh_script_progression --message="Installing Go dependency... (this will take some time)" --weight=3 - ynh_setup_source --source_id="go" --dest_dir="/usr/local/" -fi - -export PATH=$PATH:/usr/local/go/bin -env_path=$PATH +# Install Go +ynh_exec_warn_less ynh_install_go --go_version=$go_version #================================================= # CREATE A POSTGRESQL DATABASE @@ -94,8 +97,8 @@ ynh_app_setting_set --app=$app --key=db_name --value=$db_name ynh_psql_test_if_first_run ynh_psql_setup_db --db_user=$db_name --db_name=$db_name -ynh_psql_execute_as_root \ ---sql="CREATE DATABASE $db_name ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER $app;" +ynh_psql_execute_as_root --sql="DROP DATABASE $db_name" +ynh_psql_execute_as_root --sql="CREATE DATABASE $db_name ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER $app;" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -114,26 +117,21 @@ ynh_script_progression --message="Configuring NGINX web server..." --weight=1 # Create a dedicated NGINX config ynh_add_nginx_config -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." --weight=1 - -# Create a system user -ynh_system_user_create --username=$app -adduser $app ssl-cert - #================================================= # SPECIFIC SETUP #================================================= # BUILDING SOURCES AND SETTING UP THE SERVER #================================================= +ynh_use_go + +mkdir -p "$final_path/bin" +chown -R $app:root $final_path + pushd "$final_path" ynh_script_progression --message="Building the sources (it will take some time)..." --weight=6 # Build the sources - mkdir ./bin - ynh_exec_warn_less ./build.sh + ynh_exec_warn_less ynh_exec_as $app $ynh_go_load_path HOME=$final_path ./build.sh ynh_script_progression --message="Generating the keys..." --weight=1 # Generate a Matrix signing key for federation ./bin/generate-keys --private-key matrix_key.pem diff --git a/scripts/remove b/scripts/remove index 601e5f3..effd47e 100644 --- a/scripts/remove +++ b/scripts/remove @@ -7,6 +7,7 @@ #================================================= source _common.sh +source ynh_install_go source /usr/share/yunohost/helpers #================================================= @@ -58,6 +59,9 @@ ynh_script_progression --message="Removing dependencies..." --weight=3 # Remove metapackage and its dependencies ynh_remove_app_dependencies +# Remove Go +ynh_remove_go + #================================================= # REMOVE APP MAIN DIR #================================================= diff --git a/scripts/restore b/scripts/restore index 375b040..4fbfa23 100644 --- a/scripts/restore +++ b/scripts/restore @@ -8,6 +8,7 @@ # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh +source ../settings/scripts/ynh_install_go source /usr/share/yunohost/helpers #================================================= @@ -66,7 +67,7 @@ ynh_restore_file --origin_path="$final_path" ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 # Create the dedicated user (if not existing) -ynh_system_user_create --username=$app +ynh_system_user_create --username=$app --use_shell --groups="ssl-cert" #================================================= # RESTORE USER RIGHTS @@ -87,15 +88,8 @@ ynh_script_progression --message="Reinstalling dependencies..." --weight=3 # Define and install dependencies ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies -# Install Go if needed -if ! command -v /usr/local/go/bin/go &> /dev/null -then - ynh_script_progression --message="Installing Go dependency... (this will take some time)" --weight=3 - ynh_setup_source --source_id="go" --dest_dir="/usr/local/" -fi - -export PATH=$PATH:/usr/local/go/bin -env_path=$PATH +# Install Go +ynh_install_go --go_version=$go_version #================================================= # RESTORE THE PSQL DATABASE @@ -119,6 +113,7 @@ systemctl enable $app.service --quiet #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 +ynh_use_go yunohost service add $app --description="Dendrite Matrix homeserver" --log="/var/log/$app/Monolith.log" --needs_exposed_ports "$tls_port" #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index f490dbc..60cf7bb 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,6 +7,7 @@ #================================================= source _common.sh +source ynh_install_go source /usr/share/yunohost/helpers #================================================= @@ -81,6 +82,15 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." - # Create a dedicated NGINX config ynh_add_nginx_config +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 + +# Create a dedicated user (if not existing) +# It needs to be created before using the ynh_install_go helper +ynh_system_user_create --username=$app --use_shell --groups="ssl-cert" + #================================================= # UPGRADE DEPENDENCIES #================================================= @@ -88,23 +98,8 @@ ynh_script_progression --message="Upgrading dependencies..." --weight=1 ynh_exec_warn_less ynh_install_app_dependencies "$pkg_dependencies" -# TODO: check Go version and upgrade if needed -if ! command -v /usr/local/go/bin/go &> /dev/null -then - ynh_script_progression --message="Installing Go dependency... (this will take some time)" --weight=3 - ynh_setup_source --source_id="go" --dest_dir="/usr/local/" -fi - -export PATH=$PATH:/usr/local/go/bin -env_path=$PATH - -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 - -# Create a dedicated user (if not existing) -ynh_system_user_create --username=$app +# Install Go +ynh_exec_warn_less ynh_install_go --go_version=$go_version #================================================= # SPECIFIC UPGRADE @@ -112,10 +107,15 @@ ynh_system_user_create --username=$app # BUILDING SOURCES AND SETTING UP THE SERVER #================================================= +ynh_use_go + +mkdir -p "$final_path/bin" +chown -R $app:root $final_path + pushd "$final_path" ynh_script_progression --message="Building the sources (it will take some time)..." --weight=6 # Build the sources - ynh_exec_warn_less ./build.sh + ynh_exec_warn_less ynh_exec_as $app $ynh_go_load_path HOME=$final_path ./build.sh popd #=================================================