add error handling
This commit is contained in:
parent
22e7a43a52
commit
c0ab7cb7b0
1 changed files with 17 additions and 4 deletions
|
|
@ -2,23 +2,36 @@
|
||||||
|
|
||||||
wd="$(realpath "$(dirname "$(realpath -s "$0")")/.tmp")"
|
wd="$(realpath "$(dirname "$(realpath -s "$0")")/.tmp")"
|
||||||
git_url_prefix="https://git.zio.sh/zio/rootfs/raw/branch/main"
|
git_url_prefix="https://git.zio.sh/zio/rootfs/raw/branch/main"
|
||||||
|
helpers_dir="$wd/helpers"
|
||||||
|
|
||||||
|
function die() {
|
||||||
|
echo -e "\033[1;31mError: $@\033[0m"
|
||||||
|
exit 255
|
||||||
|
}
|
||||||
|
|
||||||
function fetch() {
|
function fetch() {
|
||||||
url="$1"
|
url="$1"
|
||||||
output="$2"
|
output="$2"
|
||||||
curl -L -s -o "$output" "$url"
|
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 "$wd"
|
||||||
mkdir -p "$wd/helpers"
|
mkdir -p "$helpers_dir"
|
||||||
|
|
||||||
fetch "$git_url_prefix/usr/local/bin/sh.zio.backup" "$wd/backup.sh"
|
fetch "$git_url_prefix/usr/local/bin/sh.zio.backup" "$wd/backup.sh"
|
||||||
fetch "$git_url_prefix/usr/local/libexec/zio/helpers/bash.sh" "$wd/helpers/bash.sh"
|
fetch "$git_url_prefix/usr/local/libexec/zio/helpers/bash.sh" "$wd/helpers/bash.sh"
|
||||||
|
|
||||||
chmod +x "$wd/backup.sh"
|
chmod +x "$wd/backup.sh"
|
||||||
chmod +x "$wd/helpers/bash.sh"
|
chmod +x "$helpers_dir/bash.sh"
|
||||||
|
|
||||||
export ZIO_HELPERS_DIR="$wd/helpers"
|
if [[ -n "$SUDO_USER" ]]; then
|
||||||
. "$wd/backup.sh" $@
|
chown -R "$SUDO_USER" "$wd"
|
||||||
|
fi
|
||||||
|
|
||||||
|
export ZIO_HELPERS_DIR="$helpers_dir"
|
||||||
|
/usr/bin/env bash "$wd/backup.sh" $@
|
||||||
|
|
||||||
rm -rf "$wd"
|
rm -rf "$wd"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue