1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/gitea_ynh.git synced 2024-09-03 20:36:22 +02:00
This commit is contained in:
Éric Gaspar 2022-07-23 00:32:56 +02:00
parent e7380aeebc
commit 836a6dd060
No known key found for this signature in database
GPG key ID: 574F281483054D44
8 changed files with 402 additions and 162 deletions

View file

@ -6,15 +6,14 @@ RUN_MODE = prod
[database] [database]
DB_TYPE = mysql DB_TYPE = mysql
HOST = 127.0.0.1:3306 HOST = 127.0.0.1:3306
NAME = __DB_USER__ NAME = __DB_NAME__
USER = __DB_USER__ USER = __DB_USER__
PASSWD = __DB_PASSWORD__ PASSWD = __DB_PWD__
SSL_MODE = disable SSL_MODE = disable
PATH = data/gitea.db
LOG_SQL = false LOG_SQL = false
[repository] [repository]
ROOT = __REPOS_PATH__ ROOT = __DATADIR__/repositories
FORCE_PRIVATE = false FORCE_PRIVATE = false
[server] [server]
@ -25,7 +24,7 @@ ROOT_URL = https://__DOMAIN____PATH_URL__
DISABLE_SSH = false DISABLE_SSH = false
SSH_PORT = __SSH_PORT__ SSH_PORT = __SSH_PORT__
OFFLINE_MODE = false OFFLINE_MODE = false
APP_DATA_PATH = __DATA_PATH__ APP_DATA_PATH = __DATADIR__
LANDING_PAGE = explore LANDING_PAGE = explore
LFS_START_SERVER = true LFS_START_SERVER = true
LFS_JWT_SECRET = __LFS_KEY__ LFS_JWT_SECRET = __LFS_KEY__
@ -46,10 +45,10 @@ ENABLE_REVERSE_PROXY_AUTHENTICATION = true
ENABLE_REVERSE_PROXY_AUTO_REGISTRATION = false ENABLE_REVERSE_PROXY_AUTO_REGISTRATION = false
[picture] [picture]
AVATAR_UPLOAD_PATH = __DATA_PATH__/avatars AVATAR_UPLOAD_PATH = __DATADIR_/data/avatars
[attachment] [attachment]
PATH = __DATA_PATH__/attachments PATH = __DATADIR__/data/attachments
[session] [session]
PROVIDER = memory PROVIDER = memory

View file

@ -2,15 +2,6 @@
# SET ALL CONSTANTS # SET ALL CONSTANTS
#================================================= #=================================================
app=$YNH_APP_INSTANCE_NAME
dbname=$app
db_user=$app
final_path="/opt/$app"
datadir="/home/yunohost.app/$app"
repos_path="$datadir/repositories"
data_path="$datadir/data"
ssh_path="$datadir/.ssh"
# Detect the system architecture to download the right tarball # Detect the system architecture to download the right tarball
# NOTE: `uname -m` is more accurate and universal than `arch` # NOTE: `uname -m` is more accurate and universal than `arch`
# See https://en.wikipedia.org/wiki/Uname # See https://en.wikipedia.org/wiki/Uname
@ -36,10 +27,10 @@ fi
create_dir() { create_dir() {
mkdir -p "$final_path/data" mkdir -p "$final_path/data"
mkdir -p "$final_path/custom/conf" mkdir -p "$final_path/custom/conf"
mkdir -p "$ssh_path" mkdir -p "$datadir/.ssh"
mkdir -p "$repos_path" mkdir -p "$datadir/repositories"
mkdir -p "$data_path/avatars" mkdir -p "$datadir/data/avatars"
mkdir -p "$data_path/attachments" mkdir -p "$datadir/data/attachments"
mkdir -p "/var/log/$app" mkdir -p "/var/log/$app"
} }

View file

@ -11,41 +11,79 @@ source ../settings/scripts/_common.sh
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
# Retrieve app settings #=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info --message="Loading installation settings..." ynh_print_info --message="Loading installation settings..."
domain=$(ynh_app_setting_get --app $app --key domain)
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
if [[ ! "$(systemctl status $app.service)" =~ "Active: inactive (dead)" ]]; then if [[ ! "$(systemctl status $app.service)" =~ "Active: inactive (dead)" ]]; then
ynh_print_warn --message="It's hightly recommended to make your backup when the service is stopped. Please stop $app service and with this command before to run the backup 'systemctl stop $app.service'" ynh_print_warn --message="It's hightly recommended to make your backup when the service is stopped. Please stop $app service and with this command before to run the backup 'systemctl stop $app.service'"
fi fi
#================================================= #=================================================
# STANDARD BACKUP STEPS # BACKUP THE APP MAIN DIR
#================================================= #=================================================
# Copy the app source files ynh_backup --src_path="$final_path"
ynh_print_info --message="Backing up code..."
ynh_backup --src_path "$final_path"
# Copy the data files #=================================================
ynh_print_info --message="Backing up user data..." # BACKUP THE DATA DIR
ynh_backup --src_path "$datadir" --is_big=1 #=================================================
ynh_print_info --message="Backing up configuration..." ynh_backup --src_path="$datadir" --is_big
# Copy the conf files #=================================================
ynh_backup --src_path "/etc/nginx/conf.d/${domain}.d/${app}.conf" # BACKUP THE NGINX CONFIGURATION
ynh_backup --src_path "/etc/systemd/system/${app}.service" #=================================================
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP SYSTEMD
#=================================================
ynh_backup --src_path="/etc/systemd/system/$app.service"
#=================================================
# BACKUP FAIL2BAN CONFIGURATION
#=================================================
ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf"
ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf"
#=================================================
# BACKUP VARIOUS FILES
#=================================================
# Backup logs
ynh_print_info --message="Backing up logs..."
ynh_backup --src_path "/var/log/$app" ynh_backup --src_path "/var/log/$app"
# Dump the database #=================================================
ynh_print_info --message="Backing up database" # BACKUP THE MYSQL DATABASE
ynh_mysql_dump_db "$dbname" > ./db.sql #=================================================
ynh_print_info --message="Backing up the MySQL database..."
ynh_mysql_dump_db --database="$db_name" > db.sql
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -14,53 +14,131 @@ source /usr/share/yunohost/helpers
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
ynh_script_progression --message="Loading installation settings..." #=================================================
# RETRIEVE ARGUMENTS # RETRIEVE ARGUMENTS
#=================================================
old_domain=$YNH_APP_OLD_DOMAIN old_domain=$YNH_APP_OLD_DOMAIN
domain=$YNH_APP_NEW_DOMAIN old_path=$YNH_APP_OLD_PATH
path_url=$(ynh_normalize_url_path --path_url ${YNH_APP_NEW_PATH:-'/'})
new_domain=$YNH_APP_NEW_DOMAIN
new_path=$YNH_APP_NEW_PATH
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
db_password=$(ynh_app_setting_get --app $app --key mysqlpwd) #=================================================
admin=$(ynh_app_setting_get --app $app --key adminusername) # LOAD SETTINGS
key=$(ynh_app_setting_get --app $app --key secret_key) #=================================================
lfs_key=$(ynh_app_setting_get --app $app --key lfs_key) ynh_script_progression --message="Loading installation settings..." --weight=1
port=$(ynh_app_setting_get --app $app --key web_port)
upstream_version=$(ynh_app_setting_get $app upstream_version) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
admin=$(ynh_app_setting_get --app=$app --key=adminusername)
key=$(ynh_app_setting_get --app=$app --key=secret_key)
lfs_key=$(ynh_app_setting_get --app=$app --key=lfs_key)
port=$(ynh_app_setting_get --app=$app --key=web_port)
upstream_version=$(ynh_app_setting_get --app=$app --key=upstream_version)
#=================================================
# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --time --weight=1
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
# Restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# CHECK WHICH PARTS SHOULD BE CHANGED
#=================================================
change_domain=0
if [ "$old_domain" != "$new_domain" ]
then
change_domain=1
fi
change_path=0
if [ "$old_path" != "$new_path" ]
then
change_path=1
fi
#================================================= #=================================================
# STANDARD MODIFICATIONS # STANDARD MODIFICATIONS
#================================================= #=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --time --weight=1
ynh_script_progression --message="Updating nginx configuration..." ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
#=================================================
# MODIFY URL IN NGINX CONF # MODIFY URL IN NGINX CONF
#=================================================
ynh_script_progression --message="Updating NGINX web server configuration..." --time --weight=1
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
# Change the domain for nginx # Change the path in the NGINX config file
# Change the domain for nginx if [ $change_path -eq 1 ]
if [[ "$old_domain" != "$domain" ]]; then then
# Delete file checksum for the old conf file location # Make a backup of the original NGINX config file if modified
ynh_delete_file_checksum --file "$nginx_conf_path" ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
mv $nginx_conf_path /etc/nginx/conf.d/$domain.d/$app.conf # Set global variables for NGINX helper
# Store file checksum for the new config file location domain="$old_domain"
ynh_store_file_checksum --file "/etc/nginx/conf.d/$domain.d/$app.conf" path_url="$new_path"
# Create a dedicated NGINX config
ynh_add_nginx_config
fi fi
config_nginx # Change the domain for NGINX
if [ $change_domain -eq 1 ]
then
# Delete file checksum for the old conf file location
ynh_delete_file_checksum --file="$nginx_conf_path"
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
# Store file checksum for the new config file location
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi
# Update gitea config #=================================================
# SPECIFIC MODIFICATIONS
#=================================================
ynh_script_progression --message="Updating gitea configuration..." ynh_script_progression --message="Updating gitea configuration..."
config_gitea
# RELOAD services config_gitea
ynh_script_progression --message="Starting services..."
ynh_systemd_action -l "Starting new Web server: tcp:127.0.0.1:" -p "/var/log/$app/gitea.log" -t 10 -a restart
sleep 1
# Store the checksum with the 'INTERNAL_TOKEN' value. # Store the checksum with the 'INTERNAL_TOKEN' value.
# Should be removed when the issue https://github.com/go-gitea/gitea/issues/3246 is fixed # Should be removed when the issue https://github.com/go-gitea/gitea/issues/3246 is fixed
ynh_store_file_checksum --file "$final_path/custom/conf/app.ini" ynh_store_file_checksum --file "$final_path/custom/conf/app.ini"
#=================================================
# GENERIC FINALISATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Starting new Web server: tcp:127.0.0.1:"
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Change of URL completed for $app" --last ynh_script_progression --message="Change of URL completed for $app" --last

