Initial commit
This commit is contained in:
parent
2a79ad859a
commit
7fae719399
4
home/.ssh/android-copy-backups.sh.known_hosts
Normal file
4
home/.ssh/android-copy-backups.sh.known_hosts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Example known_hosts entries
|
||||||
|
|1|+um5frSW7VwmX/QODni+oJG4AVI=|bEc28fJyS+uLnMd611M5QZuoCcU= ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC2Zx6ysyUg5U8zwWc9iqGnLzpdNnW0yh3CjNfYq+/viahofQi0TYcfKbI+gibnfFee8yz5qIyenA55MJY6DTJdWzq44WLyNoL+MXOhPZ5kOYRxI8a7Lt7gffYdfBRbAbc8NzO/AbtGTyHSQDKLlB1dI52+iQPoiFLVkE1q8CeTyNzpoL++gzDGx9K+P4jG1hWn2NMcRmihBZKRULAoGTUXXtA5I8J4s9kdRqOyNPqSH1AvEY2fuiUSHoU5M7wjH36rKrTpW0A99yyG3+X7r0aolzSgaard3izZxZ5Dyino1ORNmVZ+x6Gy+RmwlZbI/RE95KP1A3BAwSqtJCSnPz9V
|
||||||
|
|1|N/pgWDcZ2gZltCX0H5LBJsj/QyE=|V+HYraDDIEFa/E9IsLyI8P13Onw= ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBNlVAWMqn9ku266vS4uomkh654vgAgs4QcUViDE4THkkZJVRo/xNuwPIaqasBOpN6TxGNI0iLEusxTHvkbK07pM=
|
||||||
|
|1|jKXhrqA1nwYbm3P1NGW30FsmgeA=|sCfD9KOYMdK2P8JqLK0AsIifZDo= ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM7mgJkIkiUJCCU7R0XhNixG7LqQCNiFlxKT94VOqIiM
|
0
home/.ssh/android-copy-backups.sh.ssh-private-key
Normal file
0
home/.ssh/android-copy-backups.sh.ssh-private-key
Normal file
0
home/.ssh/android-copy-backups.sh.ssh-public-key
Normal file
0
home/.ssh/android-copy-backups.sh.ssh-public-key
Normal file
72
home/.termux/tasker/android-copy-backups.sh
Normal file
72
home/.termux/tasker/android-copy-backups.sh
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
declare thisScriptCallCommand thisScriptAbsPath thisScriptFileName thisScriptBaseName
|
||||||
|
thisScriptCallCommand="${BASH_SOURCE[0]}"
|
||||||
|
thisScriptAbsPath="$(realpath -s "${thisScriptCallCommand}" 2>/dev/null || { pushd "$(dirname "${0}")" &>/dev/null || exit 1; echo -n "$(cd "$(dirname "${0}")"
|
||||||
|
&>/dev/null || true; pwd -P)/$(basename "${BASH_SOURCE[0]}")"; })"
|
||||||
|
thisScriptFileName=$(basename "${thisScriptAbsPath}")
|
||||||
|
thisScriptBaseName="${thisScriptFileName%\.*}"
|
||||||
|
|
||||||
|
declare lockFileDescriptor lockFileDir lockFileNameAbsPath
|
||||||
|
lockFileDescriptor='200'
|
||||||
|
lockFileDir='/data/data/com.termux/files/usr/run/lock/quico-ops/scripts'
|
||||||
|
lockFileDir="${lockFileDir%/}"'/'"${thisScriptBaseName}"
|
||||||
|
mkdir -p "${lockFileDir}"
|
||||||
|
lockFileNameAbsPath="${lockFileDir}/${thisScriptBaseName}.lock"
|
||||||
|
|
||||||
|
# Locking mechanism is pretty much
|
||||||
|
# http://www.kfirlavi.com/blog/2012/11/06/elegant-locking-of-bash-program/
|
||||||
|
|
||||||
|
# shellcheck disable=SC2120
|
||||||
|
function lock () {
|
||||||
|
local fd="${1:-$lockFileDescriptor}"
|
||||||
|
|
||||||
|
# Create lock file
|
||||||
|
eval "exec ${fd}> ${lockFileNameAbsPath}"
|
||||||
|
|
||||||
|
# Acquire lock
|
||||||
|
flock -n "${fd}" && return 0 || return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function eexit () {
|
||||||
|
local errorStr="${*}"
|
||||||
|
echo "${errorStr}"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
lock || eexit "Only one instance of ${thisScriptAbsPath} can run at a time."
|
||||||
|
|
||||||
|
function cleanup () {
|
||||||
|
rm -f "${lockFileNameAbsPath}" &> /dev/null
|
||||||
|
}
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
declare target sourceDirBasePath sshFilesBaseDir sshPrivateKeyFileName sshKnownHostsFileName
|
||||||
|
declare -a sourceDirChildPathComponents
|
||||||
|
|
||||||
|
[[ ! "${1}" ]] && {
|
||||||
|
printf -- '%s\n' 'Argument 1 is empty. Must be rsync [USER@]HOST:DEST string. Exiting 1 ...'
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
target="${1}"
|
||||||
|
|
||||||
|
sourceDirBasePath='/storage/3430-3833'
|
||||||
|
sourceDirBasePath="${sourceDirBasePath%/}"
|
||||||
|
sshFilesBaseDir='/data/data/com.termux/files/home/.ssh'
|
||||||
|
sshFilesBaseDir="${sshFilesBaseDir%/}"
|
||||||
|
sshPrivateKeyFileName='android-copy-backups.sh.ssh-private-key'
|
||||||
|
sshKnownHostsFileName='android-copy-backups.sh.known_hosts'
|
||||||
|
|
||||||
|
sourceDirChildPathComponents[0]='DCIM'
|
||||||
|
sourceDirChildPathComponents[1]='Signal'
|
||||||
|
sourceDirChildPathComponents[2]='User'
|
||||||
|
sourceDirChildPathComponents[3]='SwiftBackup'
|
||||||
|
|
||||||
|
for sourceDir in "${sourceDirChildPathComponents[@]}"; do
|
||||||
|
rsync -a --delete -e 'ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes -o PasswordAuthentication=no -o ChallengeResponseAuthentication=no -o PubkeyAut
|
||||||
|
hentication=yes -o IdentityFile='"${sshFilesBaseDir}"'/'"${sshPrivateKeyFileName}"' -o UserKnownHostsFile='"${sshFilesBaseDir}"'/'"${sshKnownHostsFileName}" "${
|
||||||
|
sourceDirBasePath}"'/'"${sourceDir%/}" "${target}"'/'
|
||||||
|
if [[ "${?}" -eq '0' ]]; then
|
||||||
|
printf -- '%s\n' 'Successfully copied '"'${sourceDir}'"' data'
|
||||||
|
fi
|
||||||
|
done
|
Loading…
x
Reference in New Issue
Block a user