2016-12-14 10:55:15 +01:00
|
|
|
#
|
|
|
|
# Common variables
|
|
|
|
#
|
|
|
|
|
|
|
|
APPNAME="odoo"
|
|
|
|
|
|
|
|
|
|
|
|
# Package name for dependencies
|
|
|
|
DEPS_PKG_NAME="${APPNAME}-deps"
|
|
|
|
|
|
|
|
# Remote URL to fetch tarball
|
|
|
|
SOURCE_URL="http://download.gna.org/wkhtmltopdf/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz"
|
|
|
|
|
|
|
|
# Remote URL to fetch tarball checksum
|
|
|
|
SOURCE_SHA256="049b2cdec9a8254f0ef8ac273afaf54f7e25459a273e27189591edc7d7cf29db"
|
|
|
|
|
|
|
|
# App package root directory should be the parent folder
|
|
|
|
PKGDIR=$(cd ../; pwd)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Common helpers
|
|
|
|
#
|
|
|
|
|
2016-12-14 13:15:34 +01:00
|
|
|
# # Execute a command as root user
|
|
|
|
#
|
|
|
|
# usage: ynh_psql_execute_as_root sql [db]
|
|
|
|
# | arg: sql - the SQL command to execute
|
|
|
|
# | arg: db - the database to connect to
|
|
|
|
ynh_psql_execute_as_root () {
|
2016-12-14 13:44:39 +01:00
|
|
|
sudo su -c "psql" - postgres <<< ${1}
|
2016-12-14 13:15:34 +01:00
|
|
|
}
|
|
|
|
|
2016-12-14 10:55:15 +01:00
|
|
|
# Create a user
|
|
|
|
#
|
2016-12-14 13:15:34 +01:00
|
|
|
# usage: ynh_psql_create_user user pwd [host]
|
2016-12-14 10:55:15 +01:00
|
|
|
# | arg: user - the user name to create
|
|
|
|
# | arg: pwd - the password to identify user by
|
|
|
|
ynh_psql_create_user() {
|
2016-12-14 13:15:34 +01:00
|
|
|
ynh_psql_execute_as_root \
|
2016-12-14 10:55:15 +01:00
|
|
|
"CREATE USER ${1} WITH PASSWORD '${2}';"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Create a database and grant optionnaly privilegies to a user
|
|
|
|
#
|
2016-12-14 13:15:34 +01:00
|
|
|
# usage: ynh_psql_create_db db [user [pwd]]
|
2016-12-14 10:55:15 +01:00
|
|
|
# | arg: db - the database name to create
|
|
|
|
# | arg: user - the user to grant privilegies
|
|
|
|
# | arg: pwd - the password to identify user by
|
|
|
|
ynh_psql_create_db() {
|
|
|
|
db=$1
|
|
|
|
# grant all privilegies to user
|
|
|
|
if [[ $# -gt 1 ]]; then
|
|
|
|
ynh_psql_create_user ${2} "${3}"
|
2016-12-14 13:44:39 +01:00
|
|
|
sudo su -c "createdb -O ${2} $db" - postgres
|
2016-12-14 10:55:15 +01:00
|
|
|
else
|
2016-12-14 13:44:39 +01:00
|
|
|
sudo su -c "createdb $db" - postgres
|
2016-12-14 10:55:15 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
# Drop a database
|
|
|
|
#
|
2016-12-14 13:15:34 +01:00
|
|
|
# usage: ynh_psql_drop_db db
|
2016-12-14 10:55:15 +01:00
|
|
|
# | arg: db - the database name to drop
|
|
|
|
ynh_psql_drop_db() {
|
2016-12-14 13:44:39 +01:00
|
|
|
sudo su -c "dropdb ${1}" - postgres
|
2016-12-14 10:55:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Drop a user
|
|
|
|
#
|
2016-12-14 13:15:34 +01:00
|
|
|
# usage: ynh_psql_drop_user user
|
2016-12-14 10:55:15 +01:00
|
|
|
# | arg: user - the user name to drop
|
|
|
|
ynh_psql_drop_user() {
|
2016-12-14 13:44:39 +01:00
|
|
|
sudo su -c "dropuser ${1}" - postgres
|
2016-12-14 10:55:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Download and extract sources to the given directory
|
|
|
|
# usage: extract_sources DESTDIR [AS_USER]
|
|
|
|
extract_sources() {
|
|
|
|
local DESTDIR=$1
|
|
|
|
local AS_USER=${2:-admin}
|
|
|
|
|
|
|
|
# retrieve and extract Roundcube tarball
|
2016-12-14 11:06:30 +01:00
|
|
|
tarball="/tmp/${APPNAME}.tar.xz"
|
2016-12-14 10:55:15 +01:00
|
|
|
rm -f "$tarball"
|
|
|
|
wget -q -O "$tarball" "$SOURCE_URL" \
|
|
|
|
|| ynh_die "Unable to download tarball"
|
|
|
|
echo "$SOURCE_SHA256 $tarball" | sha256sum -c >/dev/null \
|
|
|
|
|| ynh_die "Invalid checksum of downloaded tarball"
|
2016-12-14 11:06:30 +01:00
|
|
|
exec_as "$AS_USER" tar xJf "$tarball" -C "$DESTDIR" --strip-components 1 \
|
2016-12-14 10:55:15 +01:00
|
|
|
|| ynh_die "Unable to extract tarball"
|
|
|
|
rm -f "$tarball"
|
|
|
|
|
|
|
|
# apply patches
|
2016-12-14 12:29:02 +01:00
|
|
|
if [[ -d "${PKGDIR}/patches" ]]; then
|
|
|
|
(cd "$DESTDIR" \
|
|
|
|
&& for p in ${PKGDIR}/patches/*.patch; do \
|
|
|
|
exec_as "$AS_USER" patch -p1 < $p; done) \
|
|
|
|
|| ynh_die "Unable to apply patches"
|
|
|
|
fi
|
2016-12-14 10:55:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# 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
|
|
|
|
}
|