-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.sh
executable file
·90 lines (74 loc) · 2.4 KB
/
utils.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/sh
# $HOME/.local/src/srv-p2pool/utils.sh
set -e
SCRIPT_DIR=$(dirname -- "$0")
SCRIPT_DIR=$(cd -- "$SCRIPT_DIR" && pwd)
echo "$SCRIPT_DIR"
print_prog_desc()
{
echo "Simple helper script to commit server configration to GitHub"
echo
}
print_help()
{
echo "Syntax: ${0} [-m 'your commit message'|-s|-h]"
echo "options:"
echo "-s Only [s]ync changes without commit."
echo "-m 'Commit message' Add your custom commit [m]essage."
echo "-h Print this [h]elp."
echo
}
COMMIT_MESSAGE="chore(bot): Sync update $(date +'%Y-%m-%d %H:%M:%S')"
sync() {
mkdir "${SCRIPT_DIR}"/etc/systemd/system -p
mkdir "${SCRIPT_DIR}${HOME}/.config" -p
echo "Syncing monerod configs..."
rsync -av /etc/systemd/system/monerod.service \
"${SCRIPT_DIR}"/etc/systemd/system/monerod.service
rsync -av "${HOME}"/.config/monero "${SCRIPT_DIR}${HOME}/.config/"
echo "Copying p2pool systemd service and socket FIFO..."
cp -u /etc/systemd/system/p2pool.service \
"${SCRIPT_DIR}"/etc/systemd/system/p2pool.service
cp -u /etc/systemd/system/p2pool.socket \
"${SCRIPT_DIR}"/etc/systemd/system/p2pool.socket
echo "Syncing lib/p2pool..."
mkdir "${SCRIPT_DIR}${HOME}/.local/lib/p2pool" -p
rsync -av --delete \
--exclude core \
--exclude p2pool_peers.txt \
--exclude p2pool.* \
"${HOME}"/.local/lib/p2pool/ \
"${SCRIPT_DIR}${HOME}/.local/lib/p2pool/"
sed -i "s/WALLET_ADDR=\"[^\"]*\"/WALLET_ADDR=\"<redacted>\"/g" \
"${SCRIPT_DIR}${HOME}/.local/lib/p2pool/run.sh"
}
# `:` means "takes an argument", not "mandatory argument".
# That is, an option character not followed by `:` means a
# flag-style option (no argument), whereas an option
# character followed by `:` means an option with an argument.
# https://stackoverflow.com/questions/18414054/reading-optarg-for-optional-flags
while getopts ":hsm:" option; do
case $option in
h) # display Help
print_prog_desc
print_help
exit;;
s) # sync
sync
exit;;
m) # custom commit message
COMMIT_MESSAGE="$OPTARG"
;;
\?) # invalid option
echo "Invalid option!"
print_help
exit;;
esac
done
sync
cd "${SCRIPT_DIR}"
git checkout automation
git add .
git commit -m "${COMMIT_MESSAGE}"
git push -u origin automation
# vim: set ts=2 sw=2 et: