2021-08-29 08:01:40 -07:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# This script was generated by bashly (https://github.com/DannyBen/bashly)
|
|
|
|
# Modifying it manually is not recommended
|
|
|
|
|
2021-12-04 22:14:09 -08:00
|
|
|
# :script.bash3_bouncer
|
|
|
|
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
|
|
|
|
printf "bash version 4 or higher is required\n"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :command.root_command
|
|
|
|
root_command() {
|
|
|
|
# :src/root_command.sh
|
|
|
|
#!/bin/bash
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
echo "running root command"
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
inspect_args
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# module_load ssh
|
|
|
|
module_load confirm
|
|
|
|
module_load path
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
local settings=${args[--settings]}
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-09-11 08:49:40 -07:00
|
|
|
if [[ $settings ]]; then
|
2021-08-29 08:01:40 -07:00
|
|
|
if [[ -f $settings ]]; then
|
|
|
|
echo loading settings file $settings
|
|
|
|
module_load yaml
|
|
|
|
eval $(parse_yaml $settings "s_")
|
|
|
|
echo $s_source
|
|
|
|
echo $s_target
|
2021-08-29 09:30:12 -07:00
|
|
|
echo $s_host
|
2021-09-11 08:49:40 -07:00
|
|
|
else
|
|
|
|
echo settings file $settings does not exist && return 1
|
|
|
|
fi
|
2021-08-29 08:01:40 -07:00
|
|
|
fi
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
if [[ $s_server_host ]]; then
|
2021-08-29 09:30:12 -07:00
|
|
|
s_server="http$([[ $s_server_secure ]] && echo "s")://${s_server_host}$([[ $s_server_port ]] && echo :${s_server_port} || echo "")"
|
2021-08-29 08:01:40 -07:00
|
|
|
fi
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
local password=${args[--password]:-$BACKUP_PASSWORD}
|
|
|
|
password=${password:-$s_password}
|
|
|
|
[[ ! $password ]] && echo restic requires a backup repository password, exiting && return 2
|
|
|
|
password="RESTIC_PASSWORD=${password}"
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
local server=${args[--server]:-$BACKUP_SERVER}
|
|
|
|
server=${server:-$s_server}
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-09-06 10:54:54 -07:00
|
|
|
local hostname=${args[--hostname]:-$s_hostname}
|
|
|
|
hostname=${hostname:-$s_host}
|
|
|
|
hostname=${hostname:-$HOSTNAME}
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-09-06 10:55:57 -07:00
|
|
|
local options="${args[--options]:-$BACKUP_OPTIONS}"
|
|
|
|
options="${options:-$s_options}"
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-09-06 10:54:54 -07:00
|
|
|
local smount=${args[--source_mount]:-$BACKUP_SOURCE_MOUNT}
|
|
|
|
smount=${smount:-$s_source_mount}
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-09-06 10:54:54 -07:00
|
|
|
echo smount: $smount $s_source_mount
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-09-06 10:54:54 -07:00
|
|
|
local tmount=${args[--target_mount]:-$BACKUP_TARGET_MOUNT}
|
|
|
|
tmount=${tmount:-$s_target_mount}
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-09-06 10:54:54 -07:00
|
|
|
echo tmount: $tmount $s_target_mount
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
local source="${args[source]:-$s_source}"
|
2021-09-06 10:54:54 -07:00
|
|
|
source="${source:-$s_source_path}"
|
2021-08-29 08:01:40 -07:00
|
|
|
source=$(echo "${source:-$PWD}" | tr -s /)
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-09-06 10:54:54 -07:00
|
|
|
echo yaml source $s_source_path $s_source_mount
|
|
|
|
echo source $source
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-09-06 10:54:54 -07:00
|
|
|
echo target $s_target
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-09-06 10:54:54 -07:00
|
|
|
echo target path $s_target_path
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
local target=${args[target]:-$s_target}
|
2021-09-06 10:54:54 -07:00
|
|
|
target=${target:-$s_target_path}
|
|
|
|
target=${target:-$(echo "${source}" | tr -s / | sed -e "s#^[.]##")}
|
|
|
|
target="$(echo "${target}" | tr -s /)"
|
|
|
|
echo "target> $target"
|
|
|
|
if [[ ${tmount} ]]; then
|
|
|
|
target="${tmount}${target}"
|
2021-08-29 08:01:40 -07:00
|
|
|
else
|
2021-09-06 10:54:54 -07:00
|
|
|
target="/${hostname}${target}"
|
2021-08-29 08:01:40 -07:00
|
|
|
fi
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-09-06 10:54:54 -07:00
|
|
|
if [[ $server ]]; then
|
|
|
|
target="rest:${server}${target}"
|
|
|
|
fi
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-09-06 10:54:54 -07:00
|
|
|
if [[ $smount ]]; then
|
2021-09-06 10:55:57 -07:00
|
|
|
setpath="--set-path ${source} --tag mount-point:${smount}"
|
2021-09-06 10:54:54 -07:00
|
|
|
source=${smount}${source}
|
|
|
|
fi
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
local exclude=${args[--exclude_file]:-$BACKUP_EXCLUDE}
|
|
|
|
exclude=${exclude:-$s_exclude}
|
|
|
|
exclude=${exclude:-"$source/exclude.bac"}
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-09-06 10:55:57 -07:00
|
|
|
# local shost=$([[ ${args[--shost]} ]] && echo ${args[--shost]}::)
|
|
|
|
# local suser=$([[ ${args[--suser]} ]] && echo ${args[--suser]}@)
|
|
|
|
# local thost=$([[ ${args[--host]} ]] && echo ${args[--host]}::)
|
|
|
|
# local tuser=$([[ ${args[--user]} ]] && echo ${args[--user]}@)
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
local options=$(echo ${args[--options]} | awk '{gsub(/\\/," ")}1')
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
local bin=$(command -v restic)
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
exclude=$([[ -f $exclude ]] && echo "--iexclude-file $exclude" || echo "")
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
echo source: $source
|
|
|
|
echo target $target
|
|
|
|
echo exclude: $exclude
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-09-06 10:55:57 -07:00
|
|
|
local sudo=$([[ ${args[--sudo]} || $s_sudo || $BACKUP_SUDO ]] && echo "sudo" || echo "")
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-09-06 10:55:57 -07:00
|
|
|
local pcmd="${sudo} ${password} ${bin} ${options} -r ${target}"
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-09-06 10:54:54 -07:00
|
|
|
local cmd="${pcmd} -H ${hostname} ${setpath} backup ${source} ${exclude}"
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 11:23:15 -07:00
|
|
|
if [[ ${args[--init]} ]]; then cmd="${pcmd} init"; fi
|
|
|
|
if [[ ${args[--snap]} ]]; then cmd="${pcmd} snapshots"; fi
|
|
|
|
if [[ ${args[--prune]} ]]; then cmd="${pcmd} prune"; fi
|
2021-08-29 08:01:40 -07:00
|
|
|
if [[ ${args[--view]} || ${args[--view-path]} ]]; then
|
|
|
|
mount=${args[--view-path]:-$BACKUP_MOUNT}
|
|
|
|
mount=${mount:-"/opt/backup/view/"}
|
|
|
|
echo view mount point $mount
|
|
|
|
if [[ -e ${mount} ]]; then
|
2021-08-29 11:23:15 -07:00
|
|
|
cmd="${pcmd} mount $mount";
|
2021-08-29 08:01:40 -07:00
|
|
|
echo browse files at $mount/snapshots/latest${source}
|
|
|
|
else
|
|
|
|
echo $mount: directory for mounting snapshot for viewing does not exist. Create and try again
|
|
|
|
return 3
|
|
|
|
fi
|
|
|
|
fi
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-09-06 10:55:57 -07:00
|
|
|
echo jq argument ${args[--jq]}
|
|
|
|
if [[ ${args[--jq]} ]];then
|
|
|
|
cmd="${cmd} | jq ${args[--jq]}"
|
|
|
|
fi
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
echo $cmd
|
|
|
|
confirm run this command? || return 1
|
|
|
|
eval $cmd
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# sudo chown -R $USER:$USER $target
|
|
|
|
# sudo chown -R $USER:$USER /home/$USER/.cache/restic
|
|
|
|
# sudo chmod -R g+rwX /home/$USER/.cache/restic
|
|
|
|
}
|
|
|
|
|
|
|
|
# :command.version_command
|
|
|
|
version_command() {
|
|
|
|
echo "$version"
|
|
|
|
}
|
|
|
|
|
|
|
|
# :command.usage
|
|
|
|
dbackup_usage() {
|
|
|
|
if [[ -n $long_usage ]]; then
|
|
|
|
printf "dbackup - differential backup using restic\n"
|
2021-12-04 22:14:09 -08:00
|
|
|
echo
|
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
else
|
|
|
|
printf "dbackup - differential backup using restic\n"
|
2021-12-04 22:14:09 -08:00
|
|
|
echo
|
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
fi
|
|
|
|
|
|
|
|
printf "Usage:\n"
|
|
|
|
printf " dbackup [SOURCE] [TARGET] [options]\n"
|
2021-09-06 10:55:57 -07:00
|
|
|
printf " dbackup --help | -h\n"
|
2021-08-29 08:01:40 -07:00
|
|
|
printf " dbackup --version\n"
|
|
|
|
echo
|
|
|
|
|
|
|
|
if [[ -n $long_usage ]]; then
|
|
|
|
printf "Options:\n"
|
|
|
|
# :command.usage_fixed_flags
|
2021-09-06 10:55:57 -07:00
|
|
|
echo " --help, -h"
|
2021-08-29 08:01:40 -07:00
|
|
|
printf " Show this help\n"
|
|
|
|
echo
|
|
|
|
echo " --version"
|
|
|
|
printf " Show version number\n"
|
|
|
|
echo
|
|
|
|
# :command.usage_flags
|
|
|
|
# :flag.usage
|
|
|
|
echo " --password, -p PASSWORD"
|
|
|
|
printf " repo password (or file path) for backup repository\n"
|
|
|
|
echo
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :flag.usage
|
|
|
|
echo " --remote, -r"
|
|
|
|
printf " backup to a remote machine\n"
|
|
|
|
echo
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :flag.usage
|
|
|
|
echo " --server URL"
|
|
|
|
printf " url of restic rest server\n"
|
|
|
|
echo
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :flag.usage
|
|
|
|
echo " --init"
|
|
|
|
printf " initialize repo (default is backup)\n"
|
|
|
|
echo
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :flag.usage
|
|
|
|
echo " --snap"
|
|
|
|
printf " list repo snapshots\n"
|
|
|
|
echo
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :flag.usage
|
|
|
|
echo " --view, -v"
|
|
|
|
printf " mount snapshot for viewing (default is BACKUP_MOUNT or /opt/backup/view)\n"
|
|
|
|
echo
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :flag.usage
|
|
|
|
echo " --view-path PATH"
|
2021-09-06 10:54:54 -07:00
|
|
|
printf " set custom mount point path for viewing of snapshot, --view not required if\n set\n"
|
2021-08-29 08:01:40 -07:00
|
|
|
echo
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :flag.usage
|
|
|
|
echo " --prune PRUNE"
|
|
|
|
printf " prune repo (default is backup). true for default prune or path to prune\n settings\n"
|
|
|
|
echo
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :flag.usage
|
|
|
|
echo " --password, -p PASSWORD"
|
|
|
|
printf " repo password (or file path) for backup repository\n"
|
|
|
|
echo
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :flag.usage
|
|
|
|
echo " --settings, -s SYAML"
|
|
|
|
printf " path to settings file (yaml). Keys are same as long\n"
|
|
|
|
echo
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :flag.usage
|
|
|
|
echo " --options, -o OPTIONS"
|
2021-09-06 10:55:57 -07:00
|
|
|
printf " additional options to pass ot underlying command (restic), \"quote\"\n"
|
2021-08-29 08:01:40 -07:00
|
|
|
echo
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :flag.usage
|
|
|
|
echo " --include_file, -i INCLUDE"
|
|
|
|
printf " include file\n"
|
|
|
|
echo
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :flag.usage
|
|
|
|
echo " --exclude_file, -e EXCLUDE"
|
|
|
|
printf " exclude file\n"
|
|
|
|
echo
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :flag.usage
|
2021-09-06 10:55:57 -07:00
|
|
|
echo " --sudo"
|
|
|
|
printf " run the backup as sudo\n"
|
|
|
|
echo
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-09-06 10:55:57 -07:00
|
|
|
# :flag.usage
|
|
|
|
echo " --jq JQ"
|
|
|
|
printf " pipe to jq command\n"
|
2021-08-29 08:01:40 -07:00
|
|
|
echo
|
|
|
|
# :command.usage_args
|
|
|
|
printf "Arguments:\n"
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :argument.usage
|
|
|
|
echo " SOURCE"
|
|
|
|
printf " source directory to be backed up, default is $PWD\n"
|
|
|
|
echo
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :argument.usage
|
|
|
|
echo " TARGET"
|
|
|
|
printf " target directory for backup\n"
|
|
|
|
echo
|
|
|
|
# :command.usage_environment_variables
|
|
|
|
printf "Environment Variables:\n"
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :environment_variable.usage
|
|
|
|
echo " BACKUP_EXCLUDE"
|
|
|
|
printf " path to file of excludes\n"
|
|
|
|
echo
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :environment_variable.usage
|
|
|
|
echo " BACKUP_INCLUDE"
|
|
|
|
printf " path to directory of includes\n"
|
|
|
|
echo
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :environment_variable.usage
|
|
|
|
echo " BACKUP_SETTINGS"
|
|
|
|
printf " path to default settings file\n"
|
|
|
|
echo
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :environment_variable.usage
|
|
|
|
echo " BACKUP_PASSWORD"
|
|
|
|
printf " path to default settings file\n"
|
|
|
|
echo
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :environment_variable.usage
|
|
|
|
echo " BACKUP_SERVER"
|
|
|
|
printf " URL of Restic rest server\n"
|
|
|
|
echo
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :environment_variable.usage
|
|
|
|
echo " BACKUP_DIR"
|
|
|
|
printf " Backup Directory\n"
|
|
|
|
echo
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-09-06 10:54:54 -07:00
|
|
|
# :environment_variable.usage
|
|
|
|
echo " BACKUP_MOUNT_POINT"
|
|
|
|
printf " mount point of source if mounted external to host\n"
|
|
|
|
echo
|
2021-08-29 08:01:40 -07:00
|
|
|
# :command.usage_examples
|
|
|
|
printf "Examples:\n"
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
printf " backup -p password . /target/dir\n"
|
|
|
|
printf " backup -s /path/to/settings/yaml/file\n"
|
|
|
|
echo
|
|
|
|
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-09-11 08:49:40 -07:00
|
|
|
# :command.normalize_input
|
|
|
|
normalize_input() {
|
|
|
|
local arg flags
|
|
|
|
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
arg="$1"
|
|
|
|
if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then
|
|
|
|
input+=("${BASH_REMATCH[1]}")
|
|
|
|
input+=("${BASH_REMATCH[2]}")
|
|
|
|
elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then
|
|
|
|
input+=("${BASH_REMATCH[1]}")
|
|
|
|
input+=("${BASH_REMATCH[2]}")
|
|
|
|
elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then
|
|
|
|
flags="${BASH_REMATCH[1]}"
|
|
|
|
for (( i=0 ; i < ${#flags} ; i++ )); do
|
|
|
|
input+=("-${flags:i:1}")
|
|
|
|
done
|
|
|
|
else
|
|
|
|
input+=("$arg")
|
|
|
|
fi
|
|
|
|
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
}
|
2021-08-29 08:01:40 -07:00
|
|
|
# :command.inspect_args
|
|
|
|
inspect_args() {
|
|
|
|
readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort)
|
|
|
|
if (( ${#args[@]} )); then
|
|
|
|
echo args:
|
|
|
|
for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done
|
|
|
|
else
|
|
|
|
echo args: none
|
|
|
|
fi
|
|
|
|
|
|
|
|
if (( ${#other_args[@]} )); then
|
|
|
|
echo
|
|
|
|
echo other_args:
|
|
|
|
echo "- \${other_args[*]} = ${other_args[*]}"
|
|
|
|
for i in "${!other_args[@]}"; do
|
|
|
|
echo "- \${other_args[$i]} = ${other_args[$i]}"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# :command.command_functions
|
|
|
|
|
|
|
|
# :command.parse_requirements
|
|
|
|
parse_requirements() {
|
|
|
|
# :command.fixed_flag_filter
|
2021-12-04 22:14:09 -08:00
|
|
|
case "${1:-}" in
|
2021-08-29 08:01:40 -07:00
|
|
|
--version )
|
|
|
|
version_command
|
|
|
|
exit
|
|
|
|
;;
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-09-06 10:55:57 -07:00
|
|
|
--help | -h )
|
2021-08-29 08:01:40 -07:00
|
|
|
long_usage=yes
|
|
|
|
dbackup_usage
|
2021-09-11 08:49:40 -07:00
|
|
|
exit
|
2021-08-29 08:01:40 -07:00
|
|
|
;;
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
esac
|
|
|
|
# :command.environment_variables_filter
|
|
|
|
# :command.dependencies_filter
|
|
|
|
# :command.command_filter
|
|
|
|
action="root"
|
|
|
|
# :command.parse_requirements_while
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
key="$1"
|
|
|
|
case "$key" in
|
|
|
|
# :flag.case
|
|
|
|
--password | -p )
|
2021-12-04 22:14:09 -08:00
|
|
|
if [[ -n ${2+x} ]]; then
|
|
|
|
# :flag.validations
|
2021-08-29 08:01:40 -07:00
|
|
|
args[--password]="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
printf "%s\n" "--password requires an argument: --password, -p PASSWORD"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :flag.case
|
|
|
|
--remote | -r )
|
|
|
|
args[--remote]=1
|
|
|
|
shift
|
|
|
|
;;
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :flag.case
|
|
|
|
--server )
|
2021-12-04 22:14:09 -08:00
|
|
|
if [[ -n ${2+x} ]]; then
|
|
|
|
# :flag.validations
|
2021-08-29 08:01:40 -07:00
|
|
|
args[--server]="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
printf "%s\n" "--server requires an argument: --server URL"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :flag.case
|
|
|
|
--init )
|
|
|
|
args[--init]=1
|
|
|
|
shift
|
|
|
|
;;
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :flag.case
|
|
|
|
--snap )
|
|
|
|
args[--snap]=1
|
|
|
|
shift
|
|
|
|
;;
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :flag.case
|
|
|
|
--view | -v )
|
|
|
|
args[--view]=1
|
|
|
|
shift
|
|
|
|
;;
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :flag.case
|
|
|
|
--view-path )
|
2021-12-04 22:14:09 -08:00
|
|
|
if [[ -n ${2+x} ]]; then
|
|
|
|
# :flag.validations
|
2021-08-29 08:01:40 -07:00
|
|
|
args[--view-path]="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
printf "%s\n" "--view-path requires an argument: --view-path PATH"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :flag.case
|
|
|
|
--prune )
|
2021-12-04 22:14:09 -08:00
|
|
|
if [[ -n ${2+x} ]]; then
|
|
|
|
# :flag.validations
|
2021-08-29 08:01:40 -07:00
|
|
|
args[--prune]="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
printf "%s\n" "--prune requires an argument: --prune PRUNE"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :flag.case
|
|
|
|
--password | -p )
|
2021-12-04 22:14:09 -08:00
|
|
|
if [[ -n ${2+x} ]]; then
|
|
|
|
# :flag.validations
|
2021-08-29 08:01:40 -07:00
|
|
|
args[--password]="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
printf "%s\n" "--password requires an argument: --password, -p PASSWORD"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :flag.case
|
|
|
|
--settings | -s )
|
2021-12-04 22:14:09 -08:00
|
|
|
if [[ -n ${2+x} ]]; then
|
|
|
|
# :flag.validations
|
2021-08-29 08:01:40 -07:00
|
|
|
args[--settings]="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
printf "%s\n" "--settings requires an argument: --settings, -s SYAML"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :flag.case
|
|
|
|
--options | -o )
|
2021-12-04 22:14:09 -08:00
|
|
|
if [[ -n ${2+x} ]]; then
|
|
|
|
# :flag.validations
|
2021-08-29 08:01:40 -07:00
|
|
|
args[--options]="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
printf "%s\n" "--options requires an argument: --options, -o OPTIONS"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :flag.case
|
|
|
|
--include_file | -i )
|
2021-12-04 22:14:09 -08:00
|
|
|
if [[ -n ${2+x} ]]; then
|
|
|
|
# :flag.validations
|
2021-08-29 08:01:40 -07:00
|
|
|
args[--include_file]="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
printf "%s\n" "--include_file requires an argument: --include_file, -i INCLUDE"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :flag.case
|
|
|
|
--exclude_file | -e )
|
2021-12-04 22:14:09 -08:00
|
|
|
if [[ -n ${2+x} ]]; then
|
|
|
|
# :flag.validations
|
2021-08-29 08:01:40 -07:00
|
|
|
args[--exclude_file]="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
printf "%s\n" "--exclude_file requires an argument: --exclude_file, -e EXCLUDE"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :flag.case
|
2021-09-06 10:55:57 -07:00
|
|
|
--sudo )
|
|
|
|
args[--sudo]=1
|
2021-08-29 08:01:40 -07:00
|
|
|
shift
|
|
|
|
;;
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-09-06 10:55:57 -07:00
|
|
|
# :flag.case
|
|
|
|
--jq )
|
2021-12-04 22:14:09 -08:00
|
|
|
if [[ -n ${2+x} ]]; then
|
|
|
|
# :flag.validations
|
2021-09-06 10:55:57 -07:00
|
|
|
args[--jq]="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
printf "%s\n" "--jq requires an argument: --jq JQ"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
-* )
|
|
|
|
printf "invalid option: %s\n" "$key"
|
|
|
|
exit 1
|
|
|
|
;;
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
* )
|
|
|
|
# :command.parse_requirements_case
|
2021-12-04 22:14:09 -08:00
|
|
|
if [[ -z ${args[source]+x} ]]; then
|
|
|
|
# :argument.validations
|
2021-08-29 08:01:40 -07:00
|
|
|
args[source]=$1
|
|
|
|
shift
|
2021-12-04 22:14:09 -08:00
|
|
|
elif [[ -z ${args[target]+x} ]]; then
|
|
|
|
# :argument.validations
|
2021-08-29 08:01:40 -07:00
|
|
|
args[target]=$1
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
printf "invalid argument: %s\n" "$key"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
2021-12-04 22:14:09 -08:00
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
esac
|
|
|
|
done
|
2021-12-04 22:14:09 -08:00
|
|
|
# :command.required_args_filter
|
|
|
|
# :command.required_flags_filter
|
2021-09-11 08:49:40 -07:00
|
|
|
# :command.catch_all_filter
|
2021-08-29 08:01:40 -07:00
|
|
|
# :command.default_assignments
|
|
|
|
# :command.whitelist_filter
|
|
|
|
}
|
|
|
|
|
|
|
|
# :command.initialize
|
|
|
|
initialize() {
|
|
|
|
version="0.1.0"
|
|
|
|
long_usage=''
|
2021-09-11 08:49:40 -07:00
|
|
|
set -e
|
|
|
|
|
2021-08-29 08:01:40 -07:00
|
|
|
# :src/initialize.sh
|
|
|
|
# Code here runs inside the initialize() function
|
|
|
|
# Use it for anything that you need to run before any other function, like
|
|
|
|
# setting environment vairables:
|
|
|
|
# CONFIG_FILE=settings.ini
|
|
|
|
#
|
|
|
|
# Feel free to empty (but not delete) this file.
|
|
|
|
echo running initialize function
|
|
|
|
}
|
|
|
|
|
|
|
|
# :command.run
|
|
|
|
run() {
|
2021-12-04 22:14:09 -08:00
|
|
|
declare -A args=()
|
|
|
|
declare -a other_args=()
|
|
|
|
declare -a input=()
|
2021-09-11 08:49:40 -07:00
|
|
|
normalize_input "$@"
|
|
|
|
parse_requirements "${input[@]}"
|
2021-08-29 08:01:40 -07:00
|
|
|
|
|
|
|
if [[ $action == "root" ]]; then
|
|
|
|
root_command
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
initialize
|
|
|
|
run "$@"
|