2
0
Fork 0
backup/sh.zio.backup

40 lines
978 B
Plaintext
Raw Permalink Normal View History

2023-08-22 01:46:52 +02:00
#!/usr/bin/env bash
wd="$(realpath "$(dirname "$(realpath -s "$0")")/.tmp")"
git_url_prefix="https://git.zio.sh/zio/rootfs/raw/branch/main"
2023-08-24 03:08:22 +02:00
helpers_dir="$wd/helpers"
backup_script_path="$wd/sh.zio.backup"
bash_helper_path="$helpers_dir/bash.sh"
2023-08-24 03:08:22 +02:00
function die() {
echo -e "\033[1;31mError: $@\033[0m"
exit 255
}
2023-08-22 01:46:52 +02:00
function fetch() {
url="$1"
output="$2"
curl -L -s -o "$output" "$url"
2023-08-24 03:08:22 +02:00
[[ $? != 0 ]] && die "Unable to download '$url'"
2023-08-22 01:46:52 +02:00
}
2023-08-24 03:08:22 +02:00
[[ ! -w "$(dirname "$(realpath -s "$0")")" ]] && die "No write permissions in current directory"
2023-08-22 01:46:52 +02:00
mkdir -p "$wd"
2023-08-24 03:08:22 +02:00
mkdir -p "$helpers_dir"
2023-08-22 01:46:52 +02:00
fetch "$git_url_prefix/usr/local/bin/sh.zio.backup" "$backup_script_path"
fetch "$git_url_prefix/usr/local/libexec/zio/helpers/bash.sh" "$bash_helper_path"
2023-08-22 01:46:52 +02:00
chmod +x "$backup_script_path"
chmod +x "$bash_helper_path"
2023-08-24 03:08:22 +02:00
if [[ -n "$SUDO_USER" ]]; then
chown -R "$SUDO_USER" "$wd"
fi
2023-08-22 01:46:52 +02:00
2023-08-24 03:08:22 +02:00
export ZIO_HELPERS_DIR="$helpers_dir"
/usr/bin/env bash "$backup_script_path" $@
2023-08-22 01:46:52 +02:00
rm -rf "$wd"