1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/gamja_ynh.git synced 2024-09-03 18:36:34 +02:00

Apply example_ynh

This commit is contained in:
yalh76 2022-07-19 01:49:58 +02:00
parent f0a4cf2766
commit 0f2148122a
17 changed files with 594 additions and 71 deletions

55
.github/ISSUE_TEMPLATE.md vendored Normal file
View file

@ -0,0 +1,55 @@
---
name: Bug report
about: When creating a bug report, please use the following template to provide all the relevant information and help debugging efficiently.
---
**How to post a meaningful bug report**
1. *Read this whole template first.*
2. *Determine if you are on the right place:*
- *If you were performing an action on the app from the webadmin or the CLI (install, update, backup, restore, change_url...), you are on the right place!*
- *Otherwise, the issue may be due to the app itself. Refer to its documentation or repository for help.*
- *When in doubt, post here and we will figure it out together.*
3. *Delete the italic comments as you write over them below, and remove this guide.*
---
### Describe the bug
*A clear and concise description of what the bug is.*
### Context
- Hardware: *VPS bought online / Old laptop or computer / Raspberry Pi at home / Internet Cube with VPN / Other ARM board / ...*
- YunoHost version: x.x.x
- I have access to my server: *Through SSH | through the webadmin | direct access via keyboard / screen | ...*
- Are you in a special context or did you perform some particular tweaking on your YunoHost instance?: *no / yes*
- If yes, please explain:
- Using, or trying to install package version/branch:
- If upgrading, current package version: *can be found in the admin, or with `yunohost app info $app_id`*
### Steps to reproduce
- *If you performed a command from the CLI, the command itself is enough. For example:*
```sh
sudo yunohost app install the_app
```
- *If you used the webadmin, please perform the equivalent command from the CLI first.*
- *If the error occurs in your browser, explain what you did:*
1. *Go to '...'*
2. *Click on '...'*
3. *Scroll down to '...'*
4. *See error*
### Expected behavior
*A clear and concise description of what you expected to happen. You can remove this section if the command above is enough to understand your intent.*
### Logs
*When an operation fails, YunoHost provides a simple way to share the logs.*
- *In the webadmin, the error message contains a link to the relevant log page. On that page, you will be able to 'Share with Yunopaste'. If you missed it, the logs of previous operations are also available under Tools > Logs.*
- *In command line, the command to share the logs is displayed at the end of the operation and looks like `yunohost log display [log name] --share`. If you missed it, you can find the log ID of a previous operation using `yunohost log list`.*
*After sharing the log, please copypaste directly the link provided by YunoHost (to help readability, no need to copypaste the entire content of the log here, just the link is enough...)*
*If applicable and useful, add screenshots to help explain your problem.*

16
.github/PULL_REQUEST_TEMPLATE.md vendored Normal file
View file

@ -0,0 +1,16 @@
## Problem
- *Description of why you made this PR*
## Solution
- *And how do you fix that problem*
## PR Status
- [ ] Code finished and ready to be reviewed/tested
- [ ] The fix/enhancement were manually tested (if applicable)
## Automatic tests
Automatic tests can be triggered on https://ci-apps-dev.yunohost.org/ *after creating the PR*, by commenting "!testme", "!gogogadgetoci" or "By the power of systemd, I invoke The Great App CI to test this Pull Request!". (N.B. : for this to work you need to be a member of the Yunohost-Apps organization)

138
.github/workflows/updater.sh vendored Normal file
View file

