Merge pull request #580 from qbit/bkp_rstr_compat
Make backup / restore use POSIX shell for portability.
This commit is contained in:
commit
3df35ef03b
scripts
@ -1,26 +1,54 @@
|
|||||||
#!/usr/bin/env bash
|
#!/bin/sh
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
echo "Usage: backup.sh [-honu] [-h] [-u user] [-n host name or ip] [-o output]"
|
||||||
|
}
|
||||||
|
|
||||||
|
while getopts "ho:n:u:" arg; do
|
||||||
|
case $arg in
|
||||||
|
h)
|
||||||
|
usage
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
n)
|
||||||
|
UNIT_HOSTNAME=$OPTARG
|
||||||
|
;;
|
||||||
|
o)
|
||||||
|
OUTPUT=$OPTARG
|
||||||
|
;;
|
||||||
|
u)
|
||||||
|
USERNAME=$OPTARG
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
# name of the ethernet gadget interface on the host
|
# name of the ethernet gadget interface on the host
|
||||||
UNIT_HOSTNAME=${1:-10.0.0.2}
|
UNIT_HOSTNAME=${UNIT_HOSTNAME:-10.0.0.2}
|
||||||
# output backup tgz file
|
# output backup tgz file
|
||||||
OUTPUT=${2:-pwnagotchi-backup.tgz}
|
OUTPUT=${OUTPUT:-${UNIT_HOSTNAME}-backup-$(date +%s).tgz}
|
||||||
# username to use for ssh
|
# username to use for ssh
|
||||||
USERNAME=${3:-pi}
|
USERNAME=${USERNAME:-pi}
|
||||||
# what to backup
|
# what to backup
|
||||||
FILES_TO_BACKUP=(
|
FILES_TO_BACKUP="/root/brain.nn \
|
||||||
/root/brain.nn
|
/root/brain.json \
|
||||||
/root/brain.json
|
/root/.api-report.json \
|
||||||
/root/.api-report.json
|
/root/.ssh \
|
||||||
/root/.bashrc
|
/root/.bashrc \
|
||||||
/root/handshakes
|
/root/.profile \
|
||||||
/root/peers
|
/root/handshakes \
|
||||||
/etc/pwnagotchi/
|
/root/peers \
|
||||||
/var/log/pwnagotchi.log
|
/etc/pwnagotchi/ \
|
||||||
/var/log/pwnagotchi*.gz
|
/etc/ssh/ \
|
||||||
/home/pi/.bashrc
|
/var/log/pwnagotchi.log \
|
||||||
)
|
/var/log/pwnagotchi*.gz \
|
||||||
|
/home/pi/.ssh \
|
||||||
|
/home/pi/.bashrc \
|
||||||
|
/home/pi/.profile"
|
||||||
|
|
||||||
ping -c 1 "${UNIT_HOSTNAME}" >/dev/null || {
|
ping -w 3 -c 1 "${UNIT_HOSTNAME}" > /dev/null 2>&1 || {
|
||||||
echo "@ unit ${UNIT_HOSTNAME} can't be reached, make sure it's connected and a static IP assigned to the USB interface."
|
echo "@ unit ${UNIT_HOSTNAME} can't be reached, make sure it's connected and a static IP assigned to the USB interface."
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,50 @@
|
|||||||
#!/usr/bin/env bash
|
#!/bin/sh
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
echo "Usage: restore.sh [-bhnu] [-h] [-b backup name] [-n host name] [-u user name]"
|
||||||
|
}
|
||||||
|
|
||||||
|
while getopts "hb:n:u:" arg; do
|
||||||
|
case $arg in
|
||||||
|
b)
|
||||||
|
BACKUP=$OPTARG
|
||||||
|
;;
|
||||||
|
h)
|
||||||
|
usage
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
n)
|
||||||
|
UNIT_HOSTNAME=$OPTARG
|
||||||
|
;;
|
||||||
|
u)
|
||||||
|
USERNAME=$OPTARG
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
exit 1
|
||||||
|
esac
|
||||||
|
done
|
||||||
# name of the ethernet gadget interface on the host
|
# name of the ethernet gadget interface on the host
|
||||||
UNIT_HOSTNAME=${1:-10.0.0.2}
|
UNIT_HOSTNAME=${UNIT_HOSTNAME:-10.0.0.2}
|
||||||
# output backup tgz file
|
# output backup tgz file
|
||||||
BACKUP=${2:-pwnagotchi-backup.tgz}
|
if [ -z $BACKUP ]; then
|
||||||
|
BACKUP=$(ls -rt ${UNIT_HOSTNAME}-backup-*.tgz 2>/dev/null | tail -n1)
|
||||||
|
if [ -z $BACKUP ]; then
|
||||||
|
echo "@ Can't find backup file. Please specify one with '-b'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "@ Found backup file:"
|
||||||
|
echo "\t${BACKUP}"
|
||||||
|
echo -n "@ continue restroring this file? (y/n) "
|
||||||
|
read CONTINUE
|
||||||
|
CONTINUE=$(echo "${CONTINUE}" | tr "[:upper:]" "[:lower:]")
|
||||||
|
if [ "${CONTINUE}" != "y" ]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
# username to use for ssh
|
# username to use for ssh
|
||||||
USERNAME=${3:-pi}
|
USERNAME=${USERNAME:-pi}
|
||||||
|
|
||||||
ping -c 1 "${UNIT_HOSTNAME}" >/dev/null || {
|
ping -w 3 -c 1 "${UNIT_HOSTNAME}" > /dev/null 2>&1 || {
|
||||||
echo "@ unit ${UNIT_HOSTNAME} can't be reached, make sure it's connected and a static IP assigned to the USB interface."
|
echo "@ unit ${UNIT_HOSTNAME} can't be reached, make sure it's connected and a static IP assigned to the USB interface."
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user