1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/glitchsoc_ynh.git synced 2024-09-03 19:15:59 +02:00

update install

This commit is contained in:
yalh76 2019-03-19 23:33:34 +01:00
parent 4a75d7c713
commit 3eee0a24e2
2 changed files with 160 additions and 28 deletions

View file

@ -8,6 +8,7 @@
source _common.sh
source /usr/share/yunohost/helpers
source ynh_install_ruby
#=================================================
# MANAGE SCRIPT FAILURE
@ -149,32 +150,14 @@ chown -R "$app": "$final_path"
#=================================================
# SPECIFIC SETUP
#=================================================
# ...
# INSTALLING RUBY
#=================================================
# TODO: try to use ynh_install_ruby from https://github.com/YunoHost-Apps/Experimental_helpers
# Install de rbenv
(
cd $final_path/.rbenv
src/configure && make -C src
ynh_install_ruby --ruby_version=2.6.0
echo "export PATH=\"$final_path/.rbenv/bin:$final_path/live/bin:\$PATH\"
eval \"\$(rbenv init -)\"" > $final_path/.profile
echo "export PATH=\"$final_path/.rbenv/bin:$final_path/live/bin:\$PATH\"" > $final_path/.bashrc
)
# Install ruby-build
(
exec_as "$app" $final_path/.rbenv/bin/rbenv install 2.6.0 || true
exec_as "$app" $final_path/.rbenv/bin/rbenv global 2.6.0 || true
exec_as "$app" $final_path/.rbenv/versions/2.6.0/bin/ruby -v
)
# Create symlink for ruby
rm /usr/bin/ruby || true
ln -s $final_path/.rbenv/versions/2.6.0/bin/ruby /usr/bin/ruby || true
# Adjust Mastodon config
#=================================================
# MODIFY A CONFIG FILE
#=================================================
cp -a $final_path/live/.env.production.sample $final_path/live/.env.production
ynh_replace_string "REDIS_HOST=redis" "REDIS_HOST=127.0.0.1" "${final_path}/live/.env.production"
@ -202,16 +185,25 @@ ynh_replace_string "SMTP_FROM_ADDRESS=notifications@example.com" "SMTP_FROM_ADDR
ynh_replace_string "#SMTP_AUTH_METHOD=plain" "SMTP_AUTH_METHOD=none" "${final_path}/live/.env.production"
ynh_replace_string "#SMTP_OPENSSL_VERIFY_MODE=peer" "SMTP_OPENSSL_VERIFY_MODE=none" "${final_path}/live/.env.production"
# Preconfig CSS & JS
# Install Mastodon
# Give right permission for the app
#=================================================
# STORE THE CONFIG FILE CHECKSUM
#=================================================
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "${final_path}/live/.env.production"
#=================================================
# INSTALLING MASTODON
#=================================================
ynh_print_info "Installing Mastodon..."
chown -R "$app": "$final_path"
(
cd "$final_path/live"
su mastodon <<INSTALL
$final_path/.rbenv/versions/2.6.0/bin/gem install bundler:1.16.6 --no-ri --no-rdoc
$final_path/.rbenv/versions/2.6.0/bin/gem install bundler
$final_path/.rbenv/versions/2.6.0/bin/gem update --system
$final_path/.rbenv/versions/2.6.0/bin/gem install bundler --no-document
$final_path/.rbenv/versions/2.6.0/bin/bundle install \
-j$(getconf _NPROCESSORS_ONLN) \
--deployment --without development test

140
scripts/ynh_install_ruby Normal file
View file

@ -0,0 +1,140 @@
#!/bin/bash
# Need also the helper https://github.com/YunoHost-Apps/Experimental_helpers/blob/master/ynh_handle_getopts_args/ynh_handle_getopts_args
rbenv_install_dir="/opt/rbenv"
# RBENV_ROOT is the directory of rbenv, it needs to be loaded as a environment variable.
export RBENV_ROOT="$rbenv_install_dir"
# Install ruby version management
#
# [internal]
#
# usage: ynh_install_rbenv
ynh_install_rbenv () {
echo "Installation of rbenv - ruby version management" >&2
# Build an app.src for rbenv
mkdir -p "../conf"
echo "SOURCE_URL=https://github.com/rbenv/rbenv/archive/v1.1.1.tar.gz
SOURCE_SUM=41f1a60714c55eceb21d692a469aee1ec4f46bba351d0dfcb0c660ff9cf1a1c9" > "../conf/rbenv.src"
# Download and extract rbenv
ynh_setup_source "$rbenv_install_dir" rbenv
# Build an app.src for ruby-build
mkdir -p "../conf"
echo "SOURCE_URL=https://github.com/rbenv/ruby-build/archive/v20180329.tar.gz
SOURCE_SUM=4c8610c178ef2fa6bb29d4bcfca52608914632a51a56a5e70aeec8bf0894167b" > "../conf/ruby-build.src"
# Download and extract ruby-build
ynh_setup_source "$rbenv_install_dir/plugins/ruby-build" ruby-build
(cd $rbenv_install_dir
./src/configure && make -C src)
# Create shims directory if needed
if [ ! -d $rbenv_install_dir/shims ] ; then
mkdir $rbenv_install_dir/shims
fi
}
# Install a specific version of ruby
#
# ynh_install_ruby will install the version of ruby provided as argument by using rbenv.
#
# rbenv (ruby version management) stores the target ruby version in a .ruby_version file created in the target folder (using rbenv local <version>)
# It then uses that information for every ruby user that uses rbenv provided ruby command
#
# This helper creates a /etc/profile.d/rbenv.sh that configures PATH environment for rbenv
# for every LOGIN user, hence your user must have a defined shell (as opposed to /usr/sbin/nologin)
#
# Don't forget to execute ruby-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 rbenv shims (e.g. $RBENV_ROOT/shims/bundle)
#
# usage: ynh_install_ruby ruby_version user
# | arg: -v, --ruby_version= - Version of ruby to install.
# If possible, prefer to use major version number (e.g. 8 instead of 8.10.0).
# The crontab will handle the update of minor versions when needed.
ynh_install_ruby () {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [v]=ruby_version= )
# Use rbenv, https://github.com/rbenv/rbenv to manage the ruby versions
local ruby_version
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
# Create $rbenv_install_dir
mkdir -p "$rbenv_install_dir/plugins/ruby-build"
# Load rbenv path in PATH
CLEAR_PATH="$rbenv_install_dir/bin:$PATH"
# Remove /usr/local/bin in PATH in case of ruby prior installation
PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
# Move an existing ruby binary, to avoid to block rbenv
test -x /usr/bin/ruby && mv /usr/bin/ruby /usr/bin/ruby_rbenv
# If rbenv is not previously setup, install it
if ! type rbenv > /dev/null 2>&1
then
ynh_install_rbenv
fi
# Restore /usr/local/bin in PATH (if needed)
PATH=$CLEAR_PATH
# And replace the old ruby binary
test -x /usr/bin/ruby_rbenv && mv /usr/bin/ruby_rbenv /usr/bin/ruby
# Install the requested version of ruby
CONFIGURE_OPTS="--disable-install-doc" MAKE_OPTS="-j2" rbenv install --skip-existing $ruby_version
# Store the ID of this app and the version of ruby requested for it
echo "$YNH_APP_ID:$ruby_version" | tee --append "$rbenv_install_dir/ynh_app_version"
# Store ruby_version into the config of this app
ynh_app_setting_set $app ruby_version $ruby_version
# Set environment for ruby users
echo "#rbenv
export RBENV_ROOT=$rbenv_install_dir
export PATH=\"$rbenv_install_dir/bin:$PATH\"
eval \"\$(rbenv init -)\"
#rbenv" > /etc/profile.d/rbenv.sh
# Load the right environment for the Installation
eval "$(rbenv init -)"
(cd $final_path
rbenv local $ruby_version)
}
# Remove the version of ruby used by the app.
#
# This helper will check if another app uses the same version of ruby,
# if not, this version of ruby will be removed.
# If no other app uses ruby, rbenv will be also removed.
#
# usage: ynh_remove_ruby
ynh_remove_ruby () {
ruby_version=$(ynh_app_setting_get $app ruby_version)
# Remove the line for this app
sed --in-place "/$YNH_APP_ID:$ruby_version/d" "$rbenv_install_dir/ynh_app_version"
# If no other app uses this version of ruby, remove it.
if ! grep --quiet "$ruby_version" "$rbenv_install_dir/ynh_app_version"
then
$rbenv_install_dir/bin/rbenv uninstall --force $ruby_version
fi
# Remove rbenv environment configuration
rm /etc/profile.d/rbenv.sh
# If no other app uses rbenv, remove rbenv and dedicated group
if [ ! -s "$rbenv_install_dir/ynh_app_version" ]
then
ynh_secure_remove "$rbenv_install_dir"
fi
}