View file

@ -3,6 +3,8 @@
#================================================= #=================================================
# GENERIC START # GENERIC START
#================================================= #=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Load common variables and helpers # Load common variables and helpers
source ./experimental_helper.sh source ./experimental_helper.sh
@ -11,27 +13,41 @@ source ./_common.sh
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
ynh_script_progression --message="Validating installation parameters..." #=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
# Retrieve arguments
domain=$YNH_APP_ARG_DOMAIN domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH path_url=$YNH_APP_ARG_PATH
admin=$YNH_APP_ARG_ADMIN admin=$YNH_APP_ARG_ADMIN
is_public=$YNH_APP_ARG_IS_PUBLIC is_public=$YNH_APP_ARG_IS_PUBLIC
upstream_version=$(ynh_app_upstream_version) upstream_version=$(ynh_app_upstream_version)
key=$(ynh_string_random)
lfs_key=$(ynh_string_random)
app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..." --time --weight=1
final_path=/opt/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
# Register (book) web path # Register (book) web path
ynh_webpath_register --app $app --domain $domain --path_url $path_url ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
# Check user parameter
ynh_user_exists "$admin" \
|| ynh_die --message "The chosen admin user does not exist."
# Check Final Path availability
test ! -e "$final_path" || ynh_die --message "This path already contains a folder"
if [ -e "$datadir" ]; then if [ -e "$datadir" ]; then
old_data_dir_path="$datadir$(date '+%Y%m%d.%H%M%S')" old_data_dir_path="$datadir$(date '+%Y%m%d.%H%M%S')"
@ -39,56 +55,107 @@ if [ -e "$datadir" ]; then
mv "$datadir" "$old_data_dir_path" mv "$datadir" "$old_data_dir_path"
fi fi
# Generate random password and key #=================================================
ynh_script_progression --message="Defining db password and key..." # STORE SETTINGS FROM MANIFEST
db_password=$(ynh_string_random) #=================================================
key=$(ynh_string_random) ynh_script_progression --message="Storing installation settings..." --weight=1
lfs_key=$(ynh_string_random)
# Find available ports ynh_app_setting_set --app=$app --key=adminusername --value=$admin
port=$(ynh_find_port --port 6000) ynh_app_setting_set --app=$app --key=secret_key --value=$key
ynh_app_setting_set --app=$app --key=lfs_key --value=$lfs_key
# Store Settings ynh_app_setting_set --app=$app --key=web_port --value=$port
ynh_script_progression --message="Storing installation settings..."
ynh_app_setting_set --app $app --key mysqlpwd --value $db_password
ynh_app_setting_set --app $app --key adminusername --value $admin
ynh_app_setting_set --app $app --key secret_key --value $key
ynh_app_setting_set --app $app --key lfs_key --value $lfs_key
ynh_app_setting_set --app $app --key web_port --value $port
#================================================= #=================================================
# STANDARD MODIFICATIONS # STANDARD MODIFICATIONS
#================================================= #=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Finding an available port..." --weight=1
# Initialize database and store mysql password for upgrade # Find an available port
ynh_script_progression --message="Configuring MySQL database..." port=$(ynh_find_port --port=6000)
ynh_mysql_create_db "$dbname" "$db_user" "$db_password" ynh_app_setting_set --app=$app --key=port --value=$port
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=1
# Add users
ynh_script_progression --message="Configuring system user..."
ynh_system_user_create --username=$app --home_dir=$datadir --use_shell ynh_system_user_create --username=$app --home_dir=$datadir --use_shell
# Add ssh permission for gitea user # Add ssh permission for gitea user
adduser $app ssh.app adduser $app ssh.app
# create needed directories #=================================================
create_dir # CREATE A MYSQL DATABASE
#=================================================
ynh_script_progression --message="Creating a MySQL database..." --weight=1
# Configure init script db_name=$(ynh_sanitize_dbid --db_name=$app)
ynh_script_progression --message="Configuring a systemd service..." --weight=2 db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --time --weight=1
### `ynh_setup_source` is used to install an app from a zip or tar.gz file,
### downloaded from an upstream source, like a git repository.
### `ynh_setup_source` use the file conf/app.src
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path" --source_id="../conf/source/$architecture"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --time --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# CREATE DATA DIRECTORY
#=================================================
ynh_script_progression --message="Creating a data directory..." --time --weight=1
datadir=/home/yunohost.app/$app
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
mkdir -p $datadir
chmod 750 "$datadir"
chmod -R o-rwx "$datadir"
chown -R $app:www-data "$datadir"
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=1
ssh_port=$(grep -P "Port\s+\d+" /etc/ssh/sshd_config | grep -P -o "\d+")
ynh_add_config --template="../conf/app.ini" --destination="$final_path/custom/conf/app.ini"
chmod 400 "$final_path/custom/conf/app.ini"
chown $app:$app "$final_path/custom/conf/app.ini"
# Store the checksum with the 'INTERNAL_TOKEN' value.
# Should be removed when the issue https://github.com/go-gitea/gitea/issues/3246 is fixed
ynh_store_file_checksum --file "$final_path/custom/conf/app.ini"
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..." --time --weight=1
# Create a dedicated systemd config
ynh_add_systemd_config ynh_add_systemd_config
# Modify Nginx configuration file and copy it to Nginx conf directory
ynh_script_progression --message="Configuring nginx..." --weight=1
config_nginx
# Configure gitea with app.ini file # create needed directories
ynh_script_progression --message="Configuring application, step 1/2..." create_dir
config_gitea
ynh_script_progression --message="Installing sources files..." --weight=10
# Install gitea
ynh_setup_source $final_path source/$architecture
# Set permissions # Set permissions
ynh_script_progression --message="Protecting directory" ynh_script_progression --message="Protecting directory"
@ -100,52 +167,73 @@ ynh_script_progression --message="Configuring application, step 2/2..."
systemctl start "$app".service systemctl start "$app".service
# Wait untill login_source mysql table is created # Wait untill login_source mysql table is created
while ! $(ynh_mysql_connect_as "$db_user" "$db_password" "$dbname" <<< "SELECT * FROM login_source;" &>/dev/null) while ! $(ynh_mysql_connect_as "$db_user" "$db_pwd" "$db_name" <<< "SELECT * FROM login_source;" &>/dev/null)
do do
sleep 2 sleep 2
done done
# Add ldap config # Add ldap config
ynh_replace_string --match_string "__APP__" --replace_string "$app" --target_file ../conf/login_source.sql ynh_replace_string --match_string "__APP__" --replace_string "$app" --target_file ../conf/login_source.sql
ynh_mysql_connect_as "$db_user" "$db_password" "$dbname" < ../conf/login_source.sql ynh_mysql_connect_as "$db_user" "$db_pwd" "$db_name" < ../conf/login_source.sql
# SETUP FAIL2BAN
ynh_script_progression --message="Configuring fail2ban..."
ynh_add_fail2ban_config --logpath "/var/log/$app/gitea.log" --failregex ".*Failed authentication attempt for .* from <HOST>" --max_retry 5
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#================================================= #=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Configuring log rotation..." --time --weight=1
# Unprotect root from SSO if public ynh_use_logrotate --logfile="/var/log/$app"
ynh_script_progression --message="Configuring permissions..."
if [ "$is_public" == '1' ];
then
ynh_permission_update --permission "main" --add "visitors"
fi
# Create permission
ynh_script_progression --message="Configuring permissions"
ynh_permission_create --permission="admin" --allowed=$admin
# Add gitea to YunoHost's monitored services
ynh_script_progression --message="Register gitea service..."
yunohost service add "$app" --log "/var/log/$app/gitea.log"
# Configure logrotate
ynh_script_progression --message="Configuring log rotation..."
ynh_use_logrotate --logfile "/var/log/$app"
# Save Version # Save Version
ynh_app_setting_set --app $app --key upstream_version --value $(ynh_app_upstream_version) ynh_app_setting_set --app $app --key upstream_version --value $(ynh_app_upstream_version)
# Reload services #=================================================
ynh_script_progression --message="Starting gitea services..." --weight=3 # INTEGRATE SERVICE IN YUNOHOST
ynh_systemd_action -l "Starting new Web server: tcp:127.0.0.1:" -p "/var/log/$app/gitea.log" -t 10 #=================================================
sleep 1 ynh_script_progression --message="Integrating service in YunoHost..." --time --weight=1
# Store the checksum with the 'INTERNAL_TOKEN' value. yunohost service add $app --description="A short description of the app" --log="/var/log/$app/$app.log"
# Should be removed when the issue https://github.com/go-gitea/gitea/issues/3246 is fixed
ynh_store_file_checksum --file "$final_path/custom/conf/app.ini"
ynh_script_progression --message="Installation of $app completed" --last #=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --time --weight=1
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Starting new Web server: tcp:127.0.0.1:"
#=================================================
# SETUP FAIL2BAN
#=================================================
ynh_script_progression --message="Configuring Fail2Ban..." --time --weight=1
ynh_add_fail2ban_config --logpath "/var/log/$app/gitea.log" --failregex ".*Failed authentication attempt for .* from <HOST>" --max_retry 5
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring permissions..." --time --weight=1
# Make app public if necessary
if [ $is_public -eq 1 ]
then
# Everyone can access the app.
# The "main" permission is automatically created before the install script.
ynh_permission_update --permission="main" --add="visitors"
fi
# Only the admin can access the admin panel of the app (if the app has an admin panel)
ynh_permission_create --permission="admin" --allowed=$admin
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --time --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --time --last

