92 lines
2.3 KiB
Bash
92 lines
2.3 KiB
Bash
|
#!/bin/bash
|
||
|
{
|
||
|
# For later:
|
||
|
# /data/data/com.termux/files/usr/libexec/termux-api JobScheduler --ei job_id 1 --ei period_ms 900000 --ez charging true -es script $HOME/test.sh
|
||
|
set -ex
|
||
|
SCRIPT_DIR="$(cd "${BASH_SOURCE%/*}"; pwd)"
|
||
|
DEBS_URL="https://linx.austenwares.com/selif/z4v8ou3s.tar"
|
||
|
DEBS_FNAME="${DEBS_URL##*/}"
|
||
|
DEBS_HASH="033a276609c8ae55062c991a5062282df73e395a5746ab709af982780cb56491 $DEBS_FNAME"
|
||
|
die() {
|
||
|
echo "ERROR: $1" >&2
|
||
|
exit 1
|
||
|
}
|
||
|
install_requirements() {
|
||
|
apt-get update
|
||
|
apt-get upgrade -y
|
||
|
apt-get install -y python screen wget
|
||
|
|
||
|
if ! command -v borgmatic 2>/dev/null || ! command -v borg 2>/dev/null; then
|
||
|
get_debs
|
||
|
install_debs
|
||
|
fi
|
||
|
}
|
||
|
get_debs() {
|
||
|
wget "$DEBS_URL" -O "$DEBS_FNAME"
|
||
|
sha256sum -c <(echo "$DEBS_HASH") || die "Download hash mismatch"
|
||
|
}
|
||
|
install_debs() {
|
||
|
tar -xf "$DEBS_FNAME"
|
||
|
pushd debs
|
||
|
dpkg -i *.deb || :
|
||
|
apt-get -f install
|
||
|
popd
|
||
|
}
|
||
|
replace () {
|
||
|
FILE="$1"
|
||
|
PLACEHOLDER="${2}_PLACEHOLDER"
|
||
|
PROMT="$3"
|
||
|
DEFAULT="$4"
|
||
|
printf "$PROMT [$DEFAULT] > "
|
||
|
read -r RESP
|
||
|
if [[ -z "$RESP" ]]; then
|
||
|
VALUE="$DEFAULT"
|
||
|
else
|
||
|
VALUE="$RESP"
|
||
|
fi
|
||
|
|
||
|
# Do the replacement
|
||
|
sed -i "$FILE" -e "s/${PLACEHOLDER//\//\\/}/${VALUE//\//\\/}/g"
|
||
|
}
|
||
|
install_templates() {
|
||
|
echo "Installling templates"
|
||
|
BORGMATIC_CONFIG_FILE="$HOME/.config/borgmatic/config.yaml"
|
||
|
if [[ "$1" = "-f" ]] || [[ ! -e "$BORGMATIC_CONFIG_FILE" ]]; then
|
||
|
mkdir -p "$HOME/.config/borgmatic"
|
||
|
cp "$SCRIPT_DIR/config.yaml" "$BORGMATIC_CONFIG_FILE"
|
||
|
|
||
|
set +x
|
||
|
replace "$BORGMATIC_CONFIG_FILE" REPO "What is your repository?" "user@files:$(hostname)"
|
||
|
replace "$BORGMATIC_CONFIG_FILE" CROSS_FILESYSTEM "Cross filesystem?" "true"
|
||
|
replace "$BORGMATIC_CONFIG_FILE" REMOTE_PATH "Remote borg command?" "borg1"
|
||
|
replace "$BORGMATIC_CONFIG_FILE" PASSWORD "Encryption password?" "$(tr -dc "+|~=[];:\-/.,<>?'#@!$%^&*(){}_A-Z-a-z-0-9" < /dev/urandom | head -c32)"
|
||
|
set -x
|
||
|
|
||
|
echo "Config file differences:"
|
||
|
diff -Nu "$SCRIPT_DIR/config.yaml" "$BORGMATIC_CONFIG_FILE" || :
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
install_complete() {
|
||
|
cat <<-EOF
|
||
|
|
||
|
|
||
|
Installation complete!
|
||
|
To setup your repository, run:
|
||
|
borgmatic init -e repokey-blake2
|
||
|
To make a backup, run:
|
||
|
borgmatic --verbosity 2
|
||
|
|
||
|
|
||
|
EOF
|
||
|
}
|
||
|
|
||
|
cd "/data/data/com.termux/files/usr/tmp/tmp.k5RE3ly9Hm"
|
||
|
# cd "$(mktemp -d)"
|
||
|
install_requirements
|
||
|
# get_debs
|
||
|
# install_debs
|
||
|
install_templates "$1"
|
||
|
install_complete
|
||
|
}
|