-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Download sources during installation and upgrade to 1.0.36 #38
Changes from 2 commits
5eadb53
6e4f673
01f5b2a
9750280
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# | ||
# Common variables | ||
# | ||
|
||
# Application version | ||
VERSION="1.0.36" | ||
|
||
# Remote URL to fetch application source tarball | ||
APPLICATION_SOURCE_URL="https://github.com/kanboard/kanboard/archive/v${VERSION}.tar.gz" | ||
|
||
# | ||
# Common helpers | ||
# | ||
|
||
# Download and extract application sources to the given directory | ||
# usage: extract_application_to DESTDIR | ||
extract_application() { | ||
local DESTDIR=$1 | ||
rc_tarball="${DESTDIR}/application.tar.gz" | ||
wget -q -O "$rc_tarball" "$APPLICATION_SOURCE_URL" \ | ||
|| ynh_die "Unable to download application tarball" | ||
tar xf "$rc_tarball" -C "$DESTDIR" --strip-components 1 \ | ||
|| ynh_die "Unable to extract application tarball" | ||
rm "$rc_tarball" | ||
} | ||
|
||
# Execute a command as another user | ||
# usage: exec_as USER COMMAND [ARG ...] | ||
exec_as() { | ||
local USER=$1 | ||
shift 1 | ||
|
||
if [[ $USER = $(whoami) ]]; then | ||
eval $@ | ||
else | ||
# use sudo twice to be root and be allowed to use another user | ||
sudo sudo -u "$USER" $@ | ||
fi | ||
} | ||
|
||
# Execute a composer command from a given directory | ||
# usage: composer_exec AS_USER WORKDIR COMMAND [ARG ...] | ||
exec_composer() { | ||
local AS_USER=$1 | ||
local WORKDIR=$2 | ||
shift 2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shift is useless here |
||
|
||
exec_as "$AS_USER" COMPOSER_HOME="${WORKDIR}/.composer" \ | ||
php "${WORKDIR}/composer.phar" $@ \ | ||
-d "${WORKDIR}" --quiet --no-interaction | ||
} | ||
|
||
# Install and initialize Composer in the given directory | ||
# usage: init_composer DESTDIR [AS_USER] | ||
init_composer() { | ||
local DESTDIR=$1 | ||
local AS_USER=${2:-admin} | ||
|
||
# install composer | ||
curl -sS https://getcomposer.org/installer \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not the best way to install composer, the composer website provide a way more secure script here: https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md |
||
| exec_as "$AS_USER" COMPOSER_HOME="${DESTDIR}/.composer" \ | ||
php -- --quiet --install-dir="$DESTDIR" \ | ||
|| ynh_die "Unable to install Composer" | ||
|
||
# update dependencies to create composer.lock | ||
exec_composer "$AS_USER" "$DESTDIR" install --no-dev \ | ||
|| ynh_die "Unable to update application core dependencies" | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think exec_composer and init_composer function should be merged since:
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,9 @@ set -eu | |
|
||
app="kanboard" | ||
|
||
# Source local helpers | ||
source ./_common.sh | ||
|
||
# Source app helpers | ||
source /usr/share/yunohost/helpers | ||
|
||
|
@@ -42,9 +45,12 @@ ynh_app_setting_set $app mysqlpwd $dbpass | |
ynh_app_setting_set $app adminusername $admin | ||
ynh_app_setting_set $app is_public $is_public | ||
|
||
# Copy sources | ||
sudo mkdir -p $DESTDIR | ||
sudo cp -a ../sources/. $DESTDIR | ||
# Create tmp directory and install app inside | ||
TMPDIR=$(ynh_mkdir_tmp) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is deprecated, use mktemp since it's bash native. |
||
extract_application "$TMPDIR" | ||
init_composer "$TMPDIR" | ||
|
||
sudo mv "$TMPDIR" "$DESTDIR" | ||
|
||
# Copy and edit config.php | ||
sudo cp ../conf/config.php ${DESTDIR} | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so over-engineered IMO. This complicate the script for exactly no gain, the whole script is run as "admin" user by YunoHost and this is used only to run thing as admin. Plus I don't think apps script should contain such generic helper, if one is really needed it should be in yunohost core.