View file

@ -15,6 +15,8 @@ ynh_script_progression --message="Loading installation settings..."
# Retrieve domain from app settings # Retrieve domain from app settings
domain=$(ynh_app_setting_get --app $app --key domain) domain=$(ynh_app_setting_get --app $app --key domain)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
#================================================= #=================================================
# STANDARD REMOVE # STANDARD REMOVE
@ -24,10 +26,13 @@ domain=$(ynh_app_setting_get --app $app --key domain)
ynh_script_progression --message="Stoping services..." ynh_script_progression --message="Stoping services..."
systemctl stop "$app".service systemctl stop "$app".service
# Drop MySQL database and user #=================================================
ynh_script_progression --message="Removing databases..." # REMOVE THE MYSQL DATABASE
ynh_mysql_drop_db "$dbname" 2>/dev/null #=================================================
ynh_mysql_drop_user "$db_user" 2>/dev/null ynh_script_progression --message="Removing the MySQL database..." --weight=1
# Remove a database if it exists, along with the associated user
ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name
# Delete app directory and configurations # Delete app directory and configurations
ynh_script_progression --message="Removing code..." ynh_script_progression --message="Removing code..."

View file

@ -19,8 +19,9 @@ ynh_script_progression --message="Loading settings..."
# Retrieve old app settings # Retrieve old app settings
domain=$(ynh_app_setting_get --app $app --key domain) domain=$(ynh_app_setting_get --app $app --key domain)
path_url=$(ynh_app_setting_get --app $app --key path) path_url=$(ynh_app_setting_get --app $app --key path)
db_password=$(ynh_app_setting_get --app $app --key mysqlpwd)
admin=$(ynh_app_setting_get --app $app --key adminusername) admin=$(ynh_app_setting_get --app $app --key adminusername)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
port=$(ynh_app_setting_get --app $app --key web_port) port=$(ynh_app_setting_get --app $app --key web_port)
upstream_version=$(ynh_app_setting_get $app upstream_version) upstream_version=$(ynh_app_setting_get $app upstream_version)
@ -43,10 +44,14 @@ ynh_system_user_create --username=$app --home_dir=$datadir --use_shell
ynh_script_progression --message="Restoring files..." --weight=10 ynh_script_progression --message="Restoring files..." --weight=10
ynh_restore ynh_restore
# Create and restore the database #=================================================
ynh_script_progression --message="Restoring database..." --weight=3 # RESTORE THE MYSQL DATABASE
ynh_mysql_create_db "$dbname" "$db_user" "$db_password" #=================================================
ynh_mysql_connect_as "$db_user" "$db_password" "$dbname" < ./db.sql ynh_script_progression --message="Restoring the MySQL database..." --weight=1
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
# Restore systemd files # Restore systemd files
systemctl daemon-reload systemctl daemon-reload

