1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/archivist_ynh.git synced 2024-09-03 18:15:55 +02:00
archivist_ynh/scripts/install

199 lines
6.1 KiB
Text
Raw Normal View History

2017-11-01 20:57:58 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
encrypt=$YNH_APP_ARG_ENCRYPT
2017-12-21 20:42:38 +01:00
ynh_print_OFF; encryption_pwd=$YNH_APP_ARG_ENCRYPTION_PWD; ynh_print_ON
2017-11-01 20:57:58 +01:00
core_backup=$YNH_APP_ARG_CORE_BACKUP
apps_backup=$YNH_APP_ARG_APPS_BACKUP
2017-12-23 23:56:21 +01:00
frequency="$YNH_APP_ARG_FREQUENCY"
2017-11-01 20:57:58 +01:00
app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
final_path=/opt/yunohost/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
if [ $encrypt -eq 1 ]; then
2017-12-21 20:42:38 +01:00
ynh_print_OFF
2017-11-01 20:57:58 +01:00
test -n "$encryption_pwd" || ynh_die "encryption_pwd can't be empty if you choose to enable encryption."
2017-12-21 20:42:38 +01:00
ynh_print_ON
2017-11-01 20:57:58 +01:00
fi
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2017-12-23 23:56:21 +01:00
ynh_app_setting_set $app frequency "$frequency"
2017-11-01 20:57:58 +01:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# INSTALL DEPENDENCIES
#=================================================
# Valid the fucking debconf message
# To find this, install the package, install also debconf-utils
# Then use `debconf-get-selections | grep package`
echo "encfs encfs/security-information boolean true" | debconf-set-selections
ynh_install_app_dependencies rsync encfs sshpass
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_app_setting_set $app final_path $final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
#=================================================
# SPECIFIC SETUP
#=================================================
# CREATE THE BACKUP DIRECTORY
#=================================================
2017-11-03 01:11:50 +01:00
backup_dir="/home/yunohost.app/${app}/backup"
enc_backup_dir="/home/yunohost.app/${app}/encrypted_backup"
2017-11-01 20:57:58 +01:00
mkdir -p "$backup_dir"
#=================================================
# CONFIGURE ARCHIVIST
#=================================================
config_file="$final_path/Backup_list.conf"
cp "$final_path/Backup_list.conf.default" "$config_file"
ynh_replace_string "^backup_dir=.*" "backup_dir=$backup_dir" "$config_file"
ynh_replace_string "^enc_backup_dir=.*" "enc_backup_dir=$enc_backup_dir" "$config_file"
if [ $encrypt -eq 1 ]
then
encrypt=true
passkey="$final_path/passkey"
2017-12-21 20:42:38 +01:00
ynh_print_OFF; echo "$encryption_pwd" > "$passkey"; ynh_print_ON
2017-11-01 20:57:58 +01:00
chmod 400 "$passkey"
else
encrypt=false
passkey=na
fi
ynh_replace_string "^encrypt=.*" "encrypt=$encrypt" "$config_file"
ynh_replace_string "^cryptpass=.*" "cryptpass=$passkey" "$config_file"
if [ $core_backup -eq 1 ]
then
core_backup=true
else
core_backup=false
fi
ynh_replace_string "^ynh_core_backup=.*" "ynh_core_backup=$core_backup" "$config_file"
if [ $apps_backup -eq 1 ]
then
# Add all current applications to the backup
while read backup_app
do
ynh_replace_string "^ynh_app_backup=$" "ynh_app_backup=$backup_app\n&" "$config_file"
done <<< "$(yunohost app list -i | grep id: | sed 's/.*id: //')"
fi
#=================================================
# SET THE CRON FILE
#=================================================
cp ../conf/cron /etc/cron.d/$app
ynh_replace_string "__FINALPATH__" "$final_path" /etc/cron.d/$app
ynh_replace_string "__APP__" "$app" /etc/cron.d/$app
if [ "$frequency" = "Daily" ]; then
2017-11-03 17:19:04 +01:00
cron_freq="0 2 * * *"
2017-12-16 23:05:44 +01:00
run_freq="every day"
2017-11-01 20:57:58 +01:00
elif [ "$frequency" = "Each 3 days" ]; then
2017-11-03 17:19:04 +01:00
cron_freq="0 2 */3 * *"
2017-12-16 23:05:44 +01:00
run_freq="each 3 days"
2017-11-01 20:57:58 +01:00
elif [ "$frequency" = "Weekly" ]; then
2017-11-03 17:19:04 +01:00
cron_freq="0 2 * * 0"
2017-12-16 23:05:44 +01:00
run_freq="once a week on sunday"
2017-11-01 20:57:58 +01:00
elif [ "$frequency" = "Biweekly" ]; then
2017-11-03 17:19:04 +01:00
cron_freq="0 2 * * 0/2"
2017-12-16 23:05:44 +01:00
run_freq="one sunday out of two"
2017-11-01 20:57:58 +01:00
else # Monthly
2017-11-03 17:19:04 +01:00
cron_freq="0 2 1 * *"
2017-12-16 23:05:44 +01:00
run_freq="once a month on the first sunday"
2017-11-01 20:57:58 +01:00
fi
ynh_replace_string "__FREQUENCY__" "$cron_freq" /etc/cron.d/$app
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "/etc/cron.d/$app"
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions to app files
chown -R root: $final_path
#=================================================
# SETUP LOGROTATE
#=================================================
mkdir -p /var/log/$app
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
#=================================================
# PRINT INFORMATIONS
#=================================================
2017-12-16 23:05:44 +01:00
Informations="To add recipients or to modify the files or apps to backup,
2017-11-03 01:11:50 +01:00
please have a look to the config file $config_file"
2017-12-16 23:05:44 +01:00
ynh_print_info "
$Informations" >&2
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
2017-12-21 20:42:38 +01:00
ynh_print_OFF
2017-12-16 23:05:44 +01:00
if [ "$encrypt" = "true" ]
then
encrypt_message="Your password for encryption is '$encryption_pwd'
"
else
encrypt_message=""
fi
message="${encrypt_message}Archivist is going to run $run_freq.
If you want to change the frequency, have a look to the file /etc/cron.d/$app.
$Informations
Please read the documentation (https://github.com/maniackcrudelis/archivist/blob/master/Configuration.md) about the configuration of archivist for more informations.
If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/archivist_ynh"
ynh_send_readme_to_admin "$message" "root"
2017-12-21 20:42:38 +01:00
ynh_print_ON