-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
115 lines (96 loc) · 2.36 KB
/
setup.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
#!/bin/sh
uid="BenSabry/UnboundRedis"
url="https://github.com/$uid/archive/refs/heads/main.zip"
tmp="/tmp/$uid"
dir="$tmp"
#region core functions
download() {
echo "Downloading $1"
{(
local url=$1
local path=$2
rm -rf $path
mkdir -p $path
cd $path
wget "$url"
zipfile="$(ls "$path/"*.zip | head -1)"
unzip $zipfile -d "$path"
rm $zipfile
extracted="$(ls -d "$path/"* | head -n 1)"
mv "$extracted"/* "$path"
rmdir "$extracted"
)} &> /dev/null
}
executable() {
if [ -n "$2" ]; then
find "$2" -type f -name "$1" -exec chmod +x {} \;
else
echo "executable(): exception, path argument can not be empty."
fi
}
copy() {
local src="$1"
local dst="$2"
# check if source exists
if [ ! -e "$src" ]; then
echo "Source $src does not exist."
return 1
fi
# if it's a file
if [ -f "$src" ]; then
# if destination file exists
if [ -e "$dst" ]; then
# overwrite its content, not the file itself
cat "$src" > "$dst"
else
# copy the file itself
cp "$src" "$dst"
fi
# if it's a directory
elif [ -d "$src" ]; then
# make sure destination path exists
mkdir -p "$dst"
# iterate over directory content
for item in "$src"/*; do
# recursively call the function with child item
copy "$item" "$dst/$(basename "$item")"
done
else
echo "Source $src is neither a file nor a directory."
return 1
fi
}
#endregion
#region logic functions
srcroot="$dir/content"
dstroot="/"
presetup() {
download $url $tmp
executable "*" "$srcroot/etc/init.d"
executable "*" "$srcroot/etc/periodic"
executable "*" "$srcroot/root/scripts"
executable "*" "$dir/scripts"
copy "$srcroot" "$dstroot"
}
setup() {
for item in "$dir"/scripts/*; do
"$item"
done
}
postsetup() {
copy "$srcroot" "$dstroot"
# register and run init.d services
for item in "$srcroot/etc/init.d"/*; do
if [ -f "$item" -a -e "$item" ]; then
local name="$(basename "$item")"
rc-update add "$name" default
service "$name" restart
fi
done
rm -rf "$tmp"
}
#endregion
presetup
setup
postsetup
echo "Setup completed"