forked from Balaselvi/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_screen.sh
executable file
·88 lines (75 loc) · 1.79 KB
/
update_screen.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
#!/bin/bash
lockfile .screen
target_list_file=/tmp/target_list
touch ${target_list_file}
function scroll_up {
# Check if TERM is available
[[ "${TERM}" == "dumb" ]] && return
for i in $(cat ${target_list_file}); do
tput cuu1
tput el
done
}
function print_targets {
# Check if TERM is available
[[ "${TERM}" == "dumb" ]] && return
count=1
for i in $(cat ${target_list_file}); do
printf "[ %02d ] [ %s ]\n" "${count}" "$i"
((count++))
done
}
function remove_target {
# Check if TERM is available
[[ "${TERM}" == "dumb" ]] && echo "[ finished ] [ $1 ] " && return
old_list=$(cat ${target_list_file})
rm ${target_list_file}
for target in ${old_list}; do
if [[ "${target}" != "$1" ]]; then
echo ${target} >> ${target_list_file}
fi
done
touch ${target_list_file}
}
function add_target {
# Check if TERM is available
[[ "${TERM}" == "dumb" ]] && echo "[ building ] [ $1 ] " && return
echo $1 >> ${target_list_file}
}
function print_targets_delay {
sleep 2 && print_targets && rm -f .screen &
exit 0
}
while getopts ":a:d:e:" opt; do
case $opt in
a)
scroll_up
add_target ${OPTARG}
print_targets
;;
d)
scroll_up
remove_target ${OPTARG}
print_targets
;;
e)
scroll_up
remove_target ${OPTARG}
echo "[ FAIL LOG START ] [ ${OPTARG} ]"
cat ${OPTARG}.log
echo "[ FAIL LOG END ] [ ${OPTARG} ]"
print_targets_delay
;;
\?)
echo "Invalid option: -$OPTARG" >&2
rm -f .screen
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
rm -f .screen
exit 1
;;
esac
done
rm -f .screen