forked from INFERLab/gridlab-d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
customize
122 lines (112 loc) · 2.68 KB
/
customize
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
#!/bin/bash
CUSTOMFILE="custom.mk"
function help_syntax ()
{
echo "Syntax: $(basename $0) <command> [<options> ...]"
}
function help ()
{
help_syntax
echo "
add <module> Add <module> to $CUSTOMFILE
delete <module> Delete <module> from $CUSTOMFILE
enable <module> Enable <module> in $CUSTOMFILE
disable <module> Disable <module> in $CUSTOMFILE
status Display status of modules matching <pattern>
sync_validate Add/remove validate.no files according to custom.mk
"
}
function add ()
{
F="$1/Makefile.mk"
if [ -z "$(grep $F $CUSTOMFILE)" ]; then
if [ -f $F ]; then
echo "include $F" >>$CUSTOMFILE
else
echo "module $1 is not a valid module (missing $F)"
fi
else
echo "$1 is already listed in $CUSTOMFILE"
sync_validate
fi
}
function delete ()
{
F="$1/Makefile.mk"
if [ -z "$(grep $F $CUSTOMFILE)" ]; then
if [ -f $F ]; then
echo "module $1 is not listed in $CUSTOMFILE"
else
echo "module $1 is not a valid module (missing $F)"
fi
else
T=".tmp$$"
grep -v $F $CUSTOMFILE >$T && mv $T $CUSTOMFILE
fi
}
function enable ()
{
F="$1/Makefile.mk"
if [ -z "$(grep $F $CUSTOMFILE)" ]; then
if [ -f $F ]; then
echo "module $1 is not listed in $CUSTOMFILE"
else
echo "module $1 is not a valid module (missing $F)"
fi
else
T=".tmp$$"
sed -e "1,\$s:^#include $F:include $F:" < $CUSTOMFILE >$T && mv $T $CUSTOMFILE
sync_validate
fi
}
function disable ()
{
F="$1/Makefile.mk"
if [ -z "$(grep $F $CUSTOMFILE)" ]; then
if [ -f $F ]; then
echo "module $1 is not listed in $CUSTOMFILE"
else
echo "module $1 is not a valid module (missing $F)"
fi
else
T=".tmp$$"
sed -e "1,\$s:^include $F:#include $F:" < $CUSTOMFILE >$T && mv $T $CUSTOMFILE
sync_validate
fi
}
function status ()
{
ENABLED=$(grep '^include' <$CUSTOMFILE | sed -e 's/include //g;s:/Makefile.mk::g')
DISABLED=$(grep '^#include' <$CUSTOMFILE | sed -e 's/#include //g;s:/Makefile.mk::g')
echo Enabled: $ENABLED
echo Disabled: $DISABLED
}
function sync_validate ()
{
ENABLED=$(grep '^include' <$CUSTOMFILE | sed -e 's/include //g;s:/Makefile.mk::g')
DISABLED=$(grep '^#include' <$CUSTOMFILE | sed -e 's/#include //g;s:/Makefile.mk::g')
for F in $ENABLED; do
if [ -f $F/validate.no ]; then
echo -n "removing $F/validate.no..."
rm $F/validate.no && echo "ok"
fi
done
for F in $DISABLED; do
if [ ! -f $F/validate.no ]; then
echo -n "adding $F/validate.no..."
echo "$*: $(date)" > $F/validate.no && echo "ok"
fi
done
}
if [ $# -eq 0 ]; then
help_syntax
else
case $1 in
(help|add|delete|enable|disable|status|sync_validate)
$*
;;
(*)
echo "$(basename $0): $1 is not a valid command"
;;
esac
fi