mirror of
https://github.com/YunoHost-Apps/listmonk_ynh.git
synced 2024-09-03 19:36:15 +02:00
commit
92aee4083c
12 changed files with 25 additions and 520 deletions
136
.github/workflows/updater.sh
vendored
136
.github/workflows/updater.sh
vendored
|
@ -1,136 +0,0 @@
|
|||
#!/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
|
||||
# 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=
|
||||
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
|
|
@ -16,10 +16,10 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in
|
|||
|
||||
## Overview
|
||||
|
||||
Listmonk is a standalone, self-hosted, newsletter and mailing list manager. It is fast, feature-rich, and packed into a single binary. It uses a PostgreSQL (⩾ v9.4) database as its data store.
|
||||
Listmonk is a standalone, self-hosted, newsletter and mailing list manager. It is fast, feature-rich, and packed into a single binary. It uses a PostgreSQL database as its data base.
|
||||
|
||||
|
||||
**Shipped version:** 2.4.0~ynh3
|
||||
**Shipped version:** 2.5.1~ynh1
|
||||
|
||||
**Demo:** https://demo.listmonk.app/
|
||||
|
||||
|
|
|
@ -16,10 +16,10 @@ Si vous n’avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) po
|
|||
|
||||
## Vue d’ensemble
|
||||
|
||||
Listmonk is a standalone, self-hosted, newsletter and mailing list manager. It is fast, feature-rich, and packed into a single binary. It uses a PostgreSQL (⩾ v9.4) database as its data store.
|
||||
Listmonk est un gestionnaire de newsletter et de liste de diffusion autonome et auto-hébergé. Il est rapide, riche en fonctionnalités et emballé dans un seul binaire. Il utilise une base de données PostgreSQL comme base de données.
|
||||
|
||||
|
||||
**Version incluse :** 2.4.0~ynh3
|
||||
**Version incluse :** 2.5.1~ynh1
|
||||
|
||||
**Démo :** https://demo.listmonk.app/
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Listmonk is a standalone, self-hosted, newsletter and mailing list manager. It is fast, feature-rich, and packed into a single binary. It uses a PostgreSQL (⩾ v9.4) database as its data store.
|
||||
Listmonk is a standalone, self-hosted, newsletter and mailing list manager. It is fast, feature-rich, and packed into a single binary. It uses a PostgreSQL database as its data base.
|
||||
|
|
1
doc/DESCRIPTION_fr.md
Normal file
1
doc/DESCRIPTION_fr.md
Normal file
|
@ -0,0 +1 @@
|
|||
Listmonk est un gestionnaire de newsletter et de liste de diffusion autonome et auto-hébergé. Il est rapide, riche en fonctionnalités et emballé dans un seul binaire. Il utilise une base de données PostgreSQL comme base de données.
|
|
@ -5,7 +5,7 @@ name = "Listmonk"
|
|||
description.en = "Newsletter and mailing list manager"
|
||||
description.fr = "Manager de newsletter et mailing list"
|
||||
|
||||
version = "2.4.0~ynh3"
|
||||
version = "2.5.1~ynh1"
|
||||
|
||||
maintainers = ["Navan Chauhan"]
|
||||
|
||||
|
@ -17,7 +17,7 @@ admindoc = "https://listmonk.app/docs/"
|
|||
code = "https://github.com/knadh/listmonk"
|
||||
|
||||
[integration]
|
||||
yunohost = ">= 11.1.18"
|
||||
yunohost = ">= 11.2"
|
||||
architectures = ["amd64", "armhf", "arm64"]
|
||||
multi_instance = true
|
||||
ldap = false
|
||||
|
@ -43,12 +43,12 @@ ram.runtime = "50M"
|
|||
[resources.sources]
|
||||
|
||||
[resources.sources.main]
|
||||
amd64.url = "https://github.com/knadh/listmonk/releases/download/v2.4.0/listmonk_2.4.0_linux_amd64.tar.gz"
|
||||
amd64.sha256 = "acdfd0f4549c15e3cd77a28778ac9904cc54abf3bec98074ee96edc64242971b"
|
||||
armhf.url = "https://github.com/knadh/listmonk/archive/refs/tags/v2.4.0.tar.gz"
|
||||
armhf.sha256 = "60571f7e279524bee81be066bbc27929042dbe7bf4740cabeb734a0269b81939"
|
||||
arm64.url = "https://github.com/knadh/listmonk/archive/refs/tags/v2.4.0.tar.gz"
|
||||
arm64.sha256 = "60571f7e279524bee81be066bbc27929042dbe7bf4740cabeb734a0269b81939"
|
||||
amd64.url = "https://github.com/knadh/listmonk/releases/download/v2.5.1/listmonk_2.5.1_linux_amd64.tar.gz"
|
||||
amd64.sha256 = "552bb7cb47d7b55be7b48a4ccc19d69b96491065433dafd8cc6a0f39869e4113"
|
||||
armhf.url = "https://github.com/knadh/listmonk/releases/download/v2.5.1/listmonk_2.5.1_linux_armv7.tar.gz"
|
||||
armhf.sha256 = "7e7e96d64cd2af96711d8d3db717cfdb5c4b8c9ac3fb78b43a4704a8e5625c99"
|
||||
arm64.url = "https://github.com/knadh/listmonk/releases/download/v2.5.1/listmonk_2.5.1_linux_arm64.tar.gz"
|
||||
arm64.sha256 = "832c5a34ed78446c179ed5423cdbce51d3e51333c1ea6cf11c74b63e0776193a"
|
||||
in_subdir = false
|
||||
|
||||
[resources.system_user]
|
||||
|
@ -74,9 +74,5 @@ ram.runtime = "50M"
|
|||
[resources.apt]
|
||||
packages = "postgresql"
|
||||
|
||||
extras.yarn.repo = "deb https://dl.yarnpkg.com/debian/ stable main"
|
||||
extras.yarn.key = "https://dl.yarnpkg.com/debian/pubkey.gpg"
|
||||
extras.yarn.packages = "yarn"
|
||||
|
||||
[resources.database]
|
||||
type = "postgresql"
|
||||
|
|
|
@ -4,9 +4,6 @@
|
|||
# COMMON VARIABLES
|
||||
#=================================================
|
||||
|
||||
nodejs_version=16
|
||||
GO_VERSION="1.18"
|
||||
|
||||
#=================================================
|
||||
# PERSONAL HELPERS
|
||||
#=================================================
|
||||
|
|
|
@ -7,62 +7,18 @@
|
|||
#=================================================
|
||||
|
||||
source _common.sh
|
||||
source ynh_install_go
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# INSTALL DEPENDENCIES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Installing dependencies..." --weight=12
|
||||
|
||||
if [ $YNH_ARCH == "armhf" ] || [ $YNH_ARCH == "arm64" ]
|
||||
then
|
||||
# Install Nodejs
|
||||
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
|
||||
|
||||
# Install Go
|
||||
ynh_exec_warn_less ynh_install_go --go_version=$GO_VERSION
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Setting up source files..." --weight=3
|
||||
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
if [ $YNH_ARCH == "armhf" ] || [ $YNH_ARCH == "arm64" ]
|
||||
then
|
||||
ynh_setup_source --dest_dir="$install_dir/build"
|
||||
pushd "$install_dir/build"
|
||||
# Change to sources directory
|
||||
cd listmonk-*
|
||||
# Build the sources
|
||||
ynh_use_go
|
||||
export GOPATH="$install_dir/build/go"
|
||||
export GOCACHE="$install_dir/build/.cache"
|
||||
ynh_use_nodejs
|
||||
make dist
|
||||
mv listmonk ../../
|
||||
popd
|
||||
ynh_remove_go
|
||||
ynh_remove_nodejs
|
||||
ynh_secure_remove --file="$install_dir/build"
|
||||
else
|
||||
ynh_setup_source --dest_dir="$install_dir"
|
||||
fi
|
||||
ynh_setup_source --dest_dir="$install_dir"
|
||||
|
||||
chmod -R o-rwx "$install_dir"
|
||||
chown -R $app:www-data "$install_dir"
|
||||
chmod +x "$install_dir/listmonk"
|
||||
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
|
||||
|
||||
# Create a dedicated NGINX config
|
||||
ynh_add_nginx_config
|
||||
|
||||
#=================================================
|
||||
# ADD A CONFIGURATION
|
||||
#=================================================
|
||||
|
@ -87,14 +43,12 @@ popd
|
|||
#=================================================
|
||||
ynh_script_progression --message="Configuring a systemd service..." --weight=1
|
||||
|
||||
# Create a dedicated NGINX config
|
||||
ynh_add_nginx_config
|
||||
|
||||
# Create a dedicated systemd config
|
||||
ynh_add_systemd_config
|
||||
|
||||
#=================================================
|
||||
# INTEGRATE SERVICE IN YUNOHOST
|
||||
#=================================================
|
||||
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
||||
|
||||
yunohost service add $app --description="Newsletter and mailing list manager" --log="/var/log/$app/$app.log"
|
||||
|
||||
#=================================================
|
||||
|
|
|
@ -22,19 +22,9 @@ then
|
|||
yunohost service remove $app
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# STOP AND REMOVE SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=2
|
||||
|
||||
# Remove the dedicated systemd config
|
||||
ynh_remove_systemd_config
|
||||
|
||||
#=================================================
|
||||
# REMOVE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1
|
||||
|
||||
# Remove the dedicated NGINX config
|
||||
ynh_remove_nginx_config
|
||||
|
||||
|
|
|
@ -10,15 +10,6 @@
|
|||
source ../settings/scripts/_common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# STANDARD RESTORATION STEPS
|
||||
#=================================================
|
||||
# RESTORE THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=2
|
||||
|
||||
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE APP MAIN DIR
|
||||
#=================================================
|
||||
|
@ -26,7 +17,6 @@ ynh_script_progression --message="Restoring the app main directory..." --weight=
|
|||
|
||||
ynh_restore_file --origin_path="$install_dir"
|
||||
|
||||
chmod -R o-rwx "$install_dir"
|
||||
chown -R $app:www-data "$install_dir"
|
||||
chmod +x "$install_dir/listmonk"
|
||||
|
||||
|
@ -42,14 +32,11 @@ ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name
|
|||
#=================================================
|
||||
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
|
||||
|
||||
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
|
||||
systemctl enable $app.service --quiet
|
||||
|
||||
#=================================================
|
||||
# INTEGRATE SERVICE IN YUNOHOST
|
||||
#=================================================
|
||||
ynh_script_progression --message="Integrating service in YunoHost..." --weight=2
|
||||
|
||||
yunohost service add $app --description="Newsletter and mailing list manager" --log="/var/log/$app/$app.log"
|
||||
|
||||
#=================================================
|
||||
|
@ -59,13 +46,6 @@ ynh_script_progression --message="Starting a systemd service..." --weight=3
|
|||
|
||||
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd"
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# RELOAD NGINX AND PHP-FPM
|
||||
#=================================================
|
||||
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
||||
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
|
||||
#=================================================
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#=================================================
|
||||
|
||||
source _common.sh
|
||||
source ynh_install_go
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
|
@ -34,43 +33,14 @@ then
|
|||
ynh_script_progression --message="Upgrading source files..." --weight=5
|
||||
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
if [ $YNH_ARCH == "armhf" ] || [ $YNH_ARCH == "arm64" ]
|
||||
then
|
||||
ynh_setup_source --dest_dir="$install_dir/build" --keep="$install_dir/config.toml"
|
||||
# Install Nodejs
|
||||
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
|
||||
# Install Go
|
||||
ynh_exec_warn_less ynh_install_go --go_version=$GO_VERSION
|
||||
pushd "$install_dir/build"
|
||||
cd listmonk-*
|
||||
# Build the sources
|
||||
ynh_use_go
|
||||
export GOPATH="$install_dir/build/go"
|
||||
export GOCACHE="$install_dir/build/.cache"
|
||||
ynh_use_nodejs
|
||||
make dist
|
||||
mv listmonk ../../
|
||||
popd
|
||||
ynh_remove_go
|
||||
ynh_remove_nodejs
|
||||
ynh_secure_remove --file="$install_dir/build"
|
||||
else
|
||||
ynh_setup_source --dest_dir="$install_dir" --keep="$install_dir/config.toml"
|
||||
fi
|
||||
ynh_setup_source --dest_dir="$install_dir" --keep="$install_dir/config.toml"
|
||||
|
||||
fi
|
||||
|
||||
chmod -R o-rwx "$install_dir"
|
||||
chown -R $app:www-data "$install_dir"
|
||||
chmod +x "$install_dir/listmonk"
|
||||
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
|
||||
|
||||
# Create a dedicated NGINX config
|
||||
ynh_add_nginx_config
|
||||
|
||||
#=================================================
|
||||
# DATABASE CONFIGURATION
|
||||
#=================================================
|
||||
|
@ -85,14 +55,12 @@ popd
|
|||
#=================================================
|
||||
ynh_script_progression --message="Upgrading systemd configuration..." --weight=2
|
||||
|
||||
# Create a dedicated NGINX config
|
||||
ynh_add_nginx_config
|
||||
|
||||
# Create a dedicated systemd config
|
||||
ynh_add_systemd_config
|
||||
|
||||
#=================================================
|
||||
# INTEGRATE SERVICE IN YUNOHOST
|
||||
#=================================================
|
||||
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
||||
|
||||
yunohost service add $app --description="Newsletter and mailing list manager" --log="/var/log/$app/$app.log"
|
||||
|
||||
#=================================================
|
||||
|
|
|
@ -1,245 +0,0 @@
|
|||
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 $install_dir/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 $install_dir
|
||||
$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 | grep -oP 'id: \K.*$')
|
||||
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
|
||||
}
|
Loading…
Reference in a new issue