-
Notifications
You must be signed in to change notification settings - Fork 0
/
build
executable file
·92 lines (81 loc) · 2.32 KB
/
build
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
#!/bin/sh
# build ports with poudriere
#
# Usage: build [-U] [-W]
# -U: do not update the ports tree before building
# -W: if tmux is running locally (and local is not the build host), then do
# not create a new tmux window
#
# globals expected in ${HOME}/.ports.conf with sample values
# bhost='storage2.mathstat.dal.ca' # build host
# bjail='12amd64' # build jail
# listf='.pl' # list file of ports to build
# if no path is supplied in listf, then ${HOME}/ is assumed
. "$HOME/.ports.conf"
usage () {
[ -n "$*" ] && printf "%s\\n" "$*" 1>&2
cat <<EOF 1>&2
Usage: ${0##*/} [-U][-W]
EOF
}
create_listf() {
cat "$listf".* > "$listf"
sort -u "$listf" -o "$listf"
}
build () {
if [ "$(hostname)" != "$bhost" ]; then
if pgrep -q tmux && [ "$newtw" != 'no' ]; then
tmux neww \; send "ssh $bhost" KPEnter "build $nu" KPEnter
else
ssh -t "$bhost" "build $nu"
fi
else
if ! command -v tmux >/dev/null 2>&1; then
printf "tmux is required on the build host.\\n"
exit 1
fi
if ! [ -f "$listf" ]; then
printf "The file, %s, does not exist.\\n" "$listf"
exit 1
elif ! [ -r "$listf" ]; then
printf "The file, %s, is not readable.\\n" "$listf"
exit 1
elif ! [ -s "$listf" ]; then
printf "Nothing new to build. The file, %s, is empty.\\n" "$listf"
return 0
else
# if tmux ls 2>&1 | grep -q '^build:'; then
# tmux neww -t '=build'
# else
# tmux new -d -s 'build'
# fi
# [ -z "$nu" ] && tmux send -t '=build:$' pull KPENTER
# tmux send -t '=build:$' "sudo poudriere options -j $bjail -f $listf \
# && sudo poudriere bulk -j $bjail -f $listf" KPEnter
# tmux att -d -t '=build' > /dev/null 2>&1
pull && \
#sudo poudriere options -j "$bjail" -f "$listf" && \
sudo poudriere bulk -j "$bjail" -f "$listf"
fi
fi
}
############################################ main
OPTIND=1
while getopts ":UW" opt; do
case $opt in
U) nu='-U' ;;
W) newtw=no ;;
*) usage "Invalid option: -$OPTARG."
exit 1
;;
esac
done
shift $((OPTIND-1))
if ! command -v tmux >/dev/null 2>&1 && [ "$newtw" != 'no' ]; then
printf "tmux is required locally unless -W is specified.\\n"
exit 1
fi
[ $# != 0 ] && { usage; exit 1; }
[ -n "${listf##/*}" ] && listf="${HOME}/$listf"
create_listf
build