Skip to content
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

Merged
merged 4 commits into from
Jan 17, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ From command line:

Infos
-----
Kanboard v1.0.31
Kanboard v1.0.35

Yunohost forum thread: <https://forum.yunohost.org/t/kanboard-package/78>

Expand Down
31 changes: 27 additions & 4 deletions conf/config.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
<?php

// Data folder (must be writeable by the web server user)
define('DATA_DIR', 'data');

// Enable/Disable debug
define('DEBUG', false);

// Available log drivers: syslog, stderr, stdout or file
define('LOG_DRIVER', '');

// Log filename if the log driver is "file"
define('LOG_FILE', __DIR__.DIRECTORY_SEPARATOR.'data'.DIRECTORY_SEPARATOR.'debug.log');
define('LOG_FILE', DATA_DIR.DIRECTORY_SEPARATOR.'debug.log');

// Plugins directory
define('PLUGINS_DIR', 'plugins');

// Folder for uploaded files
define('FILES_DIR', 'data'.DIRECTORY_SEPARATOR.'files');
// Plugins directory URL
define('PLUGIN_API_URL', 'https://kanboard.net/plugins.json');

// Enable/Disable plugin installer
define('PLUGIN_INSTALLER', true);

// Available cache drivers are "file" and "memory"
define('CACHE_DRIVER', 'memory');

// Cache folder to use if cache driver is "file" (must be writeable by the web server user)
define('CACHE_DIR', DATA_DIR.DIRECTORY_SEPARATOR.'cache');

// Folder for uploaded files (must be writeable by the web server user)
define('FILES_DIR', DATA_DIR.DIRECTORY_SEPARATOR.'files');

// E-mail address for the "From" header (notifications)
define('MAIL_FROM', 'yuno_email');
Expand All @@ -31,6 +46,11 @@
// Sendmail command to use when the transport is "sendmail"
define('MAIL_SENDMAIL_COMMAND', '/usr/sbin/sendmail -bs');

// Run automatically database migrations
// If set to false, you will have to run manually the SQL migrations from the CLI during the next Kanboard upgrade
// Do not run the migrations from multiple processes at the same time (example: web page + background worker)
define('DB_RUN_MIGRATIONS', true);

// Database driver: sqlite, mysql or postgres (sqlite by default)
define('DB_DRIVER', 'mysql');

Expand Down Expand Up @@ -183,7 +203,7 @@
// Hide login form, useful if all your users use Google/Github/ReverseProxy authentication
define('HIDE_LOGIN_FORM', true);

// Disabling logout (for external SSO authentication)
// Disabling logout (useful for external SSO authentication)
define('DISABLE_LOGOUT', true);

// Enable captcha after 3 authentication failure
Expand All @@ -204,3 +224,6 @@
define('HTTP_PROXY_PORT', '3128');
define('HTTP_PROXY_USERNAME', '');
define('HTTP_PROXY_PASSWORD', '');

// TOTP (2FA) issuer name
define('TOTP_ISSUER', 'Kanboard');
68 changes: 68 additions & 0 deletions scripts/_common.sh
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
}

Copy link
Contributor

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.

# 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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 \
Copy link
Contributor

Choose a reason for hiding this comment

The 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"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think exec_composer and init_composer function should be merged since:

  • they are never called independently
  • they can be simplified by removing all the exec_as thing

12 changes: 9 additions & 3 deletions scripts/install
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ set -eu

app="kanboard"

# Source local helpers
source ./_common.sh

# Source app helpers
source /usr/share/yunohost/helpers

Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The 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}
Expand Down
13 changes: 11 additions & 2 deletions scripts/upgrade
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ set -eu

app="kanboard"

# Source local helpers
source ./_common.sh

# Set app specific variables
dbname=$app
dbuser=$app
Expand Down Expand Up @@ -36,10 +39,16 @@ sudo rm -rf /var/lib/php5/session/*
# Move old app dir
sudo mv ${DESTDIR} ${DESTDIR}.old

sudo mkdir -p ${DESTDIR}
sudo cp -a ../sources/. ${DESTDIR}
# Create tmp directory and install app inside
TMPDIR=$(ynh_mkdir_tmp)
extract_application "$TMPDIR"
init_composer "$TMPDIR"

sudo mv "$TMPDIR" "$DESTDIR"

# restore data
sudo cp -a ${DESTDIR}.old/data ${DESTDIR}

# restore plugins
if [ -e ${DESTDIR}.old/plugins ]
then
Expand Down
26 changes: 0 additions & 26 deletions sources/.htaccess

This file was deleted.