Skip to content

Commit e4a545e

Browse files
committed
sudo
1 parent 55f81bf commit e4a545e

File tree

2 files changed

+98
-1
lines changed

2 files changed

+98
-1
lines changed

backup_pi_files

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail -o errtrace
4+
5+
CONFIG=/boot/config.txt
6+
HOST_CSV=false
7+
8+
usage(){
9+
echo "Usage: $(basename "${0}") -l <CSV_PI_HOSTNAMES>"
10+
echo "Run this from laptop."
11+
echo " -l CSV_PI_HOSTNAMES"
12+
13+
exit 1
14+
}
15+
16+
main(){
17+
trap 'fail $? $LINENO' ERR
18+
19+
parseOpts "$@"
20+
21+
for host in $(echo $HOST_CSV | tr , ' '); do
22+
backupHost "$host"
23+
done
24+
25+
info "\\nDone!"
26+
}
27+
28+
parseOpts(){
29+
while getopts ":l:h" opt; do
30+
case ${opt} in
31+
l) HOST_CSV=${OPTARG} ;;
32+
\?)
33+
warn "Invalid option: -$OPTARG"
34+
usage
35+
;;
36+
:)
37+
warn "Option -$OPTARG requires an argument."
38+
usage
39+
;;
40+
*) usage ;;
41+
esac
42+
done
43+
44+
# Validation
45+
local has_usage_errors
46+
has_usage_errors=false
47+
if [ -z "$HOST_CSV" ]; then
48+
has_usage_errors=true
49+
warn "Please supply a list of pi hostnames with the flag: -l"
50+
fi
51+
if [[ $has_usage_errors == "true" ]]; then
52+
usage
53+
fi
54+
}
55+
56+
backupHost(){
57+
local host=$1
58+
local pretty_host
59+
pretty_host=$(echo "$host" | tr . _)
60+
61+
local files="/home/pi/.zsh_history"
62+
if [[ $host == pifi* ]]; then
63+
files="$files /home/pi/.sqlite_history /home/pi/development/pifi/config.json /home/pi/development/pifi/pifi.db"
64+
fi
65+
66+
mkdir -p "$pretty_host"
67+
pushd "$pretty_host"
68+
for file in $files; do
69+
info "\\nBacking up $file from $host..."
70+
scp -o StrictHostKeyChecking=no -o 'UserKnownHostsFile /dev/null' "pi@$host":"$file" .
71+
done
72+
popd
73+
}
74+
75+
fail(){
76+
local exit_code=$1
77+
local line_no=$2
78+
local script_name
79+
script_name=$(basename "${BASH_SOURCE[0]}")
80+
die "Error in $script_name at line number: $line_no with exit code: $exit_code"
81+
}
82+
83+
info(){
84+
echo -e "\x1b[32m$*\x1b[0m" # green stdout
85+
}
86+
87+
warn(){
88+
echo -e "\x1b[33m$*\x1b[0m" # yellow stdout
89+
}
90+
91+
die(){
92+
echo
93+
echo -e "\x1b[31m$*\x1b[0m" >&2 # red stderr
94+
exit 1
95+
}
96+
97+
main "$@"

bluetooth-audio-server/install_or_update_bluetooth_audio_server.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ updateBluetoothConfig(){
147147
fi
148148

149149
# Ensure that if the NAME has spaces, it doesn't get fucked up
150-
cmd="bluetoothctl system-alias '$NAME'"
150+
cmd="sudo bluetoothctl system-alias '$NAME'"
151151
eval "$cmd"
152152
}
153153

0 commit comments

Comments
 (0)