2021-09-25 13:26:10 +02:00
|
|
|
#!@TERMUX_PREFIX@/bin/bash
|
|
|
|
set -e -u
|
|
|
|
|
|
|
|
export PREFIX=@TERMUX_PREFIX@
|
|
|
|
|
|
|
|
msg() {
|
2021-10-08 21:05:52 +02:00
|
|
|
echo "$*" >&2
|
2021-09-25 13:26:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
show_usage() {
|
|
|
|
msg
|
|
|
|
msg "Usage: termux-restore [input file]"
|
|
|
|
msg
|
|
|
|
msg "Script for restoring Termux installation directory (\$PREFIX)"
|
|
|
|
msg "from the given TAR archive."
|
|
|
|
msg
|
|
|
|
msg "It is expected that backup file was made by 'termux-backup'."
|
|
|
|
msg "Restoring procedure will erase all files in \$PREFIX directory"
|
|
|
|
msg "that are not present in the given backup file. Be careful."
|
|
|
|
msg
|
|
|
|
msg "Backup contents may be supplied via stdin by specifying input"
|
|
|
|
msg "file as '-'. Note that piped TAR archive must be uncompressed."
|
|
|
|
msg
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ $# -lt 1 ]; then
|
|
|
|
msg
|
|
|
|
msg "[!] Input file path is not specified."
|
|
|
|
show_usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $# -gt 1 ]; then
|
|
|
|
shift 1
|
|
|
|
msg
|
2021-10-08 21:05:52 +02:00
|
|
|
msg "[!] Got extra arguments: $*"
|
2021-09-25 13:26:10 +02:00
|
|
|
show_usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "$1" in
|
2021-10-08 21:05:52 +02:00
|
|
|
-\?|-h|--help|--usage) show_usage; exit 0;;
|
2021-09-25 13:26:10 +02:00
|
|
|
*) BACKUP_FILE_PATH=$1;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [ "$BACKUP_FILE_PATH" != "-" ] && [ ! -e "$BACKUP_FILE_PATH" ]; then
|
|
|
|
msg
|
|
|
|
msg "[!] File '$BACKUP_FILE_PATH' does not exist."
|
|
|
|
msg
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
if [ "$BACKUP_FILE_PATH" != "-" ] && [ ! -f "$BACKUP_FILE_PATH" ]; then
|
|
|
|
msg
|
|
|
|
msg "[!] Path '$BACKUP_FILE_PATH' is not a regular file."
|
|
|
|
msg
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2021-10-08 21:01:46 +02:00
|
|
|
# Ensure that prefix doesn't contain read-only files.
|
|
|
|
find "@TERMUX_PREFIX@" -type d -print0 | xargs -0 -r chmod u+rwx
|
|
|
|
find "@TERMUX_PREFIX@" -type f -print0 | xargs -0 -r chmod u+rw
|
|
|
|
|
2021-09-25 13:26:10 +02:00
|
|
|
# --recursive-unlink is added intentionally to delete all orphan/extra files
|
|
|
|
# in $PREFIX. It must be restored to a clean state as in backup tarball.
|
|
|
|
tar -x -C "@TERMUX_BASE_DIR@" -f "$BACKUP_FILE_PATH" \
|
|
|
|
--recursive-unlink --preserve-permissions ./usr
|