@ -0,0 +1,138 @@
#!/bin/bash
#=================================================
# PACKAGE UPDATING HELPER
#=================================================
# This script is meant to be run by GitHub Actions
# The YunoHost-Apps organisation offers a template Action to run this script periodically
# Since each app is different, maintainers can adapt its contents so as to perform
# automatic actions when a new upstream release is detected.
# Remove this exit command when you are ready to run this Action
exit 1
#=================================================
# FETCHING LATEST RELEASE AND ITS ASSETS
#=================================================
# Fetching information
current_version=$(cat manifest.json | jq -j '.version|split("~")[0]')
repo=$(cat manifest.json | jq -j '.upstream.code|split("https://github.com/")[1]')
# Some jq magic is needed, because the latest upstream release is not always the latest version (e.g. security patches for older versions)
version=$(curl --silent "https://api.github.com/repos/$repo/releases" | jq -r '.[] | select( .prerelease != true ) | .tag_name' | sort -V | tail -1)
assets=($(curl --silent "https://api.github.com/repos/$repo/releases" | jq -r '[ .[] | select(.tag_name=="'$version'").assets[].browser_download_url ] | join(" ") | @sh' | tr -d "'"))
# Later down the script, we assume the version has only digits and dots
# Sometimes the release name starts with a "v", so let's filter it out.
# You may need more tweaks here if the upstream repository has different naming conventions.
if [[ ${version:0:1} == "v" || ${version:0:1} == "V" ]]; then
version=${version:1}
fi
# Setting up the environment variables
echo "Current version: $current_version"
echo "Latest release from upstream: $version"
echo "VERSION=$version" >> $GITHUB_ENV
echo "REPO=$repo" >> $GITHUB_ENV
# For the time being, let's assume the script will fail
echo "PROCEED=false" >> $GITHUB_ENV
# Proceed only if the retrieved version is greater than the current one
if ! dpkg --compare-versions "$current_version" "lt" "$version" ; then
echo "::warning ::No new version available"
exit 0
# Proceed only if a PR for this new version does not already exist
elif git ls-remote -q --exit-code --heads https://github.com/$GITHUB_REPOSITORY.git ci-auto-update-v$version ; then
echo "::warning ::A branch already exists for this update"
exit 0
fi
# Each release can hold multiple assets (e.g. binaries for different architectures, source code, etc.)
echo "${#assets[@]} available asset(s)"
#=================================================
# UPDATE SOURCE FILES
#=================================================
# Here we use the $assets variable to get the resources published in the upstream release.
# Here is an example for Grav, it has to be adapted in accordance with how the upstream releases look like.
# Let's loop over the array of assets URLs
for asset_url in ${assets[@]}; do
echo "Handling asset at $asset_url"
# Assign the asset to a source file in conf/ directory
# Here we base the source file name upon a unique keyword in the assets url (admin vs. update)
# Leave $src empty to ignore the asset
case $asset_url in
*"admin"*)
src="app"
;;
*"update"*)
src="app-upgrade"
;;
*)
src=""
;;
esac
# If $src is not empty, let's process the asset
if [ ! -z "$src" ]; then
# Create the temporary directory
tempdir="$(mktemp -d)"
# Download sources and calculate checksum
filename=${asset_url##*/}
curl --silent -4 -L $asset_url -o "$tempdir/$filename"
checksum=$(sha256sum "$tempdir/$filename" | head -c 64)
# Delete temporary directory
rm -rf $tempdir
# Get extension
if [[ $filename == *.tar.gz ]]; then
extension=tar.gz
else
extension=${filename##*.}
fi
# Rewrite source file
cat <<EOT > conf/$src.src
SOURCE_URL=$asset_url
SOURCE_SUM=$checksum
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=$extension
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=
SOURCE_EXTRACT=true
EOT
echo "... conf/$src.src updated"
else
echo "... asset ignored"
fi
done
#=================================================
# SPECIFIC UPDATE STEPS
#=================================================
# Any action on the app's source code can be done.
# The GitHub Action workflow takes care of committing all changes after this script ends.
#=================================================
# GENERIC FINALIZATION
#=================================================
# Replace new version in manifest
echo "$(jq -s --indent 4 ".[] | .version = \"$version~ynh1\"" manifest.json)" > manifest.json
# No need to update the README, yunohost-bot takes care of it
# The Action will proceed only if the PROCEED environment variable is set to true
echo "PROCEED=true" >> $GITHUB_ENV
exit 0

View file

@ -1,8 +1,6 @@
;; Test complet ;; Test complet
; Manifest ; Manifest
domain="domain.tld" domain="domain.tld"
path="/path"
is_public=1
; Checks ; Checks
pkg_linter=1 pkg_linter=1
setup_sub_dir=0 setup_sub_dir=0
@ -11,14 +9,12 @@
setup_private=1 setup_private=1
setup_public=1 setup_public=1
upgrade=1 upgrade=1
#upgrade=1 from_commit=CommitHash # 1.0~ynh1
upgrade=1 from_commit=f0a4cf27669c30c22fa8c9756b6d0b0234bd588c
backup_restore=1 backup_restore=1
multi_instance=1 multi_instance=1
port_already_use=0
change_url=1 change_url=1
;;; Options ;;; Options
Email= Email=
Notification=none Notification=none
;;; Upgrade options
; commit=CommitHash
name=Name and date of the commit.
manifest_arg=domain=DOMAIN&path=PATH&admin=USER&language=fr&is_public=1&password=pass&port=666&

View file

@ -1,5 +1,5 @@
SOURCE_URL=url of app's source SOURCE_URL=https://git.sr.ht/~emersion/gamja/archive/v1.0.0-beta.6.tar.gz
SOURCE_SUM=sha256 checksum SOURCE_SUM=d1b4ddeb681f388c7b9ea469b7bc8c9cb7f0e6f9eb0b97ba8b77c94de281bf0c
SOURCE_SUM_PRG=sha256sum SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true SOURCE_IN_SUBDIR=true

View file

@ -1,5 +1,8 @@
location / { #sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;
root __FINALPATH__/; location __PATH__/ {
# Path to source
alias __FINALPATH__/;
} }
location /webirc/ { location /webirc/ {

7
conf/webircgateway.src Normal file
View file

@ -0,0 +1,7 @@
SOURCE_URL=https://github.com/kiwiirc/webircgateway/archive/a152bf28aa3ba37c0be78b1ef1c26e7f48ce84c2.tar.gz
SOURCE_SUM=a2a6a08596ac1c2c71af09427490b7338d963e6f1c81ea3540e7be4092990340
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=
SOURCE_EXTRACT=true

View file

@ -6,15 +6,15 @@
"en": "Simple IRC web client", "en": "Simple IRC web client",
"fr": "Simple IRC web client" "fr": "Simple IRC web client"
}, },
"version": "1.0~ynh1", "version": "1.0.0-beta.6~ynh2",
"url": "https://web.libera.chat/gamja/", "url": "https://web.libera.chat/gamja/",
"upstream": { "upstream": {
"license": "free", "license": "AGPL-3.0-or-later",
"website": "https://web.libera.chat/gamja/", "website": "https://web.libera.chat/gamja/",
"demo": "https://web.libera.chat/gamja/", "demo": "https://web.libera.chat/gamja/",
"code": "https://sr.ht/~emersion/gamja/" "code": "https://sr.ht/~emersion/gamja/"
}, },
"license": "free", "license": "AGPL-3.0-or-later",
"maintainer": { "maintainer": {
"name": "", "name": "",
"email": "" "email": ""

View file

@ -4,8 +4,10 @@
# COMMON VARIABLES # COMMON VARIABLES
#================================================= #=================================================
# nodejs version # dependencies used by the app
pkg_dependencies=""
nodejs_version=16 nodejs_version=16
go_version=1.13
#================================================= #=================================================
# PERSONAL HELPERS # PERSONAL HELPERS

View file

@ -26,6 +26,7 @@ app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app=$app --key=final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get --app=$app --key=domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
webircgateway_path=$(ynh_app_setting_get --app=$app --key=webircgateway_path)
#================================================= #=================================================
# DECLARE DATA AND CONF FILES TO BACKUP # DECLARE DATA AND CONF FILES TO BACKUP
@ -50,6 +51,12 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup --src_path="/etc/systemd/system/$app.service" ynh_backup --src_path="/etc/systemd/system/$app.service"
#=================================================
# BACKUP VARIOUS FILES
#=================================================
ynh_backup --src_path="$webircgateway_path"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================

View file

@ -108,7 +108,7 @@ fi
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --time --weight=1 ynh_script_progression --message="Starting a systemd service..." --time --weight=1
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Using config"
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX

View file

@ -7,12 +7,16 @@
#================================================= #=================================================
source _common.sh source _common.sh
source ynh_install_go
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
# MANAGE SCRIPT FAILURE # MANAGE SCRIPT FAILURE
#================================================= #=================================================
ynh_clean_setup () {
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
@ -60,8 +64,8 @@ ynh_app_setting_set --app=$app --key=port --value=$port
#================================================= #=================================================
ynh_script_progression --message="Installing dependencies..." --weight=7 ynh_script_progression --message="Installing dependencies..." --weight=7
# Install Nodejs
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_exec_warn_less ynh_install_go --go_version=$go_version
#================================================= #=================================================
# CREATE DEDICATED USER # CREATE DEDICATED USER
@ -78,7 +82,7 @@ ynh_script_progression --message="Setting up source files..." --weight=5
ynh_app_setting_set --app=$app --key=final_path --value=$final_path ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
git clone https://git.sr.ht/~emersion/gamja "$final_path" --quiet ynh_setup_source --dest_dir="$final_path"
chmod 750 "$final_path" chmod 750 "$final_path"
chmod -R o-rwx "$final_path" chmod -R o-rwx "$final_path"
@ -92,10 +96,12 @@ ynh_script_progression --message="Configuring NGINX web server..." --weight=1
# Create a dedicated NGINX config # Create a dedicated NGINX config
ynh_add_nginx_config ynh_add_nginx_config
#============================================== #=================================================
# INSTALL SUTOM # SPECIFIC SETUP
#============================================== #=================================================
ynh_script_progression --message="Building Gamja... (this will take some time and resources!)" --weight=20 # BUILD APP
#=================================================
ynh_script_progression --message="Building app... (this will take some time and resources!)" --weight=20
pushd "$final_path" pushd "$final_path"
ynh_use_nodejs ynh_use_nodejs
@ -114,15 +120,25 @@ chmod 744 "$final_path/config.json"
chown $app:www-data "$final_path/config.json" chown $app:www-data "$final_path/config.json"
#================================================= #=================================================
#CREAT GATEWAYPATH # BUILD WEBIRCGATEWAY
#================================================= #=================================================
ynh_script_progression --message="Setting up gatheway path..." --weight=4 ynh_script_progression --message="Building webircgateway..." --weight=4
webircgateway_path=/var/www/webircgateway webircgateway_path=/var/www/webircgateway
ynh_app_setting_set --app=$app --key=webircgateway_path --value=$webircgateway_path ynh_app_setting_set --app=$app --key=webircgateway_path --value=$webircgateway_path
mkdir -p $webircgateway_path mkdir -p $webircgateway_path
mv ../sources/webircgateway $webircgateway_path/webircgateway tempdir="$(mktemp -d)"
ynh_setup_source --dest_dir=$tempdir --source_id="webircgateway"
pushd $tempdir
ynh_use_go
ynh_go build
popd
mv -f $tempdir/webircgateway $webircgateway_path/webircgateway
ynh_secure_remove --file="$tempdir"
ynh_remove_go
chmod 755 "$webircgateway_path" chmod 755 "$webircgateway_path"
chmod -R o-rwx "$webircgateway_path" chmod -R o-rwx "$webircgateway_path"
@ -142,12 +158,14 @@ ynh_script_progression --message="Configuring a systemd service..." --weight=1
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config ynh_add_systemd_config
#=================================================
# GENERIC FINALIZATION
#================================================= #=================================================
# INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --description="Simple IRC web client" --log="/var/log/$app/$app.log" yunohost service add $app --description="Simple IRC web client"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
@ -155,7 +173,7 @@ yunohost service add $app --description="Simple IRC web client" --log="/var/log/
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression --message="Starting a systemd service..." --weight=1
# Start a systemd service # Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Using config"
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX

View file

@ -19,6 +19,7 @@ app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
port=$(ynh_app_setting_get --app=$app --key=port) port=$(ynh_app_setting_get --app=$app --key=port)
final_path=$(ynh_app_setting_get --app=$app --key=final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
webircgateway_path=$(ynh_app_setting_get --app=$app --key=webircgateway_path)
#================================================= #=================================================
# STANDARD REMOVE # STANDARD REMOVE
@ -41,14 +42,6 @@ ynh_script_progression --message="Stopping and removing the systemd service..."
# Remove the dedicated systemd config # Remove the dedicated systemd config
ynh_remove_systemd_config ynh_remove_systemd_config
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..." --weight=1
# Remove NodeJS
ynh_remove_nodejs
#================================================= #=================================================
# REMOVE APP MAIN DIR # REMOVE APP MAIN DIR
#================================================= #=================================================
@ -65,6 +58,24 @@ ynh_script_progression --message="Removing NGINX web server configuration..." --
# Remove the dedicated NGINX config # Remove the dedicated NGINX config
ynh_remove_nginx_config ynh_remove_nginx_config
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..." --weight=1
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
ynh_remove_nodejs
#=================================================
# SPECIFIC REMOVE
#=================================================
# REMOVE VARIOUS FILES
#=================================================
ynh_script_progression --message="Removing various files..."
ynh_secure_remove --file="$webircgateway_path"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#================================================= #=================================================

View file

@ -14,6 +14,9 @@ source /usr/share/yunohost/helpers
# MANAGE SCRIPT FAILURE # MANAGE SCRIPT FAILURE
#================================================= #=================================================
ynh_clean_setup () {
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
@ -27,6 +30,7 @@ app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path) path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
webircgateway_path=$(ynh_app_setting_get --app=$app --key=webircgateway_path)
#================================================= #=================================================
# CHECK IF THE APP CAN BE RESTORED # CHECK IF THE APP CAN BE RESTORED
@ -38,13 +42,6 @@ test ! -d $final_path \
#================================================= #=================================================
# STANDARD RESTORATION STEPS # STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
# RECREATE THE DEDICATED USER # RECREATE THE DEDICATED USER
#================================================= #=================================================
@ -69,9 +66,22 @@ chown -R $app:www-data "$final_path"
#================================================= #=================================================
ynh_script_progression --message="Reinstalling dependencies..." --weight=7 ynh_script_progression --message="Reinstalling dependencies..." --weight=7
# Install Nodejs
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE VARIOUS FILES
#=================================================
ynh_script_progression --message="Restoring various files..."
ynh_restore_file --origin_path="$webircgateway_path"
#================================================= #=================================================
# RESTORE SYSTEMD # RESTORE SYSTEMD
#================================================= #=================================================
@ -85,14 +95,14 @@ systemctl enable $app.service --quiet
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --description="Simple IRC web client" --log="/var/log/$app/$app.log" yunohost service add $app --description="Simple IRC web client"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Using config"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION

View file

@ -7,6 +7,7 @@
#================================================= #=================================================
source _common.sh source _common.sh
source ynh_install_go
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -20,10 +21,12 @@ domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path) path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
port=$(ynh_app_setting_get --app=$app --key=port) port=$(ynh_app_setting_get --app=$app --key=port)
webircgateway_path=$(ynh_app_setting_get --app=$app --key=webircgateway_path)
#================================================= #=================================================
# CHECK VERSION # CHECK VERSION
#================================================= #=================================================
ynh_script_progression --message="Checking version..."
upgrade_type=$(ynh_check_app_version_changed) upgrade_type=$(ynh_check_app_version_changed)
@ -35,6 +38,7 @@ ynh_script_progression --message="Backing up the app before upgrading (may take
# Backup the current version of the app # Backup the current version of the app
ynh_backup_before_upgrade ynh_backup_before_upgrade
ynh_clean_setup () { ynh_clean_setup () {
ynh_clean_check_starting
# Restore it if the upgrade fails # Restore it if the upgrade fails
ynh_restore_upgradebackup ynh_restore_upgradebackup
} }
@ -79,16 +83,21 @@ then
ynh_script_progression --message="Upgrading source files..." --weight=3 ynh_script_progression --message="Upgrading source files..." --weight=3
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
pushd $final_path ynh_setup_source --dest_dir="$final_path" --keep="config.json"
git fetch
git pull
popd
fi fi
chmod 750 "$final_path" chmod 750 "$final_path"
chmod -R o-rwx "$final_path" chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path" chown -R $app:www-data "$final_path"
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=5
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_exec_warn_less ynh_install_go --go_version=$go_version
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
@ -97,10 +106,12 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." -
# Create a dedicated NGINX config # Create a dedicated NGINX config
ynh_add_nginx_config ynh_add_nginx_config
#=================================================
# SPECIFIC UPGRADE
#============================================== #==============================================
# INSTALL SUTOM # BUILD APP
#============================================== #=================================================
ynh_script_progression --message="Building Gamja... (this will take some time and resources!)" --weight=20 ynh_script_progression --message="Building app... (this will take some time and resources!)" --weight=20
pushd "$final_path" pushd "$final_path"
ynh_use_nodejs ynh_use_nodejs
@ -109,9 +120,9 @@ pushd "$final_path"
popd popd
#================================================= #=================================================
# ADD A CONFIGURATION # UPDATE A CONFIG FILE
#================================================= #=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=1 ynh_script_progression --message="Updating a configuration file..." --weight=1
ynh_add_config --template="../conf/config.json" --destination="$final_path/config.json" ynh_add_config --template="../conf/config.json" --destination="$final_path/config.json"
@ -119,15 +130,23 @@ chmod 744 "$final_path/config.json"
chown $app:www-data "$final_path/config.json" chown $app:www-data "$final_path/config.json"
#================================================= #=================================================
#CREAT GATEWAYPATH # BUILD WEBIRCGATEWAY
#================================================= #=================================================
ynh_script_progression --message="Setting up gatheway path..." --weight=2 ynh_script_progression --message="Building webircgateway..." --weight=4
webircgateway_path=/var/www/webircgateway
ynh_app_setting_set --app=$app --key=webircgateway_path --value=$webircgateway_path
mkdir -p $webircgateway_path mkdir -p $webircgateway_path
mv ../sources/webircgateway $webircgateway_path/webircgateway tempdir="$(mktemp -d)"
ynh_setup_source --dest_dir=$tempdir --source_id="webircgateway"
pushd $tempdir
ynh_use_go
ynh_go build
popd
mv -f $tempdir/webircgateway $webircgateway_path/webircgateway
ynh_secure_remove --file="$tempdir"
ynh_remove_go
chmod 755 "$webircgateway_path" chmod 755 "$webircgateway_path"
chmod -R o-rwx "$webircgateway_path" chmod -R o-rwx "$webircgateway_path"
@ -139,14 +158,6 @@ ynh_add_config --template="../conf/config.conf" --destination="$webircgateway_pa
chmod 755 "$webircgateway_path/config.conf" chmod 755 "$webircgateway_path/config.conf"
chown $app:www-data "$webircgateway_path/config.conf" chown $app:www-data "$webircgateway_path/config.conf"
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=5
# Install Nodejs
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
#================================================= #=================================================
@ -155,12 +166,14 @@ ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config ynh_add_systemd_config
#=================================================
# GENERIC FINALIZATION
#================================================= #=================================================
# INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --description="Simple IRC web client" --log="/var/log/$app/$app.log" yunohost service add $app --description="Simple IRC web client"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
@ -174,7 +187,7 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="systemd"
#================================================= #=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1 ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Using config"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT

247
scripts/ynh_install_go Normal file
View file

@ -0,0 +1,247 @@
#!/bin/bash
ynh_go_try_bash_extension() {
if [ -x src/configure ]; then
src/configure && make -C src || {
ynh_print_info --message="Optional bash extension failed to build, but things will still work normally."
}
fi
}
goenv_install_dir="/opt/goenv"
go_version_path="$goenv_install_dir/versions"
# goenv_ROOT is the directory of goenv, it needs to be loaded as a environment variable.
export GOENV_ROOT="$goenv_install_dir"
# Load the version of Go for an app, and set variables.
#
# ynh_use_go has to be used in any app scripts before using Go for the first time.
# This helper will provide alias and variables to use in your scripts.
#
# To use gem or Go, use the alias `ynh_gem` and `ynh_go`
# Those alias will use the correct version installed for the app
# For example: use `ynh_gem install` instead of `gem install`
#
# With `sudo` or `ynh_exec_as`, use instead the fallback variables `$ynh_gem` and `$ynh_go`
# And propagate $PATH to sudo with $ynh_go_load_path
# Exemple: `ynh_exec_as $app $ynh_go_load_path $ynh_gem install`
#
# $PATH contains the path of the requested version of Go.
# However, $PATH is duplicated into $go_path to outlast any manipulation of $PATH
# You can use the variable `$ynh_go_load_path` to quickly load your Go version
# in $PATH for an usage into a separate script.
# Exemple: $ynh_go_load_path $final_path/script_that_use_gem.sh`
#
#
# Finally, to start a Go service with the correct version, 2 solutions
# Either the app is dependent of Go or gem, but does not called it directly.
# In such situation, you need to load PATH
# `Environment="__YNH_GO_LOAD_PATH__"`
# `ExecStart=__FINALPATH__/my_app`
# You will replace __YNH_GO_LOAD_PATH__ with $ynh_go_load_path
#
# Or Go start the app directly, then you don't need to load the PATH variable
# `ExecStart=__YNH_GO__ my_app run`
# You will replace __YNH_GO__ with $ynh_go
#
#
# one other variable is also available
# - $go_path: The absolute path to Go binaries for the chosen version.
#
# usage: ynh_use_go
#
# Requires YunoHost version 3.2.2 or higher.
ynh_use_go () {
go_version=$(ynh_app_setting_get --app=$app --key=go_version)
# Get the absolute path of this version of Go
go_path="$go_version_path/$go_version/bin"
# Allow alias to be used into bash script
shopt -s expand_aliases
# Create an alias for the specific version of Go and a variable as fallback
ynh_go="$go_path/go"
alias ynh_go="$ynh_go"
# Load the path of this version of Go in $PATH
if [[ :$PATH: != *":$go_path"* ]]; then
PATH="$go_path:$PATH"
fi
# Create an alias to easily load the PATH
ynh_go_load_path="PATH=$PATH"
# Sets the local application-specific Go version
pushd $final_path
$goenv_install_dir/bin/goenv local $go_version
popd
}
# Install a specific version of Go
#
# ynh_install_go will install the version of Go provided as argument by using goenv.
#
# This helper creates a /etc/profile.d/goenv.sh that configures PATH environment for goenv
# for every LOGIN user, hence your user must have a defined shell (as opposed to /usr/sbin/nologin)
#
# Don't forget to execute go-dependent command in a login environment
# (e.g. sudo --login option)
# When not possible (e.g. in systemd service definition), please use direct path
# to goenv shims (e.g. $goenv_ROOT/shims/bundle)
#
# usage: ynh_install_go --go_version=go_version
# | arg: -v, --go_version= - Version of go to install.
#
# Requires YunoHost version 3.2.2 or higher.
ynh_install_go () {
# Declare an array to define the options of this helper.
local legacy_args=v
local -A args_array=( [v]=go_version= )
local go_version
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
# Load goenv path in PATH
local CLEAR_PATH="$goenv_install_dir/bin:$PATH"
# Remove /usr/local/bin in PATH in case of Go prior installation
PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
# Move an existing Go binary, to avoid to block goenv
test -x /usr/bin/go && mv /usr/bin/go /usr/bin/go_goenv
# Install or update goenv
goenv="$(command -v goenv $goenv_install_dir/bin/goenv | head -1)"
if [ -n "$goenv" ]; then
ynh_print_info --message="goenv already seems installed in \`$goenv'."
pushd "${goenv%/*/*}"
if git remote -v 2>/dev/null | grep "https://github.com/syndbg/goenv.git"; then
echo "Trying to update with git..."
git pull -q --tags origin master
cd ..
ynh_go_try_bash_extension
fi
popd
else
ynh_print_info --message="Installing goenv with git..."
mkdir -p $goenv_install_dir
pushd $goenv_install_dir
git init -q
git remote add -f -t master origin https://github.com/syndbg/goenv.git > /dev/null 2>&1
git checkout -q -b master origin/master
ynh_go_try_bash_extension
goenv=$goenv_install_dir/bin/goenv
popd
fi
goenv_latest="$(command -v "$goenv_install_dir"/plugins/*/bin/goenv-latest goenv-latest | head -1)"
if [ -n "$goenv_latest" ]; then
ynh_print_info --message="\`goenv latest' command already available in \`$goenv_latest'."
pushd "${goenv_latest%/*/*}"
if git remote -v 2>/dev/null | grep "https://github.com/momo-lab/xxenv-latest.git"; then
ynh_print_info --message="Trying to update xxenv-latest with git..."
git pull -q origin master
fi
popd
else
ynh_print_info --message="Installing xxenv-latest with git..."
mkdir -p "${goenv_install_dir}/plugins"
git clone -q https://github.com/momo-lab/xxenv-latest.git "${goenv_install_dir}/plugins/xxenv-latest"
fi
# Enable caching
mkdir -p "${goenv_install_dir}/cache"
# Create shims directory if needed
mkdir -p "${goenv_install_dir}/shims"
# Restore /usr/local/bin in PATH
PATH=$CLEAR_PATH
# And replace the old Go binary
test -x /usr/bin/go_goenv && mv /usr/bin/go_goenv /usr/bin/go
# Install the requested version of Go
local final_go_version=$(goenv latest --print $go_version)
ynh_print_info --message="Installation of Go-$final_go_version"
goenv install --skip-existing $final_go_version
# Store go_version into the config of this app
ynh_app_setting_set --app=$YNH_APP_INSTANCE_NAME --key=go_version --value=$final_go_version
# Cleanup Go versions
ynh_cleanup_go
# Set environment for Go users
echo "#goenv
export GOENV_ROOT=$goenv_install_dir
export PATH=\"$goenv_install_dir/bin:$PATH\"
eval \"\$(goenv init -)\"
#goenv" > /etc/profile.d/goenv.sh
# Load the environment
eval "$(goenv init -)"
}
# Remove the version of Go used by the app.
#
# This helper will also cleanup Go versions
#
# usage: ynh_remove_go
ynh_remove_go () {
local go_version=$(ynh_app_setting_get --app=$YNH_APP_INSTANCE_NAME --key=go_version)
# Load goenv path in PATH
local CLEAR_PATH="$goenv_install_dir/bin:$PATH"
# Remove /usr/local/bin in PATH in case of Go prior installation
PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
# Remove the line for this app
ynh_app_setting_delete --app=$YNH_APP_INSTANCE_NAME --key=go_version
# Cleanup Go versions
ynh_cleanup_go
}
# Remove no more needed versions of Go used by the app.
#
# This helper will check what Go version are no more required,
# and uninstall them
# If no app uses Go, goenv will be also removed.
#
# usage: ynh_cleanup_go
ynh_cleanup_go () {
# List required Go versions
local installed_apps=$(yunohost app list --output-as json --quiet | jq -r .apps[].id)
local required_go_versions=""
for installed_app in $installed_apps
do
local installed_app_go_version=$(ynh_app_setting_get --app=$installed_app --key="go_version")
if [[ $installed_app_go_version ]]
then
required_go_versions="${installed_app_go_version}\n${required_go_versions}"
fi
done
# Remove no more needed Go versions
local installed_go_versions=$(goenv versions --bare --skip-aliases | grep -Ev '/')
for installed_go_version in $installed_go_versions
do
if ! `echo ${required_go_versions} | grep "${installed_go_version}" 1>/dev/null 2>&1`
then
ynh_print_info --message="Removing of Go-$installed_go_version"
$goenv_install_dir/bin/goenv uninstall --force $installed_go_version
fi
done
# If none Go version is required
if [[ ! $required_go_versions ]]
then
# Remove goenv environment configuration
ynh_print_info --message="Removing of goenv"
ynh_secure_remove --file="$goenv_install_dir"
ynh_secure_remove --file="/etc/profile.d/goenv.sh"
fi
}

Binary file not shown.