mirror of
https://github.com/YunoHost-Apps/lufi_ynh.git
synced 2024-09-03 19:36:28 +02:00
Fix upgrade from the old version
This commit is contained in:
parent
baf6a3aaa8
commit
25d73a472c
7 changed files with 43 additions and 11 deletions
|
@ -117,7 +117,7 @@
|
||||||
# choose what database you want to use
|
# choose what database you want to use
|
||||||
# valid choices are sqlite, postgresql and mysql (all lowercase)
|
# valid choices are sqlite, postgresql and mysql (all lowercase)
|
||||||
# optional, default is sqlite
|
# optional, default is sqlite
|
||||||
dbtype => 'postgresql',
|
dbtype => '__DB_MANAGER__',
|
||||||
|
|
||||||
# SQLite ONLY - only used if dbtype is set to sqlite
|
# SQLite ONLY - only used if dbtype is set to sqlite
|
||||||
# define a path to the SQLite database
|
# define a path to the SQLite database
|
||||||
|
|
|
@ -30,6 +30,7 @@ app=$YNH_APP_INSTANCE_NAME
|
||||||
final_path=$(ynh_app_setting_get $app final_path)
|
final_path=$(ynh_app_setting_get $app final_path)
|
||||||
domain=$(ynh_app_setting_get $app domain)
|
domain=$(ynh_app_setting_get $app domain)
|
||||||
db_name=$(ynh_app_setting_get $app db_name)
|
db_name=$(ynh_app_setting_get $app db_name)
|
||||||
|
db_manager=$(ynh_app_setting_get $app db_manager)
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# STANDARD BACKUP STEPS
|
# STANDARD BACKUP STEPS
|
||||||
|
@ -52,7 +53,9 @@ ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_print_info "Backing up the PostgreSQL database..."
|
ynh_print_info "Backing up the PostgreSQL database..."
|
||||||
|
|
||||||
|
if [ $db_manager = "postgresql" ]; then
|
||||||
ynh_psql_dump_db "$db_name" > db.sql
|
ynh_psql_dump_db "$db_name" > db.sql
|
||||||
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC BACKUP
|
# SPECIFIC BACKUP
|
||||||
|
|
|
@ -37,6 +37,7 @@ db_pwd=$(ynh_app_setting_get $app psqlpwd)
|
||||||
db_user=$db_name
|
db_user=$db_name
|
||||||
secret=$(ynh_app_setting_get $app secret)
|
secret=$(ynh_app_setting_get $app secret)
|
||||||
max_file_size=$(ynh_app_setting_get $app max_file_size)
|
max_file_size=$(ynh_app_setting_get $app max_file_size)
|
||||||
|
db_manager=$(ynh_app_setting_get $app db_manager)
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CHECK THE SYNTAX OF THE PATHS
|
# CHECK THE SYNTAX OF THE PATHS
|
||||||
|
@ -112,6 +113,7 @@ ynh_replace_string "__DB_NAME__" "$db_name" "${final_path}/lufi.conf"
|
||||||
ynh_replace_string "__DB_USER__" "$db_user" "${final_path}/lufi.conf"
|
ynh_replace_string "__DB_USER__" "$db_user" "${final_path}/lufi.conf"
|
||||||
ynh_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lufi.conf"
|
ynh_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lufi.conf"
|
||||||
ynh_replace_string "__MAX_FILE_SIZE__" "$max_file_size" "${final_path}/lufi.conf"
|
ynh_replace_string "__MAX_FILE_SIZE__" "$max_file_size" "${final_path}/lufi.conf"
|
||||||
|
ynh_replace_string "__DB_MANAGER__" "$db_manager" "${final_path}/lufi.conf"
|
||||||
if [ $max_file_size -eq 0 ]; then # Comment the limitation line if no limit
|
if [ $max_file_size -eq 0 ]; then # Comment the limitation line if no limit
|
||||||
ynh_replace_string "max_file_size" "#max_file_size" "${final_path}/lufi.conf"
|
ynh_replace_string "max_file_size" "#max_file_size" "${final_path}/lufi.conf"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -48,6 +48,9 @@ if ! [[ $max_file_size =~ "^[\-0-9]+$" ]] && [ $max_file_size -lt 0 ]; then
|
||||||
ynh_die "Max file must be a number positive or zero"
|
ynh_die "Max file must be a number positive or zero"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Use postgresql by default
|
||||||
|
db_manager="postgresql"
|
||||||
|
|
||||||
# Check web path availability
|
# Check web path availability
|
||||||
ynh_webpath_available $domain $path_url
|
ynh_webpath_available $domain $path_url
|
||||||
# Register (book) web path
|
# Register (book) web path
|
||||||
|
@ -73,6 +76,7 @@ ynh_app_setting_set $app is_public $is_public
|
||||||
ynh_app_setting_set $app port $port
|
ynh_app_setting_set $app port $port
|
||||||
ynh_app_setting_set $app path $path_url
|
ynh_app_setting_set $app path $path_url
|
||||||
ynh_app_setting_set $app max_file_size $max_file_size
|
ynh_app_setting_set $app max_file_size $max_file_size
|
||||||
|
ynh_app_setting_set $app db_manager $db_manager
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# STANDARD MODIFICATIONS
|
# STANDARD MODIFICATIONS
|
||||||
|
@ -137,6 +141,7 @@ ynh_replace_string "__DB_NAME__" "$db_name" "${final_path}/lufi.conf"
|
||||||
ynh_replace_string "__DB_USER__" "$db_user" "${final_path}/lufi.conf"
|
ynh_replace_string "__DB_USER__" "$db_user" "${final_path}/lufi.conf"
|
||||||
ynh_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lufi.conf"
|
ynh_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lufi.conf"
|
||||||
ynh_replace_string "__MAX_FILE_SIZE__" "$max_file_size" "${final_path}/lufi.conf"
|
ynh_replace_string "__MAX_FILE_SIZE__" "$max_file_size" "${final_path}/lufi.conf"
|
||||||
|
ynh_replace_string "__DB_MANAGER__" "$db_manager" "${final_path}/lufi.conf"
|
||||||
if [ $max_file_size -eq 0 ]; then # Comment the limitation line if no limit
|
if [ $max_file_size -eq 0 ]; then # Comment the limitation line if no limit
|
||||||
ynh_replace_string "max_file_size" "#max_file_size" "${final_path}/lufi.conf"
|
ynh_replace_string "max_file_size" "#max_file_size" "${final_path}/lufi.conf"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -63,7 +63,7 @@ ynh_remove_nginx_config
|
||||||
# DELETE LOG
|
# DELETE LOG
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_secure_remove "/var/log/$app/"
|
ynh_secure_remove "/var/log/$app"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE LOGROTATE CONFIGURATION
|
# REMOVE LOGROTATE CONFIGURATION
|
||||||
|
|
|
@ -32,6 +32,7 @@ domain=$(ynh_app_setting_get $app domain)
|
||||||
path_url=$(ynh_app_setting_get $app path)
|
path_url=$(ynh_app_setting_get $app path)
|
||||||
final_path=$(ynh_app_setting_get $app final_path)
|
final_path=$(ynh_app_setting_get $app final_path)
|
||||||
db_name=$(ynh_app_setting_get $app db_name)
|
db_name=$(ynh_app_setting_get $app db_name)
|
||||||
|
db_manager=$(ynh_app_setting_get $app db_manager)
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CHECK IF THE APP CAN BE RESTORED
|
# CHECK IF THE APP CAN BE RESTORED
|
||||||
|
@ -79,12 +80,15 @@ ynh_system_user_create $app
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTORE THE POSTGRESQL DATABASE
|
# RESTORE THE POSTGRESQL DATABASE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
|
if [ $db_manager = "postgresql" ]; then
|
||||||
ynh_print_info "Restoring the PostregSQL database..."
|
ynh_print_info "Restoring the PostregSQL database..."
|
||||||
|
|
||||||
db_pwd=$(ynh_app_setting_get $app psqlpwd)
|
db_pwd=$(ynh_app_setting_get $app psqlpwd)
|
||||||
ynh_psql_test_if_first_run
|
ynh_psql_test_if_first_run
|
||||||
ynh_psql_setup_db $db_name $db_name $db_pwd
|
ynh_psql_setup_db $db_name $db_name $db_pwd
|
||||||
ynh_psql_connect_as $db_name $db_pwd $db_name < ./db.sql
|
ynh_psql_connect_as $db_name $db_pwd $db_name < ./db.sql
|
||||||
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTORE USER RIGHTS
|
# RESTORE USER RIGHTS
|
||||||
|
|
|
@ -26,6 +26,7 @@ db_name=$(ynh_app_setting_get $app db_name)
|
||||||
db_user=$db_name
|
db_user=$db_name
|
||||||
db_pwd=$(ynh_app_setting_get $app psqlpwd)
|
db_pwd=$(ynh_app_setting_get $app psqlpwd)
|
||||||
max_file_size=$(ynh_app_setting_get $app max_file_size)
|
max_file_size=$(ynh_app_setting_get $app max_file_size)
|
||||||
|
db_manager=$(ynh_app_setting_get $app db_manager)
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# FIX OLD THINGS
|
# FIX OLD THINGS
|
||||||
|
@ -59,6 +60,11 @@ if [ -z "$max_file_size" ]; then
|
||||||
max_file_size=100 # 100 Mo
|
max_file_size=100 # 100 Mo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# If db_manager is empty, use sqlite for a backward compatibility
|
||||||
|
if [ -z "$db_manager" ]; then
|
||||||
|
db_manager="sqlite"
|
||||||
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -116,6 +122,7 @@ ynh_replace_string "__DB_NAME__" "$db_name" "${final_path}/lufi.conf"
|
||||||
ynh_replace_string "__DB_USER__" "$db_user" "${final_path}/lufi.conf"
|
ynh_replace_string "__DB_USER__" "$db_user" "${final_path}/lufi.conf"
|
||||||
ynh_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lufi.conf"
|
ynh_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lufi.conf"
|
||||||
ynh_replace_string "__MAX_FILE_SIZE__" "$max_file_size" "${final_path}/lufi.conf"
|
ynh_replace_string "__MAX_FILE_SIZE__" "$max_file_size" "${final_path}/lufi.conf"
|
||||||
|
ynh_replace_string "__DB_MANAGER__" "$db_manager" "${final_path}/lufi.conf"
|
||||||
if [ $max_file_size -eq 0 ]; then # Comment the limitation line if no limit
|
if [ $max_file_size -eq 0 ]; then # Comment the limitation line if no limit
|
||||||
ynh_replace_string "max_file_size" "#max_file_size" "${final_path}/lufi.conf"
|
ynh_replace_string "max_file_size" "#max_file_size" "${final_path}/lufi.conf"
|
||||||
fi
|
fi
|
||||||
|
@ -141,7 +148,7 @@ chmod +x $final_path/script/lufi
|
||||||
# SECURING FILES AND DIRECTORIES
|
# SECURING FILES AND DIRECTORIES
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
chown -R $app:$app "$final_path"
|
chown -R $app: "$final_path"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP SYSTEMD
|
# SETUP SYSTEMD
|
||||||
|
@ -156,7 +163,11 @@ ynh_add_systemd_config
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
pushd $final_path
|
pushd $final_path
|
||||||
|
if [ $db_manager = "postgresql" ]; then
|
||||||
carton install --deployment --without=sqlite --without=mysql
|
carton install --deployment --without=sqlite --without=mysql
|
||||||
|
else
|
||||||
|
carton install --deployment --without=postgresql --without=mysql
|
||||||
|
fi
|
||||||
popd
|
popd
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -171,14 +182,21 @@ ynh_use_logrotate --non-append
|
||||||
# ADVERTISE SERVICE IN ADMIN PANEL
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
|
# if /var/log/$app/production.log is a symbolic link, then move it to $final_path/log/production.log
|
||||||
|
if [ ! -L "/var/log/$app/production.log" ]
|
||||||
|
then
|
||||||
|
mv "/var/log/$app/production.log" "$final_path/log/production.log"
|
||||||
|
chown -R $app: "$final_path/log/production.log"
|
||||||
|
fi
|
||||||
|
|
||||||
yunohost service add $app --log "$final_path/log/production.log"
|
yunohost service add $app --log "$final_path/log/production.log"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTART LUFI
|
# RESTART LUFI
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_systemd_action -n $app -a reload -l "Creating process id file" -p "$final_path/log/production.log"
|
|
||||||
ln -sf "$final_path/log/production.log" "/var/log/$app/production.log"
|
ln -sf "$final_path/log/production.log" "/var/log/$app/production.log"
|
||||||
|
ynh_systemd_action -n $app -a restart -l "Creating process id file" -p "$final_path/log/production.log"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP SSOWAT
|
# SETUP SSOWAT
|
||||||
|
|
Loading…
Reference in a new issue