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