1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/turtl_ynh.git synced 2024-09-03 20:26:35 +02:00

Backup + restore + upgrade

This commit is contained in:
Luc Didry 2017-09-22 13:53:04 +02:00
parent cc2e64eae2
commit 58d9f460c7
10 changed files with 2165 additions and 51 deletions

1757
conf/quicklisp.lisp Normal file

File diff suppressed because it is too large Load diff

18
conf/quicklisp.lisp.asc Normal file
View file

@ -0,0 +1,18 @@
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.22 (Darwin)
Comment: GPGTools - https://gpgtools.org
iQIcBAABCgAGBQJUyVD2AAoJEDB5ZasCi1/3EYAQAIPm+dXrTCRgHA6aFZTc8VeB
DoBFsQPlFsLeKjixy3wSalPhI751ItWyy3DOx1tRYpFN0aYGSRbiMuVUF9DVMsSB
ROeNCg+f6lvtHuSokHKiZ95y8GarBqs4qguHi1Ir+n+inno4ZfE+8JvrxxQ9Lo4Z
KGgRoyJceaVcku3lmQK131i2eOf8RZaHmXv24tHprXpnle0d74etXO0TAdmpk5R2
OaeduaitR7o3cGT0JCS39rC5qH/H19jz9XkTjuLOGNqiKcX7XePTejdSLbT7FphN
4G2uTN8Z5HiYy56OpcuLdjHlPFiThwmIId6NMO3PHNlVAeL5PMKzw9tZTQlw4C5E
XKgL7gqC4L6Ys64/70IIBPo+L8TG74VkEbcWkNr3TCzAdz8x1Sa40YHRoVpRFK8M
T+v/qMJ8sgHb9o1OsEniv8eCFyFNPd7AlrRYehWQqRaVCuFG//95jEGNI/ig7vjK
v/z6tIyqi2e6zJPsJxAPJ8Y23jkTH4u5dvFct+k1fkZOCIpA/jLUT1RuWqLKTpOF
pSlDVmrqjrhM+jVnFEyWOg/mkSmQsY0jfC2sVDpx4XEGq3PdBnKqpPBTL0L8s5sg
YmqsGjMVk9IMCtylwuBlP5VGgoB8GmHGdhbeSKNxQJb75voDOiIS/sOP5+ACOxcA
Yg8wz616XOOHpLNUki3j
=yTd1
-----END PGP SIGNATURE-----

7
conf/turtl-preferences Normal file
View file

@ -0,0 +1,7 @@
Package: libuv1-dev
Pin: release a=jessie-backports
Pin-Priority: 900
Package: rethinkdb
Pin: origin download.rethinkdb.com
Pin-Priority: 900

View file

@ -2,6 +2,7 @@
"name": "Turtl",
"id": "turtl",
"packaging_format": 1,
"version": "0.01",
"description": {
"en": "Turtl lets you take notes, bookmark websites, and store documents for sensitive projects. From sharing passwords with your coworkers to tracking research on an article you're writing, Turtl keeps it all safe from everyone but you and those you share with.",
"fr": "Turtl vous permet de prendre des notes, de mettre en marque-page des adresses Web et de stocker des documents pour des projets sensibles. Du partage de mots de passe avec vos collègues au suivi des recherches pour un article que vous écrivez, Turtl empêche quiconque d'y accéder, sauf vous et ceux que vous partagez."
@ -14,7 +15,7 @@
"url": "https://framasoft.org"
},
"requirements": {
"yunohost": ">> 2.4.0"
"yunohost": ">> 2.6.4"
},
"multi_instance": false,
"services": [

101
scripts/backup Executable file
View file

@ -0,0 +1,101 @@
#!/bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
#=================================================
# GENERIC STARTING
#=================================================
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
if [ ! -e _common.sh ]; then
# Get the functions file if not present in the current directory
sudo cp ../settings/scripts/_common.sh ./_common.sh
sudo chmod a+rx _common.sh
fi
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
port=$(ynh_app_setting_get $app port)
domain=$(ynh_app_setting_get $app domain)
is_public=$(ynh_app_setting_get $app is_public)
wwwhome=~wwwdata
final_path="$wwwhome/$app"
#=================================================
# STANDARD BACKUP STEPS
#=================================================
# BACKUP OF THE BDD AND ITS CONFIGURATION
#=================================================
# Backup the configuration
CHECK_SIZE "/etc/rethinkdb/instances.d/turtl.conf"
ynh_backup "/etc/rethinkdb/instances.d/turtl.conf"
# Dump data
/usr/local/bin/rethinkdb dump -q --overwrite-file -f "$final_path/rethinkdb_dump.tar.gz"
#=================================================
# BACKUP OF THE MAIN DIR OF THE APP
#=================================================
CHECK_SIZE "$final_path"
ynh_backup "$final_path"
#=================================================
# BACKUP OF THE SYSTEMD SERVICE
#=================================================
CHECK_SIZE "/etc/systemd/system/$app.service"
ynh_backup "/etc/systemd/system/$app.service"
#=================================================
# BACKUP OF THE NGINX CONFIGURATION
#=================================================
CHECK_SIZE "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP OF APT PREFERENCES AND SOURCES.LIST
#=================================================
CHECK_SIZE "/etc/apt/sources.list.d/$app.list"
ynh_backup "/etc/apt/sources.list.d/$app.list"
CHECK_SIZE "/etc/apt/preferences.d/00TurtlPinning"
ynh_backup "/etc/apt/preferences.d/00TurtlPinning"
#=================================================
# BACKUP OF CCL DIRECTORIES
#=================================================
CHECK_SIZE "$wwwhome/.ccl-init.lisp"
ynh_backup "$wwwhome/.ccl-init.lisp"
CHECK_SIZE "$wwwhome/quicklisp"
ynh_backup "$wwwhome/quicklisp"
CHECK_SIZE "$wwwhome/.cache"
ynh_backup "$wwwhome/.cache"
#=================================================
# BACKUP OF RSYSLOG CONFIGURATION
#=================================================
CHECK_SIZE "/etc/rsyslog.d/$app.conf"
ynh_backup "/etc/rsyslog.d/$app.conf"
#=================================================
# BACKUP OF LOGS
#=================================================
CHECK_SIZE "/var/log/turtl"
ynh_backup "/var/log/turtl"
#=================================================
# BACKUP OF LOGROTATE CONFIGURATION
#=================================================
CHECK_SIZE "/etc/logrotate.d/$app"
ynh_backup "/etc/logrotate.d/$app"

View file

@ -20,8 +20,9 @@ ynh_abort_if_errors # Active trap pour arrêter le script si une erreur est dét
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$YNH_APP_ARG_DOMAIN
path=$YNH_APP_ARG_PATH
domain=$YNH_APP_ARG_DOMAIN
is_public=$YNH_APP_ARG_IS_PUBLIC
#=================================================
@ -36,22 +37,49 @@ then
fi
archi=$(uname -m)
pwd=$(pwd)
wwwhome=~www-data
#=================================================
# FIND AND OPEN A PORT
#=================================================
port=$(ynh_find_port 8181) # Cherche un port libre.
ynh_app_setting_set $app port $port
# Store infos in YunoHost config
ynh_app_setting_set $app domain ${domain}
ynh_app_setting_set $app port $port
ynh_app_setting_set $app path ${path}
ynh_app_setting_set $app domain ${domain}
ynh_app_setting_set $app is_public ${is_public}
#=================================================
# DEPENDENCIES
#=================================================
# Activate backports sources.list
cp -a "../conf/turtl.list" "/etc/apt/sources.list.d/$app.list"
cp -a "../conf/turtl-preferences" "/etc/apt/preferences.d/00TurtlPinning"
if [ $archi == "armv7l" ]
then
gpg --keyserver pgpkeys.mit.edu --recv-key 7638D0442B90D010
gpg -a --export 7638D0442B90D010 | apt-key add -
fi
if [ $archi == "armv7l" ]
then
# Install RethinkDB
dpkg -i ../conf/rethinkdb_2.3.6_armhf.deb
else
# Activate RethinkDB sources.list
release=$(lsb_release -cs)
echo "deb http://download.rethinkdb.com/apt $release main" | tee /etc/apt/sources.list.d/rethinkdb.list
wget -qO- https://download.rethinkdb.com/apt/pubkey.gpg | apt-key add -
ynh_package_update
fi
# Install dependencies
ynh_package_update
ynh_install_app_dependencies wget git build-essential rethinkdb libuv1-dev python-pip
# Install Clozure Common Lisp
cd /opt
if [ $archi == "armv7l" ]
@ -72,55 +100,33 @@ else
fi
sed -e "s@CCL_DEFAULT_DIRECTORY=/usr/local/src/ccl@CCL_DEFAULT_DIRECTORY=/opt/ccl@" -i /usr/bin/ccl
# Install some dependencies
cd $pwd
sudo cp -a ../conf/turtl.list /etc/apt/sources.list.d/
if [ $archi == "armv7l" ]
then
gpg --keyserver pgpkeys.mit.edu --recv-key 7638D0442B90D010
gpg -a --export 7638D0442B90D010 | sudo apt-key add -
fi
sudo apt-get update
sudo apt-get -qq -y install build-essential
sudo apt-get -qq -t jessie-backports -y install libuv1-dev
# Install QuickLisp
sudo cp -a ../conf/ccl-init.lisp ~www-data/.ccl-init.lisp
mkdir ~www-data/quicklisp ~www-data/.cache/
chown www-data: ~www-data/quicklisp ~www-data/.cache/ ~www-data/.ccl-init.lisp
cd $pwd
cp -a ../conf/ccl-init.lisp $wwwhome/.ccl-init.lisp
cp -a ../conf/quicklisp.lisp /tmp/quicklisp.lisp
cp -a ../conf/quicklisp.lisp.asc /tmp/quicklisp.lisp.asc
mkdir $wwwhome/quicklisp $wwwhome/.cache/
chown www-data: $wwwhome/quicklisp $wwwhome/.cache/ $wwwhome/.ccl-init.lisp
wget -q https://beta.quicklisp.org/quicklisp.lisp -O /tmp/quicklisp.lisp
wget -q https://beta.quicklisp.org/quicklisp.lisp.asc -O /tmp/quicklisp.lisp.asc
gpg --keyserver pgpkeys.mit.edu --recv-key 307965AB028B5FF7
gpg --verify /tmp/quicklisp.lisp.asc /tmp/quicklisp.lisp
su -c 'echo -e "(quicklisp-quickstart:install)\n(quit)" | ccl --load /tmp/quicklisp.lisp' -s /bin/bash www-data
echo "(pushnew \"./\" asdf :*central-registry* :test #'equal)" >> ~www-data/.ccl-init.lisp
echo "(pushnew \"./\" asdf :*central-registry* :test #'equal)" >> $wwwhome/.ccl-init.lisp
rm -f /tmp/quicklisp /tmp/quicklisp.lisp.asc
# Install RethinkDB
if [ $archi == "armv7l" ]
then
sudo dpkg -i ../conf/rethinkdb_2.3.6_armhf.deb
else
release=$(lsb_release -cs)
echo "deb http://download.rethinkdb.com/apt $release main" | sudo tee /etc/apt/sources.list.d/rethinkdb.list
wget -qO- https://download.rethinkdb.com/apt/pubkey.gpg | sudo apt-key add -
sudo apt-get update
sudo apt-get -qq -y install rethinkdb
fi
# Configure RethinkDB
echo "http-port=8091" > /etc/rethinkdb/instances.d/turtl.conf
service rethinkdb restart
# Install RethinkDB tools (needed for backup)
apt-get install python-pip
pip install rethinkdb
# Install Turtl
cd /var/www
cd $wwwhome
mkdir turtl/data -p
cd turtl
git clone https://github.com/turtl/api.git
@ -140,7 +146,7 @@ sed -e "s@\*server-port\* 8181@*server-port* $port@" \
-e "s@\*site-url\* \"http://turtl.dev:8181\"@*site-url* \"https://$domain\"@" \
-e "s@\*smtp-host\* nil@*smtp-host* \"localhost\"@" \
-e "s@\*display-errors\* t@*display-errors* nil@" \
-e "s@\*local-upload\* nil@*local-upload* \"/var/www/turtl/data\"@" \
-e "s@\*local-upload\* nil@*local-upload* \"$wwwhome/turtl/data\"@" \
-e "s@\*local-upload-url\* nil@*local-upload-url* \"https://$domain\"@" \
-i config/config.lisp
@ -149,38 +155,37 @@ then
sed -e "s@\*api-path\* \"\"@\*api-path\* \"$path\"@" -i config/config.lisp
fi
ynh_store_checksum_config "config/config.lisp" # Enregistre la somme de contrôle du fichier de config
#=================================================
# LOG HANDLING
#=================================================
cd $pwd
sudo cp ../conf/rsyslogd.conf /etc/rsyslog.d/turtl.conf
sudo service rsyslog restart
sudo cp ../conf/logrotate.conf /etc/logrotate.d/turtl
cp "../conf/rsyslogd.conf" "/etc/rsyslog.d/$app.conf"
service rsyslog restart
mkdir /var/log/turtl/ -p
cp "../conf/logrotate.conf" "/etc/logrotate.d/$app"
#=================================================
# ENABLE SERVICE IN ADMIN PANEL
#=================================================
# Add service to Yunohost monitoring
sudo cp ../conf/turtl.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo yunohost service add turtl --log "/var/log/turtl/turtl.log"
sudo yunohost service start turtl
cp "../conf/turtl.service" "/etc/systemd/system/$app.service"
systemctl daemon-reload
yunohost service add turtl --log "/var/log/turtl/$app.log"
yunohost service start turtl
#=================================================
# NGINX
#=================================================
# Copy Nginx conf
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
# Change variables in Nginx configuration
if [ $is_public -eq 1 ];
then
ynh_app_setting_set "$app" unprotected_uris "$path"
fi
sudo sed -i "s@__PATH__@$path@g" /etc/nginx/conf.d/$domain.d/$app.conf
sudo sed -i "s@__PORT__@$port@g" /etc/nginx/conf.d/$domain.d/$app.conf
sed -i "s@__PATH__@$path@g" /etc/nginx/conf.d/$domain.d/$app.conf
sed -i "s@__PORT__@$port@g" /etc/nginx/conf.d/$domain.d/$app.conf
# Reload Nginy
sudo service nginx reload
# Reload Nginx
service nginx reload

167
scripts/restore Executable file
View file

@ -0,0 +1,167 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
if [ ! -e _common.sh ]; then
# Get the _common.sh file if it's not in the current directory
cp ../settings/scripts/_common.sh ./_common.sh
chmod a+rx _common.sh
fi
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
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
path=$(ynh_app_setting_get $app path)
port=$(ynh_app_setting_get $app port)
domain=$(ynh_app_setting_get $app domain)
is_public=$(ynh_app_setting_get $app is_public)
wwwhome=~wwwdata
final_path="$wwwhome/$app"
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
yunohost app checkurl "${domain}${path_url}" -a "$app" \
test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "
#=================================================
# RESTORE OF THE NGINX CONFIGURATION
#=================================================
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE OF THE MAIN DIR OF THE APP
#=================================================
ynh_restore_file "$final_path"
#=================================================
# HANDLE LOG FILES AND LOGROTATE
#=================================================
mkdir -p /var/log/turtl
# Restore rsyslog conf
ynh_restore_file "/etc/rsyslog.d/$app.conf"
# Restore logrotate conf
ynh_restore_file "/etc/logrotate.d/$app"
#=================================================
# APT STUFF
#=================================================
ynh_restore_file "/etc/apt/sources.list.d/$app.list"
ynh_restore_file "/etc/apt/preferences.d/00TurtlPinning"
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_package_update
if ! ynh_package_is_installed "wget" ; then
ynh_install_app_dependencies wget
fi
if ! ynh_package_is_installed "git" ; then
ynh_install_app_dependencies git
fi
#=================================================
# INSTALL CCL
#=================================================
cd /opt
if [ $archi == "armv7l" ]
then
wget -q ftp://ftp.clozure.com/pub/release/1.11/ccl-1.11-linuxarm.tar.gz
tar xf ccl-1.11-linuxarm.tar.gz
else
wget -q ftp://ftp.clozure.com/pub/release/1.11/ccl-1.11-linuxx86.tar.gz
tar xf ccl-1.11-linuxx86.tar.gz
fi
cd ccl
if [ $(grep -c "flags.* lm .*" /proc/cpuinfo) -eq 0 ]
then
cp scripts/ccl /usr/bin/ccl
else
cp scripts/ccl64 /usr/bin/ccl
fi
sed -e "s@CCL_DEFAULT_DIRECTORY=/usr/local/src/ccl@CCL_DEFAULT_DIRECTORY=/opt/ccl@" -i /usr/bin/ccl
# Install some dependencies
if [ $archi == "armv7l" ]
then
gpg --keyserver pgpkeys.mit.edu --recv-key 7638D0442B90D010
gpg -a --export 7638D0442B90D010 | apt-key add -
fi
if ! ynh_package_is_installed "build-essential" ; then
ynh_install_app_dependencies build-essential
fi
ynh_install_app_dependencies libuv1-dev
ynh_restore_file "$wwwhome/.ccl-init.lisp"
ynh_restore_file "$wwwhome/quicklisp"
ynh_restore_file "$wwwhome/.cache"
#=================================================
# INSTALL Rethinkdb
#=================================================
if [ $archi == "armv7l" ]
then
dpkg -i ../conf/rethinkdb_2.3.6_armhf.deb
else
release=$(lsb_release -cs)
echo "deb http://download.rethinkdb.com/apt $release main" | tee /etc/apt/sources.list.d/rethinkdb.list
wget -qO- https://download.rethinkdb.com/apt/pubkey.gpg | apt-key add -
ynh_package_update
ynh_install_app_dependencies rethinkdb
fi
echo "http-port=8091" > /etc/rethinkdb/instances.d/turtl.conf
service rethinkdb restart
# Install RethinkDB tools (needed for backup)
ynh_install_app_dependencies python-pip
pip install rethinkdb
#=================================================
# RESTORE OF THE BDD
#=================================================
/usr/local/bin/rethinkdb restore "$final_path/rethinkdb_dump.tar.gz"
#=================================================
# RESTORE SYSTEMD SERVICE
#=================================================
ynh_restore_file "/etc/systemd/system/$app.service"
systemctl daemon-reload
systemctl enable $app.service
#=================================================
# ENABLE SERVICE IN ADMIN PANEL
#=================================================
systemctl daemon-reload
yunohost service add turtl --log "/var/log/turtl/$app.log"
#=================================================
# START SERVICE
#=================================================
yunohost service start turtl
#=================================================
# RELOAD NGINX
#=================================================
systemctl reload nginx

52
scripts/upgrade Executable file
View file

@ -0,0 +1,52 @@
#!/bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
path=$(ynh_app_setting_get $app path)
port=$(ynh_app_setting_get $app port)
domain=$(ynh_app_setting_get $app domain)
is_public=$(ynh_app_setting_get $app path)
#=================================================
# FIX OLD THINGS
#=================================================
cp ../conf/rsyslogd.conf /etc/rsyslog.d/turtl.conf
service rsyslog restart
cp ../conf/logrotate.conf /etc/logrotate.d/turtl
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# 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 THE PATH
#=================================================
# Verify and correct path syntax
path_url=$(ynh_normalize_url_path $path_url) # Vérifie et corrige la syntaxe du path.
#=================================================
# STANDARD UPGRADE STEPS
#=================================================

4
temp.sh Normal file
View file

@ -0,0 +1,4 @@
set -eu
a=~luc
echo "$a"
ls $a

2
temp.txt Normal file
View file

@ -0,0 +1,2 @@
yunohost app install https://github.com/ldidry/Turtl_ynh.git --verbose -a "is_public=0&domain=ynh.pi&path=/" --debug
yunohost app remove turtl