-
Notifications
You must be signed in to change notification settings - Fork 0
/
steps
executable file
·72 lines (53 loc) · 1.42 KB
/
steps
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
#!/bin/bash
# This script will execute every command listed here, one at a time, stopping on
# first error and logging commands and outputs to both stdout and a file.
if [ ! $1 ]; then
echo "Usage: "
echo "$0 <commands-list-file> <step-number>"
echo ""
echo "commands-list-file: a file listing the commands to run, one command per line."
echo "step-number: line number of the command to resume at, skipping all the ones before that."
echo ""
echo "$0 <commands-list-file> list"
echo ""
echo "list all steps with their number"
exit 1
fi
trap "echo '\nkeyboard interrupt'; exit 1" SIGINT
trap "exit 1" SIGTERM
commands=$(< $1)
export TOP_PID=$$
if [ $2 ]; then
skip_to=$(($2))
else
skip_to=0
fi
step_id=1
run_cmd()
{
if (( $step_id >= $skip_to )); then
printf "\nExecuting %02d: %s\n" $step_id "$1"
bash -c "$1"
if [ $? -ne 0 ]; then
printf "\nInstall failed on command %02d: %s\n" $step_id "$1"
kill -s TERM $TOP_PID
fi
else
printf "skipping step %02d: %s\n" $step_id "$line"
fi
}
if [ "$2" == "list" ]; then
while read -r line
do
printf "%02d: %s\n" $step_id "$line"
step_id=$((step_id + 1))
done <<< "$commands"
exit 0
fi
echo -e "\nNew run:" >> $1.log
while read -r line
do
run_cmd "$line" 2>&1 | tee -a "$1.log"
step_id=$((step_id + 1))
done <<< "$commands"
exit 0