View file

@ -16,14 +16,17 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_normalize_url_path --path_url $(ynh_app_setting_get --app $app --key path)) path_url=$(ynh_app_setting_get --app=$app --key=path)
db_password=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
admin=$(ynh_app_setting_get --app=$app --key=adminusername) admin=$(ynh_app_setting_get --app=$app --key=adminusername)
key=$(ynh_app_setting_get --app=$app --key=secret_key) key=$(ynh_app_setting_get --app=$app --key=secret_key)
lfs_key=$(ynh_app_setting_get --app=$app --key=lfs_key) lfs_key=$(ynh_app_setting_get --app=$app --key=lfs_key)
port=$(ynh_app_setting_get --app=$app --key=web_port) port=$(ynh_app_setting_get --app=$app --key=web_port)
upstream_version=$(ynh_app_setting_get --app=$app --key=upstream_version) upstream_version=$(ynh_app_setting_get --app=$app --key=upstream_version)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_password=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
#================================================= #=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
@ -56,12 +59,30 @@ ynh_systemd_action --service_name=$app --action="stop"
#================================================= #=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
# If db_name doesn't exist, create it
if [ -z "$db_name" ]; then
db_name=$(ynh_sanitize_dbid --db_name=$app)
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
fi
# If lfs_key doesn't exist, create it # If lfs_key doesn't exist, create it
if [ -z "$lfs_key" ]; then if [ -z "$lfs_key" ]; then
lfs_key=$(ynh_string_random) lfs_key=$(ynh_string_random)
ynh_app_setting_set --app=$app --key=lfs_key --value=$lfs_key ynh_app_setting_set --app=$app --key=lfs_key --value=$lfs_key
fi fi
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
ynh_app_setting_delete --app=$app --key=is_public
fi
if ! ynh_permission_exists --permission="admin"; then
# Create the required permissions
ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin
fi
#================================================= #=================================================
# MIGRATION FROM GOGS # MIGRATION FROM GOGS
#================================================= #=================================================
@ -123,13 +144,21 @@ ynh_secure_remove --file="/opt/$app/templates"
# Configure gitea with app.ini file # Configure gitea with app.ini file
config_gitea config_gitea
# Configure init script #=================================================
ynh_script_progression --message="Updating systemd units..." # NGINX CONFIGURATION
ynh_add_systemd_config #=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --time --weight=1
# Modify Nginx configuration file and copy it to Nginx conf directory # Create a dedicated NGINX config
ynh_script_progression --message="Configuring nginx..." --weight=1 ynh_add_nginx_config
config_nginx
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Upgrading systemd configuration..." --time --weight=1
# Create a dedicated systemd config
ynh_add_systemd_config
#================================================= #=================================================
# DB migration # DB migration
@ -263,10 +292,13 @@ set_permission
# Save Version # Save Version
ynh_app_setting_set --app $app --key upstream_version --value $(ynh_app_upstream_version) ynh_app_setting_set --app $app --key upstream_version --value $(ynh_app_upstream_version)
# Reload services #=================================================
ynh_script_progression --message="Starting gitea services..." --weight=3 # START SYSTEMD SERVICE
ynh_systemd_action -l "Starting new Web server: tcp:127.0.0.1:" -p "/var/log/$app/gitea.log" -t 10 #=================================================
sleep 1 ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Starting new Web server: tcp:127.0.0.1:"
# Store the checksum with the 'INTERNAL_TOKEN' value. # Store the checksum with the 'INTERNAL_TOKEN' value.
# Should be removed when the issue https://github.com/go-gitea/gitea/issues/3246 is fixed # Should be removed when the issue https://github.com/go-gitea/gitea/issues/3246 is fixed
@ -292,4 +324,8 @@ you don't see Gogs as installed." >&2
(cd /tmp; echo "/tmp/$script_post_migration > /tmp/$script_post_migration.log 2>&1" | at now + 2 minutes) (cd /tmp; echo "/tmp/$script_post_migration > /tmp/$script_post_migration.log 2>&1" | at now + 2 minutes)
fi fi
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last ynh_script_progression --message="Upgrade of $app completed" --last