Skip to content
This repository has been archived by the owner on May 24, 2020. It is now read-only.

[enh] Restore from an usb key #37

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion build/script/hypercube/hypercube.sh
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,34 @@ function find_hypercubefile() {
fi
}

function find_backup() {
logfile ${FUNCNAME[0]}

backup_file=$(find /media/ -mindepth 2 -maxdepth 2 -regex '.*/backup\.tar\.gz$' | head -n1)

if [ -z "${backup_file}" ]; then
backup_file=$(find /root/ -mindepth 1 -maxdepth 1 -regex '.*/backup\.tar\.gz$' | head -n1)
fi

if [ ! -z "${backup_file}" ]; then
info "Backup file found"

echo "DETECTED FILE: ${backup_file}" >> $log_file

else
err "No 'backup.tar.gz' file found"
fi

}

function restore() {
logfile ${FUNCNAME[0]}

mv "${backup_file}" "${archive_dir}"

yunohost backup restore -n backup --force --verbose &>> $log_file
}

function load_json() {
logfile ${FUNCNAME[0]}

Expand Down Expand Up @@ -600,6 +628,7 @@ function end_installation() {
declare -A settings
tmp_dir=$(mktemp -dp /tmp/ labriqueinternet-installhypercube-XXXXX)
hypercube_file="${tmp_dir}/install.hypercube"
archive_dir="/home/yunohost.backup/archives/"
exit_status=0
webserver_pid=
is_dyndns_useful=false
Expand Down Expand Up @@ -658,7 +687,29 @@ else
find_hypercubefile

if [ ! -r "${hypercube_file}" -o ! -s "${hypercube_file}" ]; then
exit_error "Cannot continue without a usable HyperCube file"

info "Looking for backup file"
find_backup

if [ ! -r "${backup_file}" -o ! -s "${backup_file}" ]; then
exit_error "Cannot continue without a usable HyperCube or backup file"
fi

info "Upgrading Debian/YunoHost..."
deb_upgrade

info "Restoring"
restore

info "Rebooting..."

if [ -f /etc/crypttab ]; then
warn "Once rebooted, you have to give the passphrase for uncrypting your Cube"
fi

sleep 5
keep_debugging=false
systemctl reboot
fi

info "Loading JSON"
Expand Down