-
Notifications
You must be signed in to change notification settings - Fork 14
/
build-latest
executable file
·57 lines (48 loc) · 1.24 KB
/
build-latest
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
#!/bin/bash
#
# Builds a history for the directory `latest/` by starting with
# an empty directory, committing that, and then copying-and-committing
# each dated version from `versions/` in turn.
#
#
# Directory and program name detection
#
# Preserve the original working dir as origDir.
origDir="${PWD}"
# Set progName to the program name, progDir to its directory, and baseDir
# to progDir's directory. Follows symlinks.
prog="$0"
while [[ -h ${prog} ]]; do
[[ "$(/bin/ls -ld "${prog}")" =~ .*' -> '(.*)$ ]]
newProg="${BASH_REMATCH[1]}"
if [[ ${newProg} =~ ^/ ]]; then
prog="${newProg}"
else
prog="$(dirname "${prog}")/${newProg}"
fi
done
progName="$(basename "${prog}")"
progDir="$(dirname "${prog}")"
cd "${progDir}"
progDir="${PWD}"
cd ..
baseDir="${PWD}"
cd "${origDir}"
unset prog
unset newProg
#
# Main script
#
if ! git --version >& /dev/null; then
echo "${progName}: Need git!" 1>&2
exit 1
fi
cd "${progDir}"
rm -rf latest
git commit -a -m "Clear out the latest/ directory. (via ${progName})"
for dir in $(cat versions/order.txt); do
rm -rf latest
cp -r "versions/${dir}" latest || exit 1
git add latest || exit 1
git commit -a -m "${dir}. (History generated via ${progName})" || exit 1
done