-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·150 lines (128 loc) · 3.74 KB
/
install.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env bash
#################################################
#### Ensure we are in the right path. ###########
#################################################
if [[ 0 -eq $(echo $0 | grep -c '^/') ]]; then
# relative path
EXEC_PATH=$(dirname "`pwd`/$0")
else
# absolute path
EXEC_PATH=$(dirname "$0")
fi
EXEC_PATH=$(echo ${EXEC_PATH} | sed 's@/\./@/@g' | sed 's@/\.*$@@')
cd $EXEC_PATH || exit 1
#################################################
#
# install `btm daemon` as a systemd service
# - replace all UPPER words in btm-daemon.service to their actual instances
# - copy `btm-daemon.service` to a right path
# - copy `btm` binary to '/usr/local/bin/'
# - enable `btm-daemon.service`
#
# example:
#
# ```
# install.sh \
# --snapshot-itv=4 \
# --snapshot-cap=100 \
# --snapshot-mode=zfs \
# --snapshot-algo=fair \
# --snapshot-volume=zfs/blockchain
# ```
#
usage() {
echo -e "\033[31;01mUsage\033[0m"
echo
echo -e "\tinstall.sh"
echo -e "\t\t--snapshot-itv=<ITV>"
echo -e "\t\t--snapshot-cap=<CAP>"
echo -e "\t\t--snapshot-mode=<MODE>"
echo -e "\t\t--snapshot-algo=<ALGO>"
echo -e "\t\t--snapshot-volume=<VOLUME>"
echo
echo -e "\033[31;01mExample\033[0m"
echo
echo -e "\tinstall.sh \\"
echo -e "\t\t--snapshot-itv=4 \\"
echo -e "\t\t--snapshot-cap=100 \\"
echo -e "\t\t--snapshot-mode=zfs \\"
echo -e "\t\t--snapshot-algo=fair \\"
echo -e "\t\t--snapshot-volume=zfs/blockchain"
echo
echo -e "\033[31;01mExample, short style\033[0m"
echo
echo -e "\tinstall.sh -i=4 -c=100 -m=zfs -a=fair -p=zfs/blockchain"
echo -e "\tinstall.sh -i=4 -c=100 -m=btrfs -a=fair -p=/data/blockchain"
echo
}
for i in "$@"; do
case $i in
-i=*|--snapshot-itv=*)
ITV="${i#*=}"
;;
-c=*|--snapshot-cap=*)
CAP="${i#*=}"
;;
-m=*|--snapshot-mode=*)
MODE="${i#*=}"
;;
-a=*|--snapshot-algo=*)
ALGO="${i#*=}"
;;
-p=*|--snapshot-volume=*)
VOLUME="${i#*=}"
;;
*)
usage
exit 1
;;
esac
done
if [[ "" == $ITV ]]; then
ITV=10
fi
expr $ITV + 0 2>/dev/null 1>&2
if [[ 0 -ne $? ]]; then
echo -e "\n\tthe value of \033[31;01m--snapshot-itv\033[0m is NOT a valid number !!\n"
exit 1
fi
if [[ "" == $CAP ]]; then
CAP=100
fi
expr $CAP + 0 2>/dev/null 1>&2
if [[ 0 -ne $? ]]; then
echo -e "\n\tthe value of \033[31;01m--snapshot-cap\033[0m is NOT a valid number !!\n"
exit 1
fi
if [[ "" == $MODE ]]; then
echo -e "\n\t\033[31;01m--snapshot-mode\033[0m is missing !!\n"
exit 1
fi
if [[ "zfs" != $MODE && "btrfs" != $MODE ]]; then
echo -e "\n\tthe value of \033[31;01m--snapshot-mode\033[0m can only be 'zfs' or 'btrfs' !!\n"
exit 1
fi
if [[ "" == $ALGO ]]; then
ALGO=fair
fi
if [[ "fair" != $ALGO && "fade" != $ALGO ]]; then
echo -e "\n\tthe value of \033[31;01m--snapshot-algo\033[0m can only be 'fair' or 'fade' !!\n"
exit 1
fi
if [[ "" == $VOLUME ]]; then
echo -e "\n\t\033[31;01m--snapshot-volume\033[0m is missing !!\n"
exit 1
fi
cp -f btm-daemon.service x.service
sed -i "s#ITV#${ITV}#g" x.service
sed -i "s#CAP#${CAP}#g" x.service
sed -i "s#MODE#${MODE}#g" x.service
sed -i "s#ALGO#${ALGO}#g" x.service
sed -i "s#VOLUME#${VOLUME}#g" x.service
target_path=$(dirname $(systemctl cat network.target | grep -o '#.*/network.target' | sed -r 's/^\s*#\s+//g'))
cp -f x.service ${target_path}/btm-daemon.service || exit 1
cp -f btm /usr/local/bin/ || exit 1
systemctl disable btm-daemon.service
systemctl enable btm-daemon.service
systemctl restart btm-daemon.service
systemctl status btm-daemon.service