1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/plume_ynh.git synced 2024-09-03 20:15:54 +02:00
plume_ynh/scripts/install
Éric Gaspar aaca75df11 fix
2023-06-02 11:59:58 +02:00

131 lines
4.1 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
admin_email=$(ynh_user_get_info $admin 'mail')
secret_key=$(ynh_string_random --length=32 | base64)
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..."
ynh_app_setting_set --app=$app --key=admin_email --value=$admin_email
ynh_app_setting_set --app=$app --key=secret_key --value=$secret_key
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..."
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir/$app"
# Create the media directory, where uploads will be stored
mkdir -p $install_dir/media
# Create the cargo directory
mkdir -p $install_dir/.cargo/bin
# Move binaries
mv $install_dir/$app/bin/* $install_dir/.cargo/bin/
chmod +x $install_dir/.cargo/bin/*
# Remove empty bin directory
ynh_secure_remove --file="$install_dir/$app/bin"
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:$app "$install_dir"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..."
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# SPECIFIC SETUP
#=================================================
# CREATE LOG FOLDER
#=================================================
mkdir -p "/var/log/$app"
chown -R "$app":"$app" "/var/log/$app"
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a config file..."
ynh_add_config --template="../conf/.env" --destination="$install_dir/$app/.env"
chmod 400 "$install_dir/$app/.env"
chown $app:$app "$install_dir/$app/.env"
#=================================================
# MAKE SETUP
#=================================================
ynh_script_progression --message="Making setup..."
# Set right permissions
chown -R "$app":"$app" $install_dir
export PATH="$PATH:$install_dir/.cargo/bin:$install_dir/.local/bin:/usr/local/sbin"
pushd $install_dir/$app
sudo -u "$app" env PATH=$PATH plm migration run
# Add new instance
if [ $registration -eq 1 ]
then
sudo -u "$app" env PATH=$PATH plm instance new --domain "$domain" --name "$name" -l 'CC-BY'
else
sudo -u "$app" env PATH=$PATH plm instance new --private --domain "$domain" --name "$name" -l 'CC-BY'
fi
# Add admin user
sudo -u "$app" env PATH=$PATH plm users new --admin -n "$admin" -N "$admin" --email "$admin_email" --password "$password"
# Initialise search index
sudo -u "$app" env PATH=$PATH plm search init -p $install_dir/$app
popd
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..."
# Create a dedicated systemd config
ynh_add_systemd_config
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
yunohost service add $app --description="$app daemon for Plume" --log="/var/log/$app/$app.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Started plume"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed"