Merge remote-tracking branch 'origin/master' into trantor
commit
d3e19cd9d2
|
@ -1,364 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# This script was generated by bashly (https://github.com/DannyBen/bashly)
|
||||
# Modifying it manually is not recommended
|
||||
|
||||
# :command.root_command
|
||||
root_command() {
|
||||
# :src/root_command.sh
|
||||
echo Running Backup Command
|
||||
|
||||
inspect_args
|
||||
|
||||
# module_load ssh
|
||||
module_load confirm
|
||||
|
||||
local source=${args[source]}
|
||||
local target=${args[target]}
|
||||
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]}@)
|
||||
local mirror=${args[--mirror]}
|
||||
local options=$(echo ${args[--options]} | awk '{gsub(/\\/," ")}1')
|
||||
local sudo=$([[ ${args[--sudo]} ]] && echo sudo)
|
||||
local exclude=${args[--exclude_file]}
|
||||
|
||||
if [[ ! $exclude ]]; then
|
||||
[[ -f $source/exclude.bac ]] && exclude="$source/exclude.bac"
|
||||
# ls $source
|
||||
# [[ $EXCLUDE_BACKUP ]] && exclude="$BACKUP_EXCLUDE"
|
||||
fi
|
||||
echo making exclude
|
||||
[[ $exclude ]] && exclude="--exclude-globbing-filelist $exclude"
|
||||
|
||||
# local ssh="--remote-schema \"ssh -C %s /home/sysadmin/.local/bin/rdiff-backup --server\""
|
||||
|
||||
cmd="$sudo rdiff-backup $options $exclude $ssh ${suser}${shost}$source ${tuser}${thost}$target"
|
||||
echo $cmd
|
||||
confirm run this command? || return 1
|
||||
eval $cmd
|
||||
}
|
||||
|
||||
# :command.version_command
|
||||
version_command() {
|
||||
echo "$version"
|
||||
}
|
||||
|
||||
# :command.usage
|
||||
backup_usage() {
|
||||
if [[ -n $long_usage ]]; then
|
||||
printf "backup - backup/mirror a directory using rdiff or rsync\n"
|
||||
echo
|
||||
else
|
||||
printf "backup - backup/mirror a directory using rdiff or rsync\n"
|
||||
echo
|
||||
fi
|
||||
|
||||
printf "Usage:\n"
|
||||
printf " backup [SOURCE] [TARGET] [options]\n"
|
||||
printf " backup --help\n"
|
||||
printf " backup --version | -v\n"
|
||||
echo
|
||||
|
||||
if [[ -n $long_usage ]]; then
|
||||
printf "Options:\n"
|
||||
# :command.usage_fixed_flags
|
||||
echo " --help"
|
||||
printf " Show this help\n"
|
||||
echo
|
||||
echo " --version, -v"
|
||||
printf " Show version number\n"
|
||||
echo
|
||||
# :command.usage_flags
|
||||
# :flag.usage
|
||||
echo " --host, -h THOST"
|
||||
printf " host on remote to target to receive backup\n"
|
||||
echo
|
||||
|
||||
# :flag.usage
|
||||
echo " --shost SHOST"
|
||||
printf " remote to host of source\n"
|
||||
echo
|
||||
|
||||
# :flag.usage
|
||||
echo " --user, -u TUSER"
|
||||
printf " user on remote host\n"
|
||||
echo
|
||||
|
||||
# :flag.usage
|
||||
echo " --suser SUSER"
|
||||
printf " remote user on source host\n"
|
||||
echo
|
||||
|
||||
# :flag.usage
|
||||
echo " --sshcfg SSHCFG"
|
||||
printf " path to sshcfg file\n"
|
||||
echo
|
||||
|
||||
# :flag.usage
|
||||
echo " --options, -o OPTIONS"
|
||||
printf " rdiff options\n"
|
||||
echo
|
||||
|
||||
# :flag.usage
|
||||
echo " --include_file, -i OPTIONS"
|
||||
printf " rdiff options\n"
|
||||
echo
|
||||
|
||||
# :flag.usage
|
||||
echo " --exclude_file, -e OPTIONS"
|
||||
printf " rdiff options\n"
|
||||
echo
|
||||
|
||||
# :flag.usage
|
||||
echo " --mirror, -m"
|
||||
printf " make a mirror copy instead of a differential snapshot\n"
|
||||
echo
|
||||
|
||||
# :flag.usage
|
||||
echo " --sudo, -s"
|
||||
printf " run the backup as sudo\n"
|
||||
echo
|
||||
|
||||
# :flag.usage
|
||||
echo " --no-dir, -n"
|
||||
printf " don't make a directory of same name within the target, merge sub directories\n"
|
||||
echo
|
||||
# :command.usage_args
|
||||
printf "Arguments:\n"
|
||||
|
||||
# :argument.usage
|
||||
echo " SOURCE"
|
||||
printf " source directory to be backed up, default is $PWD\n"
|
||||
echo
|
||||
|
||||
# :argument.usage
|
||||
echo " TARGET"
|
||||
printf " target directory for backup\n"
|
||||
echo
|
||||
# :command.usage_environment_variables
|
||||
printf "Environment Variables:\n"
|
||||
|
||||
# :environment_variable.usage
|
||||
echo " BACKUP_EXCLUDE"
|
||||
printf " path to file of excludes\n"
|
||||
echo
|
||||
|
||||
# :environment_variable.usage
|
||||
echo " BACKUP_INCLUDE"
|
||||
printf " path to directory of includes\n"
|
||||
echo
|
||||
# :command.usage_examples
|
||||
printf "Examples:\n"
|
||||
|
||||
printf " backup -m -n -h thost --shost shost -u tuser --suser suser . /target/dir\n"
|
||||
echo
|
||||
|
||||
fi
|
||||
}
|
||||
|
||||
# :command.inspect_args
|
||||
inspect_args() {
|
||||
echo args:
|
||||
for k in "${!args[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done
|
||||
}
|
||||
|
||||
# :command.command_functions
|
||||
|
||||
# :command.parse_requirements
|
||||
parse_requirements() {
|
||||
# :command.fixed_flag_filter
|
||||
case "$1" in
|
||||
--version | -v )
|
||||
version_command
|
||||
exit
|
||||
;;
|
||||
|
||||
--help )
|
||||
long_usage=yes
|
||||
backup_usage
|
||||
exit 1
|
||||
;;
|
||||
|
||||
esac
|
||||
# :command.environment_variables_filter
|
||||
# :command.dependencies_filter
|
||||
# :command.command_filter
|
||||
action="root"
|
||||
# :command.required_args_filter
|
||||
# :command.required_flags_filter
|
||||
# :command.parse_requirements_while
|
||||
while [[ $# -gt 0 ]]; do
|
||||
key="$1"
|
||||
case "$key" in
|
||||
# :flag.case
|
||||
--host | -h )
|
||||
if [[ $2 && $2 != -* ]]; then
|
||||
args[--host]="$2"
|
||||
shift
|
||||
shift
|
||||
else
|
||||
printf "%s\n" "--host requires an argument: --host, -h THOST"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
# :flag.case
|
||||
--shost )
|
||||
if [[ $2 && $2 != -* ]]; then
|
||||
args[--shost]="$2"
|
||||
shift
|
||||
shift
|
||||
else
|
||||
printf "%s\n" "--shost requires an argument: --shost SHOST"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
# :flag.case
|
||||
--user | -u )
|
||||
if [[ $2 && $2 != -* ]]; then
|
||||
args[--user]="$2"
|
||||
shift
|
||||
shift
|
||||
else
|
||||
printf "%s\n" "--user requires an argument: --user, -u TUSER"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
# :flag.case
|
||||
--suser )
|
||||
if [[ $2 && $2 != -* ]]; then
|
||||
args[--suser]="$2"
|
||||
shift
|
||||
shift
|
||||
else
|
||||
printf "%s\n" "--suser requires an argument: --suser SUSER"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
# :flag.case
|
||||
--sshcfg )
|
||||
if [[ $2 && $2 != -* ]]; then
|
||||
args[--sshcfg]="$2"
|
||||
shift
|
||||
shift
|
||||
else
|
||||
printf "%s\n" "--sshcfg requires an argument: --sshcfg SSHCFG"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
# :flag.case
|
||||
--options | -o )
|
||||
if [[ $2 && $2 != -* ]]; then
|
||||
args[--options]="$2"
|
||||
shift
|
||||
shift
|
||||
else
|
||||
printf "%s\n" "--options requires an argument: --options, -o OPTIONS"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
# :flag.case
|
||||
--include_file | -i )
|
||||
if [[ $2 && $2 != -* ]]; then
|
||||
args[--include_file]="$2"
|
||||
shift
|
||||
shift
|
||||
else
|
||||
printf "%s\n" "--include_file requires an argument: --include_file, -i OPTIONS"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
# :flag.case
|
||||
--exclude_file | -e )
|
||||
if [[ $2 && $2 != -* ]]; then
|
||||
args[--exclude_file]="$2"
|
||||
shift
|
||||
shift
|
||||
else
|
||||
printf "%s\n" "--exclude_file requires an argument: --exclude_file, -e OPTIONS"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
# :flag.case
|
||||
--mirror | -m )
|
||||
args[--mirror]=1
|
||||
shift
|
||||
;;
|
||||
|
||||
# :flag.case
|
||||
--sudo | -s )
|
||||
args[--sudo]=1
|
||||
shift
|
||||
;;
|
||||
|
||||
# :flag.case
|
||||
--no-dir | -n )
|
||||
args[--no-dir]=1
|
||||
shift
|
||||
;;
|
||||
|
||||
|
||||
-* )
|
||||
printf "invalid option: %s\n" "$key"
|
||||
exit 1
|
||||
;;
|
||||
|
||||
* )
|
||||
# :command.parse_requirements_case
|
||||
if [[ ! ${args[source]} ]]; then
|
||||
args[source]=$1
|
||||
shift
|
||||
elif [[ ! ${args[target]} ]]; then
|
||||
args[target]=$1
|
||||
shift
|
||||
else
|
||||
printf "invalid argument: %s\n" "$key"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
# :command.default_assignments
|
||||
}
|
||||
|
||||
# :command.initialize
|
||||
initialize() {
|
||||
version="0.1.0"
|
||||
long_usage=''
|
||||
set -e
|
||||
|
||||
# :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.
|
||||
}
|
||||
|
||||
# :command.run
|
||||
run() {
|
||||
declare -A args
|
||||
parse_requirements "$@"
|
||||
|
||||
if [[ ${args[--version]} ]]; then
|
||||
version_command
|
||||
elif [[ ${args[--help]} ]]; then
|
||||
long_usage=yes
|
||||
backup_usage
|
||||
elif [[ $action == "root" ]]; then
|
||||
root_command
|
||||
fi
|
||||
}
|
||||
|
||||
initialize
|
||||
run "$@"
|
|
@ -2,21 +2,27 @@
|
|||
# This script was generated by bashly (https://github.com/DannyBen/bashly)
|
||||
# Modifying it manually is not recommended
|
||||
|
||||
# :script.bash3_bouncer
|
||||
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
|
||||
printf "bash version 4 or higher is required\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# :command.root_command
|
||||
root_command() {
|
||||
# :src/root_command.sh
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
echo "running root command"
|
||||
|
||||
|
||||
inspect_args
|
||||
|
||||
|
||||
# module_load ssh
|
||||
module_load confirm
|
||||
module_load path
|
||||
|
||||
|
||||
local settings=${args[--settings]}
|
||||
|
||||
|
||||
if [[ $settings ]]; then
|
||||
if [[ -f $settings ]]; then
|
||||
echo loading settings file $settings
|
||||
|
@ -29,48 +35,47 @@ root_command() {
|
|||
echo settings file $settings does not exist && return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
if [[ $s_server_host ]]; then
|
||||
s_server="http$([[ $s_server_secure ]] && echo "s")://${s_server_host}$([[ $s_server_port ]] && echo :${s_server_port} || echo "")"
|
||||
fi
|
||||
|
||||
|
||||
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}"
|
||||
|
||||
|
||||
local server=${args[--server]:-$BACKUP_SERVER}
|
||||
server=${server:-$s_server}
|
||||
|
||||
|
||||
local hostname=${args[--hostname]:-$s_hostname}
|
||||
hostname=${hostname:-$s_host}
|
||||
hostname=${hostname:-$HOSTNAME}
|
||||
|
||||
|
||||
local options="${args[--options]:-$BACKUP_OPTIONS}"
|
||||
options="${options:-$s_options}"
|
||||
|
||||
|
||||
local smount=${args[--source_mount]:-$BACKUP_SOURCE_MOUNT}
|
||||
smount=${smount:-$s_source_mount}
|
||||
|
||||
|
||||
echo smount: $smount $s_source_mount
|
||||
|
||||
|
||||
|
||||
local tmount=${args[--target_mount]:-$BACKUP_TARGET_MOUNT}
|
||||
tmount=${tmount:-$s_target_mount}
|
||||
|
||||
|
||||
echo tmount: $tmount $s_target_mount
|
||||
|
||||
|
||||
local source="${args[source]:-$s_source}"
|
||||
source="${source:-$s_source_path}"
|
||||
source=$(echo "${source:-$PWD}" | tr -s /)
|
||||
|
||||
|
||||
echo yaml source $s_source_path $s_source_mount
|
||||
echo source $source
|
||||
|
||||
|
||||
echo target $s_target
|
||||
|
||||
|
||||
echo target path $s_target_path
|
||||
|
||||
|
||||
local target=${args[target]:-$s_target}
|
||||
target=${target:-$s_target_path}
|
||||
target=${target:-$(echo "${source}" | tr -s / | sed -e "s#^[.]##")}
|
||||
|
@ -81,42 +86,41 @@ root_command() {
|
|||
else
|
||||
target="/${hostname}${target}"
|
||||
fi
|
||||
|
||||
|
||||
if [[ $server ]]; then
|
||||
target="rest:${server}${target}"
|
||||
fi
|
||||
|
||||
|
||||
if [[ $smount ]]; then
|
||||
setpath="--set-path ${source} --tag mount-point:${smount}"
|
||||
source=${smount}${source}
|
||||
fi
|
||||
|
||||
|
||||
local exclude=${args[--exclude_file]:-$BACKUP_EXCLUDE}
|
||||
exclude=${exclude:-$s_exclude}
|
||||
exclude=${exclude:-"$source/exclude.bac"}
|
||||
|
||||
|
||||
|
||||
# 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]}@)
|
||||
|
||||
|
||||
local options=$(echo ${args[--options]} | awk '{gsub(/\\/," ")}1')
|
||||
|
||||
|
||||
local bin=$(command -v restic)
|
||||
|
||||
|
||||
exclude=$([[ -f $exclude ]] && echo "--iexclude-file $exclude" || echo "")
|
||||
|
||||
|
||||
echo source: $source
|
||||
echo target $target
|
||||
echo exclude: $exclude
|
||||
|
||||
|
||||
local sudo=$([[ ${args[--sudo]} || $s_sudo || $BACKUP_SUDO ]] && echo "sudo" || echo "")
|
||||
|
||||
|
||||
local pcmd="${sudo} ${password} ${bin} ${options} -r ${target}"
|
||||
|
||||
|
||||
local cmd="${pcmd} -H ${hostname} ${setpath} backup ${source} ${exclude}"
|
||||
|
||||
|
||||
if [[ ${args[--init]} ]]; then cmd="${pcmd} init"; fi
|
||||
if [[ ${args[--snap]} ]]; then cmd="${pcmd} snapshots"; fi
|
||||
if [[ ${args[--prune]} ]]; then cmd="${pcmd} prune"; fi
|
||||
|
@ -132,16 +136,16 @@ root_command() {
|
|||
return 3
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
echo jq argument ${args[--jq]}
|
||||
if [[ ${args[--jq]} ]];then
|
||||
cmd="${cmd} | jq ${args[--jq]}"
|
||||
fi
|
||||
|
||||
|
||||
echo $cmd
|
||||
confirm run this command? || return 1
|
||||
eval $cmd
|
||||
|
||||
|
||||
# sudo chown -R $USER:$USER $target
|
||||
# sudo chown -R $USER:$USER /home/$USER/.cache/restic
|
||||
# sudo chmod -R g+rwX /home/$USER/.cache/restic
|
||||
|
@ -156,10 +160,12 @@ version_command() {
|
|||
dbackup_usage() {
|
||||
if [[ -n $long_usage ]]; then
|
||||
printf "dbackup - differential backup using restic\n"
|
||||
echo
|
||||
echo
|
||||
|
||||
else
|
||||
printf "dbackup - differential backup using restic\n"
|
||||
echo
|
||||
echo
|
||||
|
||||
fi
|
||||
|
||||
printf "Usage:\n"
|
||||
|
@ -182,128 +188,128 @@ dbackup_usage() {
|
|||
echo " --password, -p PASSWORD"
|
||||
printf " repo password (or file path) for backup repository\n"
|
||||
echo
|
||||
|
||||
|
||||
# :flag.usage
|
||||
echo " --remote, -r"
|
||||
printf " backup to a remote machine\n"
|
||||
echo
|
||||
|
||||
|
||||
# :flag.usage
|
||||
echo " --server URL"
|
||||
printf " url of restic rest server\n"
|
||||
echo
|
||||
|
||||
|
||||
# :flag.usage
|
||||
echo " --init"
|
||||
printf " initialize repo (default is backup)\n"
|
||||
echo
|
||||
|
||||
|
||||
# :flag.usage
|
||||
echo " --snap"
|
||||
printf " list repo snapshots\n"
|
||||
echo
|
||||
|
||||
|
||||
# :flag.usage
|
||||
echo " --view, -v"
|
||||
printf " mount snapshot for viewing (default is BACKUP_MOUNT or /opt/backup/view)\n"
|
||||
echo
|
||||
|
||||
|
||||
# :flag.usage
|
||||
echo " --view-path PATH"
|
||||
printf " set custom mount point path for viewing of snapshot, --view not required if\n set\n"
|
||||
echo
|
||||
|
||||
|
||||
# :flag.usage
|
||||
echo " --prune PRUNE"
|
||||
printf " prune repo (default is backup). true for default prune or path to prune\n settings\n"
|
||||
echo
|
||||
|
||||
|
||||
# :flag.usage
|
||||
echo " --password, -p PASSWORD"
|
||||
printf " repo password (or file path) for backup repository\n"
|
||||
echo
|
||||
|
||||
|
||||
# :flag.usage
|
||||
echo " --settings, -s SYAML"
|
||||
printf " path to settings file (yaml). Keys are same as long\n"
|
||||
echo
|
||||
|
||||
|
||||
# :flag.usage
|
||||
echo " --options, -o OPTIONS"
|
||||
printf " additional options to pass ot underlying command (restic), \"quote\"\n"
|
||||
echo
|
||||
|
||||
|
||||
# :flag.usage
|
||||
echo " --include_file, -i INCLUDE"
|
||||
printf " include file\n"
|
||||
echo
|
||||
|
||||
|
||||
# :flag.usage
|
||||
echo " --exclude_file, -e EXCLUDE"
|
||||
printf " exclude file\n"
|
||||
echo
|
||||
|
||||
|
||||
# :flag.usage
|
||||
echo " --sudo"
|
||||
printf " run the backup as sudo\n"
|
||||
echo
|
||||
|
||||
|
||||
# :flag.usage
|
||||
echo " --jq JQ"
|
||||
printf " pipe to jq command\n"
|
||||
echo
|
||||
# :command.usage_args
|
||||
printf "Arguments:\n"
|
||||
|
||||
|
||||
# :argument.usage
|
||||
echo " SOURCE"
|
||||
printf " source directory to be backed up, default is $PWD\n"
|
||||
echo
|
||||
|
||||
|
||||
# :argument.usage
|
||||
echo " TARGET"
|
||||
printf " target directory for backup\n"
|
||||
echo
|
||||
# :command.usage_environment_variables
|
||||
printf "Environment Variables:\n"
|
||||
|
||||
|
||||
# :environment_variable.usage
|
||||
echo " BACKUP_EXCLUDE"
|
||||
printf " path to file of excludes\n"
|
||||
echo
|
||||
|
||||
|
||||
# :environment_variable.usage
|
||||
echo " BACKUP_INCLUDE"
|
||||
printf " path to directory of includes\n"
|
||||
echo
|
||||
|
||||
|
||||
# :environment_variable.usage
|
||||
echo " BACKUP_SETTINGS"
|
||||
printf " path to default settings file\n"
|
||||
echo
|
||||
|
||||
|
||||
# :environment_variable.usage
|
||||
echo " BACKUP_PASSWORD"
|
||||
printf " path to default settings file\n"
|
||||
echo
|
||||
|
||||
|
||||
# :environment_variable.usage
|
||||
echo " BACKUP_SERVER"
|
||||
printf " URL of Restic rest server\n"
|
||||
echo
|
||||
|
||||
|
||||
# :environment_variable.usage
|
||||
echo " BACKUP_DIR"
|
||||
printf " Backup Directory\n"
|
||||
echo
|
||||
|
||||
|
||||
# :environment_variable.usage
|
||||
echo " BACKUP_MOUNT_POINT"
|
||||
printf " mount point of source if mounted external to host\n"
|
||||
echo
|
||||
# :command.usage_examples
|
||||
printf "Examples:\n"
|
||||
|
||||
|
||||
printf " backup -p password . /target/dir\n"
|
||||
printf " backup -s /path/to/settings/yaml/file\n"
|
||||
echo
|
||||
|
@ -360,32 +366,31 @@ inspect_args() {
|
|||
# :command.parse_requirements
|
||||
parse_requirements() {
|
||||
# :command.fixed_flag_filter
|
||||
case "$1" in
|
||||
case "${1:-}" in
|
||||
--version )
|
||||
version_command
|
||||
exit
|
||||
;;
|
||||
|
||||
|
||||
--help | -h )
|
||||
long_usage=yes
|
||||
dbackup_usage
|
||||
exit
|
||||
;;
|
||||
|
||||
|
||||
esac
|
||||
# :command.environment_variables_filter
|
||||
# :command.dependencies_filter
|
||||
# :command.command_filter
|
||||
action="root"
|
||||
# :command.required_args_filter
|
||||
# :command.required_flags_filter
|
||||
# :command.parse_requirements_while
|
||||
while [[ $# -gt 0 ]]; do
|
||||
key="$1"
|
||||
case "$key" in
|
||||
# :flag.case
|
||||
--password | -p )
|
||||
if [[ $2 ]]; then
|
||||
if [[ -n ${2+x} ]]; then
|
||||
# :flag.validations
|
||||
args[--password]="$2"
|
||||
shift
|
||||
shift
|
||||
|
@ -394,16 +399,17 @@ parse_requirements() {
|
|||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
|
||||
# :flag.case
|
||||
--remote | -r )
|
||||
args[--remote]=1
|
||||
shift
|
||||
;;
|
||||
|
||||
|
||||
# :flag.case
|
||||
--server )
|
||||
if [[ $2 ]]; then
|
||||
if [[ -n ${2+x} ]]; then
|
||||
# :flag.validations
|
||||
args[--server]="$2"
|
||||
shift
|
||||
shift
|
||||
|
@ -412,28 +418,29 @@ parse_requirements() {
|
|||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
|
||||
# :flag.case
|
||||
--init )
|
||||
args[--init]=1
|
||||
shift
|
||||
;;
|
||||
|
||||
|
||||
# :flag.case
|
||||
--snap )
|
||||
args[--snap]=1
|
||||
shift
|
||||
;;
|
||||
|
||||
|
||||
# :flag.case
|
||||
--view | -v )
|
||||
args[--view]=1
|
||||
shift
|
||||
;;
|
||||
|
||||
|
||||
# :flag.case
|
||||
--view-path )
|
||||
if [[ $2 ]]; then
|
||||
if [[ -n ${2+x} ]]; then
|
||||
# :flag.validations
|
||||
args[--view-path]="$2"
|
||||
shift
|
||||
shift
|
||||
|
@ -442,10 +449,11 @@ parse_requirements() {
|
|||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
|
||||
# :flag.case
|
||||
--prune )
|
||||
if [[ $2 ]]; then
|
||||
if [[ -n ${2+x} ]]; then
|
||||
# :flag.validations
|
||||
args[--prune]="$2"
|
||||
shift
|
||||
shift
|
||||
|
@ -454,10 +462,11 @@ parse_requirements() {
|
|||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
|
||||
# :flag.case
|
||||
--password | -p )
|
||||
if [[ $2 ]]; then
|
||||
if [[ -n ${2+x} ]]; then
|
||||
# :flag.validations
|
||||
args[--password]="$2"
|
||||
shift
|
||||
shift
|
||||
|
@ -466,10 +475,11 @@ parse_requirements() {
|
|||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
|
||||
# :flag.case
|
||||
--settings | -s )
|
||||
if [[ $2 ]]; then
|
||||
if [[ -n ${2+x} ]]; then
|
||||
# :flag.validations
|
||||
args[--settings]="$2"
|
||||
shift
|
||||
shift
|
||||
|
@ -478,10 +488,11 @@ parse_requirements() {
|
|||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
|
||||
# :flag.case
|
||||
--options | -o )
|
||||
if [[ $2 ]]; then
|
||||
if [[ -n ${2+x} ]]; then
|
||||
# :flag.validations
|
||||
args[--options]="$2"
|
||||
shift
|
||||
shift
|
||||
|
@ -490,10 +501,11 @@ parse_requirements() {
|
|||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
|
||||
# :flag.case
|
||||
--include_file | -i )
|
||||
if [[ $2 ]]; then
|
||||
if [[ -n ${2+x} ]]; then
|
||||
# :flag.validations
|
||||
args[--include_file]="$2"
|
||||
shift
|
||||
shift
|
||||
|
@ -502,10 +514,11 @@ parse_requirements() {
|
|||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
|
||||
# :flag.case
|
||||
--exclude_file | -e )
|
||||
if [[ $2 ]]; then
|
||||
if [[ -n ${2+x} ]]; then
|
||||
# :flag.validations
|
||||
args[--exclude_file]="$2"
|
||||
shift
|
||||
shift
|
||||
|
@ -514,16 +527,17 @@ parse_requirements() {
|
|||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
|
||||
# :flag.case
|
||||
--sudo )
|
||||
args[--sudo]=1
|
||||
shift
|
||||
;;
|
||||
|
||||
|
||||
# :flag.case
|
||||
--jq )
|
||||
if [[ $2 ]]; then
|
||||
if [[ -n ${2+x} ]]; then
|
||||
# :flag.validations
|
||||
args[--jq]="$2"
|
||||
shift
|
||||
shift
|
||||
|
@ -532,19 +546,20 @@ parse_requirements() {
|
|||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
|
||||
|
||||
-* )
|
||||
printf "invalid option: %s\n" "$key"
|
||||
exit 1
|
||||
;;
|
||||
|
||||
|
||||
* )
|
||||
# :command.parse_requirements_case
|
||||
if [[ ! ${args[source]} ]]; then
|
||||
if [[ -z ${args[source]+x} ]]; then
|
||||
# :argument.validations
|
||||
args[source]=$1
|
||||
shift
|
||||
elif [[ ! ${args[target]} ]]; then
|
||||
elif [[ -z ${args[target]+x} ]]; then
|
||||
# :argument.validations
|
||||
args[target]=$1
|
||||
shift
|
||||
else
|
||||
|
@ -552,9 +567,11 @@ parse_requirements() {
|
|||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
|
||||
esac
|
||||
done
|
||||
# :command.required_args_filter
|
||||
# :command.required_flags_filter
|
||||
# :command.catch_all_filter
|
||||
# :command.default_assignments
|
||||
# :command.whitelist_filter
|
||||
|
@ -566,11 +583,6 @@ initialize() {
|
|||
long_usage=''
|
||||
set -e
|
||||
|
||||
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
|
||||
printf "bash version 4 or higher is required\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# :src/initialize.sh
|
||||
# Code here runs inside the initialize() function
|
||||
# Use it for anything that you need to run before any other function, like
|
||||
|
@ -583,9 +595,9 @@ initialize() {
|
|||
|
||||
# :command.run
|
||||
run() {
|
||||
declare -A args
|
||||
declare -a other_args
|
||||
declare -a input
|
||||
declare -A args=()
|
||||
declare -a other_args=()
|
||||
declare -a input=()
|
||||
normalize_input "$@"
|
||||
parse_requirements "${input[@]}"
|
||||
|
||||
|
|
|
@ -0,0 +1,598 @@
|
|||
#!/usr/bin/env bash
|
||||
# This script was generated by bashly (https://github.com/DannyBen/bashly)
|
||||
# Modifying it manually is not recommended
|
||||
|
||||
# :command.root_command
|
||||
root_command() {
|
||||
# :src/root_command.sh
|
||||
#!/bin/bash
|
||||
|
||||
echo "running root command"
|
||||
|
||||
inspect_args
|
||||
|
||||
# module_load ssh
|
||||
module_load confirm
|
||||
module_load path
|
||||
|
||||
local settings=${args[--settings]}
|
||||
|
||||
if [[ $settings ]]; then
|
||||
if [[ -f $settings ]]; then
|
||||
echo loading settings file $settings
|
||||
module_load yaml
|
||||
eval $(parse_yaml $settings "s_")
|
||||
echo $s_source
|
||||
echo $s_target
|
||||
echo $s_host
|
||||
else
|
||||
echo settings file $settings does not exist && return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $s_server_host ]]; then
|
||||
s_server="http$([[ $s_server_secure ]] && echo "s")://${s_server_host}$([[ $s_server_port ]] && echo :${s_server_port} || echo "")"
|
||||
fi
|
||||
|
||||
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}"
|
||||
|
||||
local server=${args[--server]:-$BACKUP_SERVER}
|
||||
server=${server:-$s_server}
|
||||
|
||||
local hostname=${args[--hostname]:-$s_hostname}
|
||||
hostname=${hostname:-$s_host}
|
||||
hostname=${hostname:-$HOSTNAME}
|
||||
|
||||
local options="${args[--options]:-$BACKUP_OPTIONS}"
|
||||
options="${options:-$s_options}"
|
||||
|
||||
local smount=${args[--source_mount]:-$BACKUP_SOURCE_MOUNT}
|
||||
smount=${smount:-$s_source_mount}
|
||||
|
||||
echo smount: $smount $s_source_mount
|
||||
|
||||
|
||||
local tmount=${args[--target_mount]:-$BACKUP_TARGET_MOUNT}
|
||||
tmount=${tmount:-$s_target_mount}
|
||||
|
||||
echo tmount: $tmount $s_target_mount
|
||||
|
||||
local source="${args[source]:-$s_source}"
|
||||
source="${source:-$s_source_path}"
|
||||
source=$(echo "${source:-$PWD}" | tr -s /)
|
||||
|
||||
echo yaml source $s_source_path $s_source_mount
|
||||
echo source $source
|
||||
|
||||
echo target $s_target
|
||||
|
||||
echo target path $s_target_path
|
||||
|
||||
local target=${args[target]:-$s_target}
|
||||
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}"
|
||||
else
|
||||
target="/${hostname}${target}"
|
||||
fi
|
||||
|
||||
if [[ $server ]]; then
|
||||
target="rest:${server}${target}"
|
||||
fi
|
||||
|
||||
if [[ $smount ]]; then
|
||||
setpath="--set-path ${source} --tag mount-point:${smount}"
|
||||
source=${smount}${source}
|
||||
fi
|
||||
|
||||
local exclude=${args[--exclude_file]:-$BACKUP_EXCLUDE}
|
||||
exclude=${exclude:-$s_exclude}
|
||||
exclude=${exclude:-"$source/exclude.bac"}
|
||||
|
||||
|
||||
# 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]}@)
|
||||
|
||||
local options=$(echo ${args[--options]} | awk '{gsub(/\\/," ")}1')
|
||||
|
||||
local bin=$(command -v restic)
|
||||
|
||||
exclude=$([[ -f $exclude ]] && echo "--iexclude-file $exclude" || echo "")
|
||||
|
||||
echo source: $source
|
||||
echo target $target
|
||||
echo exclude: $exclude
|
||||
|
||||
local sudo=$([[ ${args[--sudo]} || $s_sudo || $BACKUP_SUDO ]] && echo "sudo" || echo "")
|
||||
|
||||
local pcmd="${sudo} ${password} ${bin} ${options} -r ${target}"
|
||||
|
||||
local cmd="${pcmd} -H ${hostname} ${setpath} backup ${source} ${exclude}"
|
||||
|
||||
if [[ ${args[--init]} ]]; then cmd="${pcmd} init"; fi
|
||||
if [[ ${args[--snap]} ]]; then cmd="${pcmd} snapshots"; fi
|
||||
if [[ ${args[--prune]} ]]; then cmd="${pcmd} prune"; fi
|
||||
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
|
||||
cmd="${pcmd} mount $mount";
|
||||
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
|
||||
|
||||
echo jq argument ${args[--jq]}
|
||||
if [[ ${args[--jq]} ]];then
|
||||
cmd="${cmd} | jq ${args[--jq]}"
|
||||
fi
|
||||
|
||||
echo $cmd
|
||||
confirm run this command? || return 1
|
||||
eval $cmd
|
||||
|
||||
# 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"
|
||||
echo
|
||||
else
|
||||
printf "dbackup - differential backup using restic\n"
|
||||
echo
|
||||
fi
|
||||
|
||||
printf "Usage:\n"
|
||||
printf " dbackup [SOURCE] [TARGET] [options]\n"
|
||||
printf " dbackup --help | -h\n"
|
||||
printf " dbackup --version\n"
|
||||
echo
|
||||
|
||||
if [[ -n $long_usage ]]; then
|
||||
printf "Options:\n"
|
||||
# :command.usage_fixed_flags
|
||||
echo " --help, -h"
|
||||
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
|
||||
|
||||
# :flag.usage
|
||||
echo " --remote, -r"
|
||||
printf " backup to a remote machine\n"
|
||||
echo
|
||||
|
||||
# :flag.usage
|
||||
echo " --server URL"
|
||||
printf " url of restic rest server\n"
|
||||
echo
|
||||
|
||||
# :flag.usage
|
||||
echo " --init"
|
||||
printf " initialize repo (default is backup)\n"
|
||||
echo
|
||||
|
||||
# :flag.usage
|
||||
echo " --snap"
|
||||
printf " list repo snapshots\n"
|
||||
echo
|
||||
|
||||
# :flag.usage
|
||||
echo " --view, -v"
|
||||
printf " mount snapshot for viewing (default is BACKUP_MOUNT or /opt/backup/view)\n"
|
||||
echo
|
||||
|
||||
# :flag.usage
|
||||
echo " --view-path PATH"
|
||||
printf " set custom mount point path for viewing of snapshot, --view not required if\n set\n"
|
||||
echo
|
||||
|
||||
# :flag.usage
|
||||
echo " --prune PRUNE"
|
||||
printf " prune repo (default is backup). true for default prune or path to prune\n settings\n"
|
||||
echo
|
||||
|
||||
# :flag.usage
|
||||
echo " --password, -p PASSWORD"
|
||||
printf " repo password (or file path) for backup repository\n"
|
||||
echo
|
||||
|
||||
# :flag.usage
|
||||
echo " --settings, -s SYAML"
|
||||
printf " path to settings file (yaml). Keys are same as long\n"
|
||||
echo
|
||||
|
||||
# :flag.usage
|
||||
echo " --options, -o OPTIONS"
|
||||
printf " additional options to pass ot underlying command (restic), \"quote\"\n"
|
||||
echo
|
||||
|
||||
# :flag.usage
|
||||
echo " --include_file, -i INCLUDE"
|
||||
printf " include file\n"
|
||||
echo
|
||||
|
||||
# :flag.usage
|
||||
echo " --exclude_file, -e EXCLUDE"
|
||||
printf " exclude file\n"
|
||||
echo
|
||||
|
||||
# :flag.usage
|
||||
echo " --sudo"
|
||||
printf " run the backup as sudo\n"
|
||||
echo
|
||||
|
||||
# :flag.usage
|
||||
echo " --jq JQ"
|
||||
printf " pipe to jq command\n"
|
||||
echo
|
||||
# :command.usage_args
|
||||
printf "Arguments:\n"
|
||||
|
||||
# :argument.usage
|
||||
echo " SOURCE"
|
||||
printf " source directory to be backed up, default is $PWD\n"
|
||||
echo
|
||||
|
||||
# :argument.usage
|
||||
echo " TARGET"
|
||||
printf " target directory for backup\n"
|
||||
echo
|
||||
# :command.usage_environment_variables
|
||||
printf "Environment Variables:\n"
|
||||
|
||||
# :environment_variable.usage
|
||||
echo " BACKUP_EXCLUDE"
|
||||
printf " path to file of excludes\n"
|
||||
echo
|
||||
|
||||
# :environment_variable.usage
|
||||
echo " BACKUP_INCLUDE"
|
||||
printf " path to directory of includes\n"
|
||||
echo
|
||||
|
||||
# :environment_variable.usage
|
||||
echo " BACKUP_SETTINGS"
|
||||
printf " path to default settings file\n"
|
||||
echo
|
||||
|
||||
# :environment_variable.usage
|
||||
echo " BACKUP_PASSWORD"
|
||||
printf " path to default settings file\n"
|
||||
echo
|
||||
|
||||
# :environment_variable.usage
|
||||
echo " BACKUP_SERVER"
|
||||
printf " URL of Restic rest server\n"
|
||||
echo
|
||||
|
||||
# :environment_variable.usage
|
||||
echo " BACKUP_DIR"
|
||||
printf " Backup Directory\n"
|
||||
echo
|
||||
|
||||
# :environment_variable.usage
|
||||
echo " BACKUP_MOUNT_POINT"
|
||||
printf " mount point of source if mounted external to host\n"
|
||||
echo
|
||||
# :command.usage_examples
|
||||
printf "Examples:\n"
|
||||
|
||||
printf " backup -p password . /target/dir\n"
|
||||
printf " backup -s /path/to/settings/yaml/file\n"
|
||||
echo
|
||||
|
||||
fi
|
||||
}
|
||||
|
||||
# :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
|
||||
}
|
||||
# :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
|
||||
case "$1" in
|
||||
--version )
|
||||
version_command
|
||||
exit
|
||||
;;
|
||||
|
||||
--help | -h )
|
||||
long_usage=yes
|
||||
dbackup_usage
|
||||
exit
|
||||
;;
|
||||
|
||||
esac
|
||||
# :command.environment_variables_filter
|
||||
# :command.dependencies_filter
|
||||
# :command.command_filter
|
||||
action="root"
|
||||
# :command.required_args_filter
|
||||
# :command.required_flags_filter
|
||||
# :command.parse_requirements_while
|
||||
while [[ $# -gt 0 ]]; do
|
||||
key="$1"
|
||||
case "$key" in
|
||||
# :flag.case
|
||||
--password | -p )
|
||||
if [[ $2 ]]; then
|
||||
args[--password]="$2"
|
||||
shift
|
||||
shift
|
||||
else
|
||||
printf "%s\n" "--password requires an argument: --password, -p PASSWORD"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
# :flag.case
|
||||
--remote | -r )
|
||||
args[--remote]=1
|
||||
shift
|
||||
;;
|
||||
|
||||
# :flag.case
|
||||
--server )
|
||||
if [[ $2 ]]; then
|
||||
args[--server]="$2"
|
||||
shift
|
||||
shift
|
||||
else
|
||||
printf "%s\n" "--server requires an argument: --server URL"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
# :flag.case
|
||||
--init )
|
||||
args[--init]=1
|
||||
shift
|
||||
;;
|
||||
|
||||
# :flag.case
|
||||
--snap )
|
||||
args[--snap]=1
|
||||
shift
|
||||
;;
|
||||
|
||||
# :flag.case
|
||||
--view | -v )
|
||||
args[--view]=1
|
||||
shift
|
||||
;;
|
||||
|
||||
# :flag.case
|
||||
--view-path )
|
||||
if [[ $2 ]]; then
|
||||
args[--view-path]="$2"
|
||||
shift
|
||||
shift
|
||||
else
|
||||
printf "%s\n" "--view-path requires an argument: --view-path PATH"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
# :flag.case
|
||||
--prune )
|
||||
if [[ $2 ]]; then
|
||||
args[--prune]="$2"
|
||||
shift
|
||||
shift
|
||||
else
|
||||
printf "%s\n" "--prune requires an argument: --prune PRUNE"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
# :flag.case
|
||||
--password | -p )
|
||||
if [[ $2 ]]; then
|
||||
args[--password]="$2"
|
||||
shift
|
||||
shift
|
||||
else
|
||||
printf "%s\n" "--password requires an argument: --password, -p PASSWORD"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
# :flag.case
|
||||
--settings | -s )
|
||||
if [[ $2 ]]; then
|
||||
args[--settings]="$2"
|
||||
shift
|
||||
shift
|
||||
else
|
||||
printf "%s\n" "--settings requires an argument: --settings, -s SYAML"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
# :flag.case
|
||||
--options | -o )
|
||||
if [[ $2 ]]; then
|
||||
args[--options]="$2"
|
||||
shift
|
||||
shift
|
||||
else
|
||||
printf "%s\n" "--options requires an argument: --options, -o OPTIONS"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
# :flag.case
|
||||
--include_file | -i )
|
||||
if [[ $2 ]]; then
|
||||
args[--include_file]="$2"
|
||||
shift
|
||||
shift
|
||||
else
|
||||
printf "%s\n" "--include_file requires an argument: --include_file, -i INCLUDE"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
# :flag.case
|
||||
--exclude_file | -e )
|
||||
if [[ $2 ]]; then
|
||||
args[--exclude_file]="$2"
|
||||
shift
|
||||
shift
|
||||
else
|
||||
printf "%s\n" "--exclude_file requires an argument: --exclude_file, -e EXCLUDE"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
# :flag.case
|
||||
--sudo )
|
||||
args[--sudo]=1
|
||||
shift
|
||||
;;
|
||||
|
||||
# :flag.case
|
||||
--jq )
|
||||
if [[ $2 ]]; then
|
||||
args[--jq]="$2"
|
||||
shift
|
||||
shift
|
||||
else
|
||||
printf "%s\n" "--jq requires an argument: --jq JQ"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
|
||||
-* )
|
||||
printf "invalid option: %s\n" "$key"
|
||||
exit 1
|
||||
;;
|
||||
|
||||
* )
|
||||
# :command.parse_requirements_case
|
||||
if [[ ! ${args[source]} ]]; then
|
||||
args[source]=$1
|
||||
shift
|
||||
elif [[ ! ${args[target]} ]]; then
|
||||
args[target]=$1
|
||||
shift
|
||||
else
|
||||
printf "invalid argument: %s\n" "$key"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
# :command.catch_all_filter
|
||||
# :command.default_assignments
|
||||
# :command.whitelist_filter
|
||||
}
|
||||
|
||||
# :command.initialize
|
||||
initialize() {
|
||||
version="0.1.0"
|
||||
long_usage=''
|
||||
set -e
|
||||
|
||||
if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then
|
||||
printf "bash version 4 or higher is required\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# :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() {
|
||||
declare -A args
|
||||
declare -a other_args
|
||||
declare -a input
|
||||
normalize_input "$@"
|
||||
parse_requirements "${input[@]}"
|
||||
|
||||
if [[ $action == "root" ]]; then
|
||||
root_command
|
||||
fi
|
||||
}
|
||||
|
||||
initialize
|
||||
run "$@"
|
|
@ -0,0 +1,50 @@
|
|||
#!/bin/bash
|
||||
|
||||
# user to start MUST be first in arguments
|
||||
# if not supplied then will use default
|
||||
chromium_() {
|
||||
local DEFAULT=/opt/chromium
|
||||
# local DEFAULT="$HOME/.local/share/chromium"
|
||||
local exe="/usr/bin/chromium"
|
||||
if [[ ! -f $exe ]]; then
|
||||
echo deb chromium not installed, checking for flatpak version
|
||||
flatpak=$(flatpak info com.github.Eloston.UngoogledChromium | grep error:)
|
||||
if [[ $flatpak ]]; then
|
||||
echo no flatpak version either - exiting && return 1
|
||||
else
|
||||
flatpak=true
|
||||
exe="/usr/bin/flatpak run --branch=stable --arch=x86_64 --filesystem=<dir> --command=/app/bin/chromium --file-forwarding com.github.Eloston.UngoogledChromium @@u"
|
||||
fi
|
||||
fi
|
||||
# an instance gets it's own directory
|
||||
local instance=${CHROMIUM_INSTANCE}
|
||||
[[ $1 && (! $1 == -*) ]] && instance=$1 && shift
|
||||
[[ $1 && (! $1 == -*) ]] && url=$1 && shift
|
||||
if [[ $instance =~ http[s]?:\/\/ ]]; then
|
||||
url=$instance
|
||||
instance=""
|
||||
if [[ $url =~ ^-+ ]]; then
|
||||
url=""
|
||||
set -- "$@" $url
|
||||
url=""
|
||||
fi
|
||||
fi
|
||||
|
||||
local dir
|
||||
if [[ ! $instance ]]; then
|
||||
unset CHROME_CONFIG_HOME
|
||||
$HOME/.config/chromium
|
||||
dir=$HOME/.config/chromium
|
||||
exe="${exe/<dir>/$dir}"
|
||||
echo starting chromium for $USER in
|
||||
else
|
||||
[[ $instance == "incognito" ]] && set -- "$@" "-incognito"
|
||||
dir=${CHROMIUM_HOME:-$DEFAULT}/$instance
|
||||
exe="${exe/<dir>/$dir}"
|
||||
fi
|
||||
echo $exe $@ --user-data-dir=$dir $url $([[ $flatpak ]] && echo "@@")
|
||||
|
||||
}
|
||||
|
||||
# # if script was executed then call the function
|
||||
(return 0 2>/dev/null) || chromium_ $@
|
|
@ -0,0 +1,20 @@
|
|||
#!/bin/bash
|
||||
|
||||
function chromium_install {
|
||||
|
||||
source $BASH_SHELL_BASE/module.lib
|
||||
module_load helpers
|
||||
NAME="chromium"
|
||||
DIR=$(adirname "$0")
|
||||
BIN=${1:-/opt/bin/$NAME}
|
||||
# [[ $(chown :users $DIR/$NAME.sh) ]] || sudo chown :users $DIR/$NAME.sh
|
||||
[[ $(chmod 755 $DIR/$NAME.sh) ]] || sudo chmod 755 $DIR/$NAME.sh
|
||||
ln -sf $DIR/$NAME.sh $BIN
|
||||
echo link created
|
||||
ls -la /opt/bin | grep chromium
|
||||
echo with permissions
|
||||
ls -la $DIR | grep chromium.sh
|
||||
}
|
||||
|
||||
# if script was executed then call the function
|
||||
(return 0 2>/dev/null) || chromium_install $@
|
|
@ -1,9 +0,0 @@
|
|||
#!/bin/bash
|
||||
source $BASH_SHELL_BASE/module.lib
|
||||
module_load helpers
|
||||
NAME=${1:-$(filename $0)}
|
||||
DIR=$(adirname "$0")
|
||||
BIN=${1:-/opt/bin/$NAME}
|
||||
chown :users $DIR/$NAME.sh
|
||||
chmod 755 $DIR/$NAME.sh
|
||||
ln -sf $DIR/$NAME.sh $BIN
|
|
@ -4,10 +4,16 @@
|
|||
# if not supplied then will use default
|
||||
chromium_() {
|
||||
local DEFAULT=/opt/chromium
|
||||
local DEFAULT_USER=$HOME/.browsers
|
||||
# local DEFAULT="$HOME/.local/share/chromium"
|
||||
local exe="/usr/bin/chromium"
|
||||
|
||||
[[ $1 == "-version" ]] && $exe -version && return
|
||||
|
||||
[[ $1 == -g ]] && exe=$(command -v google-chrome) && shift
|
||||
echo execuatble to be used: $exe
|
||||
if [[ ! -f $exe ]]; then
|
||||
echo deb chromium not installed, checking for flatpak version
|
||||
echo chromium/chrome not installed, checking for flatpak version
|
||||
flatpak=$(flatpak info com.github.Eloston.UngoogledChromium | grep error:)
|
||||
if [[ $flatpak ]]; then
|
||||
echo no flatpak version either - exiting && return 1
|
||||
|
@ -37,13 +43,14 @@ chromium_() {
|
|||
echo starting chromium for $USER in
|
||||
dir=$HOME/.config/chromium
|
||||
exe="${exe/<dir>/$dir}"
|
||||
# echo $exe "$@" $([[ $flatpak ]] && echo " @@")
|
||||
# $exe "$@"
|
||||
else
|
||||
[[ $instance == "incognito" ]] && set -- "$@" "-incognito"
|
||||
dir=${CHROMIUM_HOME:-$DEFAULT}/$instance
|
||||
dir=${DEFAULT_USER}/$instance
|
||||
dir=$([[ -d "$dir" ]] && echo $dir || echo "${CHROMIUM_HOME:-$DEFAULT}/$instance")
|
||||
exe="${exe/<dir>/$dir}"
|
||||
fi
|
||||
mkdir -p $dir
|
||||
echo $exe $@ --user-data-dir=$dir $url $([[ $flatpak ]] && echo "@@")
|
||||
$exe $@ --user-data-dir=$dir $url $([[ $flatpak ]] && echo "@@")
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
#!/bin/bash
|
||||
ungoogled_install() {
|
||||
module_load confirm
|
||||
module_load helpers
|
||||
|
||||
SDIR=$(adirname ${1:-$(dirname ${BASH_SOURCE[0]})})
|
||||
|
||||
if [[ ! $(which lastversion) ]]; then
|
||||
echo lastversion is not installed
|
||||
echo it is a required dependency for this script
|
||||
echo see https://github.com/dvershinin/lastversion
|
||||
return
|
||||
fi
|
||||
|
||||
CUR_VERSION=$( /usr/bin/chromium -version | grep -oP '(?<=Chromium )[^ ]*')
|
||||
|
||||
_repo="Eloston/ungoogled-chromium-binaries"
|
||||
|
||||
NEW_VERSION=$(lastversion ${_repo})
|
||||
|
||||
echo "Ungoogled: Current Version : $CUR_VERSION => New Version: $NEW_VERSION"
|
||||
|
||||
[[ $NEW_VERSION = $CUR_VERSION ]] && [[ ! ${1} == "-f" ]] && echo Latest version is already installed
|
||||
|
||||
_temp=/tmp/ungoogled_chromium
|
||||
echo $_temp to download deb and install
|
||||
mkdir -p $_temp || exit &> /dev/null
|
||||
pushd $_temp &> /dev/null || exit
|
||||
|
||||
echo downloading common deb
|
||||
lastversion ${_repo} --format assets --filter common_ -d common.deb
|
||||
lastversion ${_repo} --format assets --filter mium_.+amd64.deb -d chromium.deb
|
||||
echo installing common libraries
|
||||
sudo dpkg -i common.deb
|
||||
echo installing ungoogled-chromium
|
||||
sudo dpkg -i chromium.deb
|
||||
|
||||
echo done installing, removing $_temp
|
||||
rm -r $_temp &> /dev/null || true
|
||||
|
||||
popd >/dev/null
|
||||
|
||||
confirm "do you want to install WidevineCDM for digital streaming rights?"
|
||||
if [ $? -eq 0 ]; then
|
||||
module_load widevine-install
|
||||
widevine_install
|
||||
fi
|
||||
|
||||
confirm "do you want to install the uci chromium start script in /opt/bin ?"
|
||||
if [ $? -eq 0 ]; then
|
||||
module_load chromium-install
|
||||
chromium_install
|
||||
fi
|
||||
|
||||
|
||||
}
|
||||
|
||||
# # if script was executed then call the function
|
||||
(return 0 2>/dev/null) || ungoogled_install $@
|
|
@ -0,0 +1,71 @@
|
|||
#!/bin/bash
|
||||
# -eux
|
||||
function confirm()
|
||||
{
|
||||
echo -n "$@ "
|
||||
read -e answer
|
||||
for response in y Y yes YES Yes Sure sure SURE OK ok Ok
|
||||
do
|
||||
if [ "_$answer" == "_$response" ]
|
||||
then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
# Any answer other than the list above is considered a "no" answer
|
||||
return 1
|
||||
}
|
||||
|
||||
function widevine_install {
|
||||
|
||||
_chrome_ver=$( /usr/bin/chromium -version | grep -oP '(?<=Chromium )[^ ]*')
|
||||
|
||||
_l_target_dir=~/.local/lib/WidevineCdm
|
||||
_target_dir=/usr/lib/chromium/WidevineCdm
|
||||
_sudo="sudo"
|
||||
|
||||
if [[ "${1}" == "-l" ]]; then
|
||||
_sudo=""
|
||||
_target_dir=$_l_target_dir
|
||||
shift
|
||||
fi
|
||||
|
||||
echo "install widevineCDM for chromium version $_chrome_ver"
|
||||
echo "into $_target_dir"
|
||||
|
||||
confirm "confirm (y/n)" || exit
|
||||
|
||||
_temp=/tmp/chromium_widevine
|
||||
echo using $_temp to download deb and extract widevine
|
||||
mkdir -p $_temp || exit &> /dev/null
|
||||
pushd $_temp &> /dev/null || exit
|
||||
|
||||
# Download deb, which has corresponding Widevine version
|
||||
# Support resuming partially downloaded (or skipping re-download) with -c flag
|
||||
if [[ "${1}" == "-u" ]]; then
|
||||
_un="un"
|
||||
fi
|
||||
_url=https://dl.google.com/linux/deb/pool/main/g/google-chrome-${_un}stable/google-chrome-${_un}stable_${_chrome_ver}-1_amd64.deb
|
||||
echo downloading $_url
|
||||
|
||||
wget -c $_url || exit
|
||||
|
||||
# Unpack deb
|
||||
rm -r unpack_deb &> /dev/null || true
|
||||
mkdir -p unpack_deb
|
||||
echo extracting package...
|
||||
dpkg-deb -R google-chrome-stable_${_chrome_ver}-1_amd64.deb unpack_deb || exit
|
||||
echo removing any old WidevineCDM installs at $_target_dir
|
||||
$_sudo rm -r $_target_dir &> /dev/null || true
|
||||
echo moving WidevineCDM to target $_target_dir
|
||||
$_sudo mv unpack_deb/opt/google/chrome/WidevineCdm $_target_dir &> /dev/null || exit
|
||||
[[ $_sudo ]] && $_sudo chown -R root:root $_target_dir
|
||||
echo done, removing $_temp
|
||||
rm -r $_temp &> /dev/null || true
|
||||
popd &> /dev/null
|
||||
|
||||
}
|
||||
|
||||
# if script was executed then call the function
|
||||
(return 0 2>/dev/null) || widevine_install $@
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
#!/bin/bash
|
||||
# -eux
|
||||
function confirm()
|
||||
{
|
||||
echo -n "$@ "
|
||||
read -e answer
|
||||
for response in y Y yes YES Yes Sure sure SURE OK ok Ok
|
||||
do
|
||||
if [ "_$answer" == "_$response" ]
|
||||
then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
# Any answer other than the list above is considered a "no" answer
|
||||
return 1
|
||||
}
|
||||
|
||||
|
||||
_chrome_ver=$( /usr/bin/chromium -version | grep -oP '(?<=Chromium )[^ ]*')
|
||||
|
||||
_l_target_dir=~/.local/lib/WidevineCdm
|
||||
_target_dir=/usr/lib/chromium/WidevineCdm
|
||||
_sudo="sudo"
|
||||
|
||||
if [[ "${1}" == "-l" ]]; then
|
||||
_sudo=""
|
||||
_target_dir=$_l_target_dir
|
||||
shift
|
||||
fi
|
||||
|
||||
echo "install widevineCDM for chromium version $_chrome_ver"
|
||||
echo "into $_target_dir"
|
||||
|
||||
confirm "confirm (y/n)" || exit
|
||||
|
||||
_temp=/tmp/chromium_widevine
|
||||
echo using $_temp to download deb and extract widevine
|
||||
mkdir -p $_temp || exit &> /dev/null
|
||||
pushd $_temp &> /dev/null || exit
|
||||
|
||||
# Download deb, which has corresponding Widevine version
|
||||
# Support resuming partially downloaded (or skipping re-download) with -c flag
|
||||
if [[ "${1}" == "-u" ]]; then
|
||||
_un="un"
|
||||
fi
|
||||
_url=https://dl.google.com/linux/deb/pool/main/g/google-chrome-${_un}stable/google-chrome-${_un}stable_${_chrome_ver}-1_amd64.deb
|
||||
echo downloading $_url
|
||||
|
||||
wget -c $_url || exit
|
||||
|
||||
# Unpack deb
|
||||
rm -r unpack_deb &> /dev/null || true
|
||||
mkdir -p unpack_deb
|
||||
echo extracting package...
|
||||
dpkg-deb -R google-chrome-stable_${_chrome_ver}-1_amd64.deb unpack_deb || exit
|
||||
echo removing any old WidevineCDM installs at $_target_dir
|
||||
$_sudo rm -r $_target_dir &> /dev/null || true
|
||||
echo moving WidevineCDM to target $_target_dir
|
||||
$_sudo mv unpack_deb/opt/google/chrome/WidevineCdm $_target_dir &> /dev/null || exit
|
||||
[[ $_sudo ]] && $_sudo chown -R root:root $_target_dir
|
||||
echo done, removing $_temp
|
||||
rm -r $_temp &> /dev/null || true
|
||||
popd &> /dev/null
|
||||
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/env bash
|
||||
# https://raw.githubusercontent.com/flathub/com.github.Eloston.UngoogledChromium/master/widevine-install.sh
|
||||
# https://github.com/flathub/com.github.Eloston.UngoogledChromium
|
||||
# Exit on error and forbid unset variables
|
||||
set -eu
|
||||
|
||||
# Get latest WideVine Version by getting last line in https://dl.google.com/widevine-cdm/versions.txt
|
||||
_widevine_ver="$(wget -qO- https://dl.google.com/widevine-cdm/versions.txt | tail -n1)"
|
||||
|
||||
# Get the architecture of the current machine
|
||||
ARCH="$(uname -m)"
|
||||
case "$ARCH" in
|
||||
x86_64)
|
||||
WIDEVINE_ARCH="x64"
|
||||
CHROMIUM_ARCH="x64"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "The architecture $ARCH is not supported." >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Download WideVine into a temporary file and use trap to delete it on exit
|
||||
widevine_zip="$(mktemp)"
|
||||
trap 'rm -f "${widevine_zip:?}"' EXIT
|
||||
wget -O "$widevine_zip" "https://dl.google.com/widevine-cdm/${_widevine_ver}-linux-${WIDEVINE_ARCH}.zip"
|
||||
|
||||
# Install WideVine from zip file into UngoogledChromium flatpak
|
||||
_install_prefix="/opt/chromium/$1/WidevineCdm/${_widevine_ver}"
|
||||
unzip -p "$widevine_zip" libwidevinecdm.so | install -Dm644 "/dev/stdin" "${_install_prefix}/_platform_specific/linux_$CHROMIUM_ARCH/libwidevinecdm.so"
|
||||
unzip -p "$widevine_zip" manifest.json | install -m644 "/dev/stdin" "${_install_prefix}/manifest.json"
|
||||
unzip -p "$widevine_zip" LICENSE.txt | install -m644 "/dev/stdin" "${_install_prefix}/LICENSE.txt"
|
|
@ -0,0 +1 @@
|
|||
/shell/host/all/dev/backup/dbackup
|
|
@ -0,0 +1,4 @@
|
|||
# will make a launch script at /usr/bin for a given flatpak application
|
||||
# $1 is bin file name, $2 is flatpak application name
|
||||
# --mount -m will mount any folders outside the sandbox
|
||||
# this launch script will make is easier to start the app like it was a native debian app
|
|
@ -1,113 +1,116 @@
|
|||
#!/bin/bash
|
||||
|
||||
hugo_install () {
|
||||
hugo_install() {
|
||||
# inspried from this forum post https://discourse.gohugo.io/t/script-to-install-latest-hugo-release-on-macos-and-ubuntu/14774/10
|
||||
# if you have run into github api anonymous access limits which happens during debugging/dev then add user and token here or sourced from a separate file
|
||||
# . ~/githubapitoken
|
||||
#GITHUB_USER=""
|
||||
#GITHUB_TOKEN=""
|
||||
|
||||
|
||||
if [ "$GITHUB_TOKEN" != "" ]; then
|
||||
echo using access token with script
|
||||
echo $GITHUB_USER $GITHUB_TOKEN
|
||||
fi
|
||||
|
||||
|
||||
EXTENDED=false
|
||||
FORCE=false
|
||||
EFILE=""
|
||||
|
||||
|
||||
|
||||
# options
|
||||
# e - download and install the extended version
|
||||
# c - use 'hugoe' as the install command for extended version otherwise 'hugo' will launch extended version
|
||||
# f - force download/overwrite of same version
|
||||
|
||||
|
||||
declare OPTION
|
||||
declare OPTARG
|
||||
declare OPTIND
|
||||
|
||||
|
||||
while getopts 'ecf' OPTION; do
|
||||
case "$OPTION" in
|
||||
e)
|
||||
echo "installing extended hugo"
|
||||
EXTENDED=true
|
||||
e)
|
||||
echo "installing extended hugo"
|
||||
EXTENDED=true
|
||||
;;
|
||||
c)
|
||||
if [ $EXTENDED = true ]; then
|
||||
EFILE="e"
|
||||
echo using hugoe for extended command
|
||||
fi
|
||||
c)
|
||||
if [ $EXTENDED = true ]; then
|
||||
EFILE="e"
|
||||
echo using hugoe for extended command
|
||||
fi
|
||||
;;
|
||||
f)
|
||||
echo "FORCING download/overwrite"
|
||||
FORCE=true
|
||||
f)
|
||||
echo "FORCING download/overwrite"
|
||||
FORCE=true
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $(( OPTIND - 1 ))
|
||||
|
||||
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
DEFAULT_BIN_DIR="/usr/local/bin"
|
||||
# Single optional argument is directory in which to install hugo
|
||||
BIN_DIR=${1:-"$DEFAULT_BIN_DIR"}
|
||||
|
||||
|
||||
BIN_PATH="$(which hugo$EFILE)"
|
||||
declare -A ARCHES
|
||||
ARCHES=( ["arm64"]="ARM64" ["aarch64"]="ARM64" ["x86_64"]="64bit" ["arm32"]="ARM" ["armhf"]="ARM" )
|
||||
ARCHES=(["arm64"]="ARM64" ["aarch64"]="ARM64" ["x86_64"]="64bit" ["arm32"]="ARM" ["armhf"]="ARM")
|
||||
ARCH=$(arch)
|
||||
|
||||
|
||||
if [ -z "${ARCHES[$ARCH]}" ]; then
|
||||
echo Your machine kernel architecture $ARCH is not supported by this script, aborting
|
||||
echo Your machine kernel architecture $ARCH is not supported by this script, aborting
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
|
||||
INSTALLED="$(hugo$EFILE version 2>/dev/null | cut -d'v' -f2 | cut -c 1-6)"
|
||||
CUR_VERSION=${INSTALLED:-"None"}
|
||||
echo $(curl -u $GITHUB_USER:$GITHUB_TOKEN -s https://api.github.com/repos/gohugoio/hugo/releases/latest | grep tag_name)
|
||||
NEW_VERSION="$(curl -u $GITHUB_USER:$GITHUB_TOKEN -s https://api.github.com/repos/gohugoio/hugo/releases/latest \
|
||||
| grep tag_name \
|
||||
| cut -d'v' -f2 | cut -c 1-6)"
|
||||
|
||||
echo "Hugo `[ $EXTENDED == true ] && echo "Extended"`: Current Version : $CUR_VERSION => New Version: $NEW_VERSION"
|
||||
|
||||
if [ -z "$NEW_VERSION" ]; then
|
||||
echo Unable to retrieve new version number - Likely you have reached github anonymous limit
|
||||
echo set environment variable `$GITHUB_USER` and `$GITHUB_TOKEN` and try again
|
||||
exit 1
|
||||
fi
|
||||
|
||||
[[ $NEW_VERSION = $CUR_VERSION ]] && [[ $FORCE = false ]] && echo Latest version already installed at $BIN_PATH && return 0
|
||||
|
||||
pushd /tmp/ > /dev/null
|
||||
|
||||
URL=$(curl -u $GITHUB_USER:$GITHUB_TOKEN -s https://api.github.com/repos/gohugoio/hugo/releases/latest \
|
||||
| grep "browser_download_url.*hugo.*._Linux-${ARCHES[$ARCH]}\.tar\.gz" \
|
||||
| \
|
||||
if [ $EXTENDED = true ]; then
|
||||
grep "_extended"
|
||||
else
|
||||
grep -v "_extended"
|
||||
fi \
|
||||
| cut -d ":" -f 2,3 \
|
||||
| tr -d \" \
|
||||
# echo $(curl -u $GITHUB_USER:$GITHUB_TOKEN -s https://api.github.com/repos/gohugoio/hugo/releases/latest | grep tag_name)
|
||||
# NEW_VERSION="$(curl -u $GITHUB_USER:$GITHUB_TOKEN -s https://api.github.com/repos/gohugoio/hugo/releases/latest \
|
||||
# | grep tag_name \
|
||||
# | cut -d'v' -f2 | cut -c 1-6)"
|
||||
|
||||
NEW_VERSION=$(lastversion hugo)
|
||||
|
||||
echo "Hugo $([ $EXTENDED == true ] && echo "Extended"): Current Version : $CUR_VERSION => New Version: $NEW_VERSION"
|
||||
|
||||
# if [ -z "$NEW_VERSION" ]; then
|
||||
# echo Unable to retrieve new version number - Likely you have reached github anonymous limit
|
||||
# echo set environment variable $($GITHUB_USER) and $($GITHUB_TOKEN) and try again
|
||||
# exit 1
|
||||
# fi
|
||||
|
||||
[[ $NEW_VERSION = $CUR_VERSION ]] && [[ $FORCE = false ]] && echo Latest version already installed at $BIN_PATH && return 0
|
||||
|
||||
pushd /tmp/ >/dev/null
|
||||
|
||||
# curl -u $GITHUB_USER:$GITHUB_TOKEN -s https://api.github.com/repos/gohug#oio/hugo/releases/latest |
|
||||
# grep "browser_download_url.*hugo.*._Linux-${ARCHES[$ARCH]}\.tar\.gz" |
|
||||
|
||||
URL=$(
|
||||
lastversion hugo --format assets --filter Linux-${ARCHES[$ARCH]}\.tar\.gz |
|
||||
if [ $EXTENDED = true ]; then
|
||||
grep "_extended"
|
||||
else
|
||||
grep -v "_extended"
|
||||
fi
|
||||
# |
|
||||
# cut -d ":" -f 2,3 |
|
||||
# tr -d \"
|
||||
)
|
||||
|
||||
|
||||
echo $URL
|
||||
|
||||
echo "Installing version $NEW_VERSION `[ $EXTENDED == true ] && echo "Extended"` "
|
||||
|
||||
echo "Installing version $NEW_VERSION $([ $EXTENDED == true ] && echo "Extended") "
|
||||
echo "This machine's architecture is $ARCH"
|
||||
echo "Downloading Tarball $URL"
|
||||
|
||||
|
||||
wget --user=-u $GITHUB_USER --password=$GITHUB_TOKEN -q $URL
|
||||
|
||||
|
||||
TARBALL=$(basename $URL)
|
||||
# TARBALL="$(find . -name "*Linux-${ARCHES[$ARCH]}.tar.gz" 2>/dev/null)"
|
||||
echo Expanding Tarball, $TARBALL
|
||||
tar -xzf $TARBALL hugo
|
||||
|
||||
|
||||
chmod +x hugo
|
||||
|
||||
|
||||
if [ -w $BIN_DIR ]; then
|
||||
echo "Installing hugo to $BIN_DIR"
|
||||
mv hugo -f $BIN_DIR/hugo$EFILE
|
||||
|
@ -115,15 +118,15 @@ hugo_install () {
|
|||
echo "installing hugo to $BIN_DIR (sudo)"
|
||||
sudo mv -f hugo $BIN_DIR/hugo$EFILE
|
||||
fi
|
||||
|
||||
|
||||
rm $TARBALL
|
||||
|
||||
popd > /dev/null
|
||||
|
||||
echo Installing hugo `[ $EXTENDED == true ] && echo "extended"` as hugo$EFILE
|
||||
|
||||
|
||||
popd >/dev/null
|
||||
|
||||
echo Installing hugo $([ $EXTENDED == true ] && echo "extended") as hugo$EFILE
|
||||
|
||||
BIN_PATH="$(which hugo$EFILE)"
|
||||
|
||||
|
||||
if [ -z "$BIN_PATH" ]; then
|
||||
printf "WARNING: Installed Hugo Binary in $BIN_DIR is not in your environment path\nPATH=$PATH\n"
|
||||
else
|
||||
|
@ -135,5 +138,5 @@ hugo_install () {
|
|||
printf "New Hugo binary version at $BIN_PATH is\n $($BIN_PATH version)\n"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
#!/bin/bash
|
||||
log=$HOME/.session/session.log
|
||||
&>> $log
|
||||
echo $USER $HOME
|
||||
echo "lightdm login setup $(date)"
|
||||
|
||||
# example commands to run when logging in, here binding some other directories for the user
|
||||
#echo "binding chromium browsers to .browsers"
|
||||
#/usr/bin/bindfs --map=sysadmin/$USER:@users/@$USER /opt/chromium/default $HOME/.browsers/default
|
||||
# bind alternate downloads directory
|
||||
#/usr/bin/bindfs --map=sysadmin/$USER:@users/@$USER /data/downloads $HOME/Downloads
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
#!/bin/bash
|
||||
log=$HOME/.session/session.log
|
||||
&>> $log
|
||||
echo $USER $HOME
|
||||
echo "lightdm logout cleanup $(date)"
|
||||
# example complimentary cleanup here unmounting those mounted in session_login
|
||||
#echo "un mounting chromium browsers from .browsers"
|
||||
#/bin/fusermount -u $HOME/.browsers/default
|
||||
#/bin/fusermount -u $HOME/Downloads
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
# run the session login script manually, used for debugging
|
||||
sudo -E HOME=$HOME USER=$USER ./session_login
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/bash
|
||||
# run the session logout script manually, used for debugging
|
||||
sudo -E HOME=$HOME USER=$USER /bin/bash session_logout
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
[Seat:*]
|
||||
session-cleanup-script=/opt/scripts/lightdm-cleanup.sh
|
||||
session-setup-script=/opt/scripts/lightdm-setup.sh
|
|
@ -0,0 +1,28 @@
|
|||
#!/bin/bash
|
||||
|
||||
function confirm()
|
||||
{
|
||||
echo -n "$@ "
|
||||
read -e answer
|
||||
for response in y Y yes YES Yes Sure sure SURE OK ok Ok
|
||||
do
|
||||
if [ "_$answer" == "_$response" ]
|
||||
then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
# Any answer other than the list above is considered a "no" answer
|
||||
return 1
|
||||
}
|
||||
|
||||
if [[ -d $HOME/.session ]]; then
|
||||
echo $HOME/.session folder already exists
|
||||
confirm "!overwrite??? (y/n)" || exit
|
||||
/bin/cp -r -f $HOME/.session/ $HOME/.session-saved/
|
||||
echo saved copy first to $HOME/.session-saved
|
||||
fi
|
||||
echo copying .session from $(pwd) to $HOME
|
||||
/bin/cp -r -f .session/ $HOME
|
||||
echo setting execute permissions
|
||||
chmod +x $HOME/.session/*
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/bash
|
||||
echo "cleanup for ${USER}:${HOME} $(date)" >> /opt/scripts/lightdm.log
|
||||
log=${HOME}/.session.log
|
||||
if [[ -e $HOME/.session_logout ]]; then su -c "/bin/bash $HOME/.session_logout 1>>${log} 2>>${log} || true" $USER; fi
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/bash
|
||||
echo "setup for ${USER}:${HOME} $(date)" >> /opt/scripts/lightdm.log
|
||||
log=${HOME}/.session.log
|
||||
if [[ -e $HOME/.session_login ]]; then su -c "/bin/bash $HOME/.session_login 1>>${log} 2>>${log} || true" $USER; fi
|
|
@ -0,0 +1,69 @@
|
|||
#!/bin/bash
|
||||
loginout_install() {
|
||||
module_load confirm
|
||||
module_load helpers
|
||||
|
||||
[[ ! $(systemctl list-units | grep lightdm) ]] && echo lightdm not running on this machine, aborting && return
|
||||
|
||||
SDIR=$(adirname "${BASH_SOURCE[0]}")
|
||||
# echo source directory: $SDIR
|
||||
|
||||
|
||||
pushd $SDIR &> /dev/null || exit
|
||||
[[ ! -d /etc/lightdm/lightdm.conf.d ]] && mkdir -p /etc/lightdm/lightdm.conf.d
|
||||
echo copying 50-setup-cleanup.conf to /etc/lightdm/lightdm.conf.d
|
||||
sudo cp -f 50-setup-cleanup.conf /etc/lightdm/lightdm.conf.d
|
||||
|
||||
if [[ ! -d /opt/scripts ]]; then
|
||||
if [[ ! $(mkdir -p /opt/scripts) ]]; then
|
||||
_sudo="sudo"
|
||||
[[ $($_sudo mkdir -p /opt/scripts) ]] && echo can not make /opt/scripts, aborting && return
|
||||
fi
|
||||
fi
|
||||
|
||||
echo copying lightdm-cleanup.sh and lightdm-setup.sh to /opt/scripts
|
||||
$_sudo cp -f lightdm-*.sh /opt/scripts
|
||||
|
||||
|
||||
popd >/dev/null
|
||||
|
||||
_user=${1:-${USER}}
|
||||
confirm "add a user .session folder for $_user" && add_user_session $1
|
||||
|
||||
|
||||
}
|
||||
|
||||
function add_user_session {
|
||||
|
||||
module_load confirm
|
||||
module_load helpers
|
||||
|
||||
SDIR=$(adirname "${BASH_SOURCE[0]}")
|
||||
# echo source directory: $SDIR
|
||||
|
||||
pushd $SDIR &> /dev/null || exit
|
||||
|
||||
_user=${1:-${USER}}
|
||||
|
||||
[[ ! $(user_exists $_user) ]] && echo user $_user does not exist, aborting && return
|
||||
_home=$(bash -c "cd ~$(printf %q $_user) && pwd")
|
||||
|
||||
echo making $_home/.session folder for $_user
|
||||
# mkdir $USER/.session
|
||||
|
||||
sudo -H -E -u "$_user" -s /bin/bash cpy.session.sh
|
||||
|
||||
popd >/dev/null
|
||||
|
||||
|
||||
# confirm "do you want to install WidevineCDM for digital streaming rights?"
|
||||
# if [ $? -eq 0 ]; then
|
||||
# module_load widevine-install
|
||||
# widevine_install
|
||||
# fi
|
||||
|
||||
|
||||
}
|
||||
|
||||
# if script was executed then call the function
|
||||
(return 0 2>/dev/null) || loginout_install $@
|
|
@ -0,0 +1,51 @@
|
|||
|
||||
Lightdm (gdm) is the login manager for linux ubuntu and mint (by default)
|
||||
|
||||
If you need setup and cleanup that is ONLY done at lightdm login/logout then
|
||||
one can run a script to setup and cleanup the session by
|
||||
|
||||
running the loginout-install script, requires sudo
|
||||
|
||||
`module_load loginout-install; loginout_install <user>` # default is current user
|
||||
|
||||
after loading common scripts this will ask if you want to add the .session folder for the user
|
||||
|
||||
or if you just need to add a user .session folder afterward
|
||||
|
||||
`module_load loginout-install; add_user_session <user>`
|
||||
|
||||
|
||||
the script does this
|
||||
|
||||
in `/etc/lightdm/lightdm.conf.d` adds a file `50-setup-cleanup.conf`
|
||||
|
||||
```
|
||||
[Seat:*]
|
||||
session-cleanup-script=/opt/scripts/lightdm-cleanup.sh
|
||||
session-setup-script=/opt/scripts/lightdm-setup.sh
|
||||
```
|
||||
|
||||
in /opt/scripts put two files below and make sure they are +x executable
|
||||
|
||||
```
|
||||
#!/bin/bash
|
||||
#lightdm-setup.sh
|
||||
echo "setup for ${USER}:${HOME} $(date)" >> /opt/scripts/lightdm.log
|
||||
log=${HOME}/.session.log
|
||||
if [[ -e $HOME/.session_login ]]; then su -c "/bin/bash $HOME/.session_login 1>>${log} 2>>${log} || true" $USER; fi
|
||||
```
|
||||
|
||||
```
|
||||
#!/bin/bash
|
||||
#lightdm-cleanup.sh
|
||||
echo "cleanup for ${USER}:${HOME} $(date)" >> /opt/scripts/lightdm.log
|
||||
log=${HOME}/.session.log
|
||||
if [[ -e $HOME/.session_logout ]]; then su -c "/bin/bash $HOME/.session_logout 1>>${log} 2>>${log} || true" $USER; fi
|
||||
```
|
||||
|
||||
then in the user home puts
|
||||
`.session_login` and `.session_logout` files both executable
|
||||
in those you can do anything like bindfs and fusermount -u
|
||||
|
||||
make sure you restart lightdm or reboot
|
||||
`sdr lightdm`
|
Reference in New Issue