-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmakeTemplate.sh
executable file
·166 lines (165 loc) · 4.37 KB
/
makeTemplate.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env bash
# shellcheck disable=SC2164,SC2103,SC2317
modules=("vkd3d" "dxvk" "dxvk-async" "dxvk-nvapi" "wine-games" "wine-mainline" "tdfutils" "xutils" "zenity" "msi" "vcredist" "corefonts")
fail(){
echo "Build failed: $1"
exit 1
}
hasCommand(){
command -v "$1" > /dev/null
return $?
}
export -f fail
export -f hasCommand
if [[ "$PWD" = *" "* ]]; then
fail "The current path ($PWD) contains spaces, this will cause Wine to fail to build, move TDF somewhere else"
fi
if [ "$1" = "clean" ]; then
echo "Cleaning up"
rm -f state
for module in "${modules[@]}"; do
cd "$module"
if ! ./clean.sh; then
fail "Clean failed for module $module"
fi
cd ..
done
echo "Done!"
fi
if [ -z "$TDF_BUILD_STARTED" ]; then
if [ -n "$TDF_BUILD_AUTOUPDATE" ]; then
if [ -d .git ]; then
echo "Checking for TDF updates"
git fetch --all -p
git reset --hard origin/"$(git branch --show-current)" > /dev/null
TDF_BUILD_STARTED=1 ./makeTemplate.sh && exit 0
exit 0
else
echo "Not a git repo, please check for TDF updates manually"
fi
else
echo "This is a git repo, use TDF_BUILD_AUTOUPDATE=1 ./makeTemplate.sh to automatically download TDF updates"
sleep 1
fi
fi
startT=$SECONDS
failedDepsCheck=0
for module in "${modules[@]}"; do
cd "$module"
for f in ./0-*.sh; do
if ! "$f"; then
failedDepsCheck=1
fi
done
cd ..
done
if ! command -v zstd > /dev/null; then
echo "zstd not installed"
failedDepsCheck=1
fi
if [ $failedDepsCheck -eq 1 ]; then
fail "missing dependencies"
fi
failedModules=()
version=$(date +"%Y%m%d")
startState=0
if [ -f state ]; then
startState="$(cat state)"
startState=$((startState))
fi
for state in {1..3}; do
echo "$state" > state
for module in "${modules[@]}"; do
skip=0
for f in "${failedModules[@]}"; do
if [ "$module" = "$f" ]; then
skip=1
break
fi
done
if [ $skip -eq 1 ]; then
echo "WARNING: $module has fallbacked, skipping state $state"
continue
fi
cd "$module"
modState=0
if [ -f state ]; then
modState="$(cat state)"
modState=$((modState))
fi
if [ "$modState" -gt "$state" ]; then
echo "RESUME: $module is in state $modState, current state is $state, skipping this phase"
cd ..
continue
fi
ok=0
for f in "./$state"-*.sh; do
if [ ! -f "$f" ]; then
continue
fi
ok=1
if ! "$f"; then
echo "FAILED: $module, phase $state, script $f"
if [ -x fallback.sh ]; then
echo "Attempting fallback for module $module"
failedModules+=("$module")
if ! ./fallback.sh; then
fail "$module, both the regular build and the fallback have failed"
fi
break
else
echo "No fallback available for this module"
fail "$module"
fi
fi
done
if [ "$ok" -ne 1 ]; then
echo "$module has no scripts for phase $state, skipping"
echo "$((state+1))" > state
fi
cd ..
done
done
rm -f state
time=$((SECONDS - startT))
ss=$((time % 60))
mm=$(( ( time / 60 ) % 60 ))
hh=$((time / 3600))
if [ $hh -lt 1 ]; then
hh=""
else
hh="${hh}h "
fi
if [[ $hh -lt 1 && $mm -lt 1 ]]; then
mm=""
else
mm="${mm}m "
fi
ss="${ss}s"
echo "Build completed in $hh$mm$ss"
echo "Copying files"
dir="template-$version"
rm -rf "$dir"
cp -r template-base "$dir"
for module in "${modules[@]}"; do
cp -r "$module/build" "$dir/system/$module"
done
if [ ${#failedModules[@]} -ne 0 ]; then
echo "WARNING: The following modules failed to build, a fallback version was used instead"
for module in "${failedModules[@]}"; do
echo "* $module"
done
fi
echo "v$version" > "$dir/system/version"
echo "Packaging template, this will take a few minutes"
cd "$dir"
chmod -R 777 .
./run.sh archive
cd ..
echo "Cleaning up"
for module in "${modules[@]}"; do
rm -f "$module/state"
done
rm -rf "$dir"
echo "Done!"
exit 0