-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·245 lines (215 loc) · 5.67 KB
/
build.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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#! /bin/sh
# vim: set sw=4:
set -e
myfullname="$0"
old_LANG="$LANG"
old_LC_ALL="$LC_ALL"
LANG=C
LC_ALL=C
showhelp() {
cat << EOF
Syntax:
$myname [option]... [var=value]... mode [mode-specific options]
Modes:
build
install
clean
distclean
fink [-r,--release]
Options:
-n, --dry-run display commands without modifying any files
-q, --quiet don't print informational messages
-d, --debug debug $myname
-h, --help show this message
Variables:
prefix[=/opt/sw]
destdir[empty]
srcdir[auto($mydir)]
Examples:
$myname -q destdir=/opt/sw/src/foobar install
$myname clean
EOF
return 0
}
badarg() {
test "x$1" != x && extra=" $1"
echo "Bad argument$extra; try $myname -h for more information." >&2
return 2
}
# Following constructs do not work:
# go some-command > somewhere
# go some-command | another-command
# go some-command && another-command
# Instead use go_r or go_p:
# go_r somewhere some-command
# go_p 'another-command' some-command
# Or do manually:
# $show some-command \&\& another-command
# $run some-command && $run another-command
go() {
$show "$@"
$run "$@"
}
go_r() {
dst="$1"
shift
$show "$@" \> "$dst"
case "x$run" in
x:) ;;
*) $run "$@" > "$dst" ;;
esac
}
go_p() {
dst="$1"
shift
eval '$show "$@" \| '"$dst"
$run "$@" | $run eval "$dst"
}
dobuild() {
go $mkinstalldirscmd "$builddir"
$show "creating build.sed"
if [[ -d /opt/X11/etc/X11/xinit ]]; then
xinitdir="/opt/X11/etc/X11/xinit";
elif [[ -d /opt/X11/lib/X11/xinit ]]; then
xinitdir="/opt/X11/lib/X11/xinit";
else
echo "xinit dir for X11 not found. Exiting."
exit 1;
fi
case "x$run" in
x:) ;;
*)
$run cat > "$builddir/build.sed" << EOF
s|@PREFIX@|$prefix|g
s|@XINITDIR@|$xinitdir|g
s|@X_BINDIR@|/opt/X11/bin|g
EOF
;;
esac
for src in "$srcdir"/sedsrc/*.in; do
base=`basename "$src" .in`
go_r "$builddir/$base" /usr/bin/sed -f "$builddir/build.sed" "$src"
done
}
doinstall() {
go $mkinstalldirscmd -m 755 "$destdir$bindir"
go $mkinstalldirscmd -m 755 "$destdir$sbindir"
go $mkinstalldirscmd -m 755 "$destdir$mydatadir"
go $mkinstalldirscmd -m 755 "$destdir$mydocdir"
go $mkinstalldirscmd -m 755 "$destdir$sysconfdir/xinitrc.d"
$show cd "$builddir"
cd "$builddir"
go $installcmd -m 755 xinitrc.sh "$destdir$bindir"
go $installcmd -m 755 update-sys-xinitrc "$destdir$sbindir"
go $installcmd -m 644 sys-xinitrc-fink "$destdir$mydatadir"
$show cd "$firstpwd"
cd "$firstpwd"
$show cd "$srcdir/doc"
cd "$srcdir/doc"
go $installcmd -m 644 README.txt numbering.txt "$destdir$mydocdir"
$show cd "../simple"
cd "../simple"
go $installcmd -m 755 [0-9][0-9]*.sh "$destdir$sysconfdir/xinitrc.d"
}
doclean() {
go rm -rf "$builddir" "$pkgname.info" "$pkgname.patch" "$pkgname-"*".tar.gz"
}
dodistclean() {
doclean
go_p 'xargs rm -f' find . -name "semantic.cache" -or -name "*~" -or -name "*.bak" -or -name ".*.swp"
}
dofink() {
version=`cat $srcdir/version`
case "x$1" in
x-r|x--release)
gitver=
fullver="$version"
sedargs="-e s/@TARDIST@//g -e s/@PATCHDIST@/#/g"
;;
x)
gitcommit=`/usr/bin/git rev-parse HEAD 2>/dev/null | cut -b 1-8`
gitver="+git-$gitcommit"
fullver="$version$gitver"
sedargs="-e s/@TARDIST@/#/g -e s/@PATCHDIST@//g"
;;
*) badarg "$1"; exit ;;
esac
files=".gitignore ChangeLog build.sh doc/ $pkgname.info.in sedsrc/ simple/ version"
sedargs="$sedargs -e s/@FULLVERSION@/$fullver/g"
workdir="$pkgname-$fullver"
go rm -rf "$workdir" "$workdir.dummy"
trap 'go rm -rf "$workdir" "$workdir.dummy"' 0
go mkdir "$workdir" "$workdir.dummy"
$show \( cd "$srcdir" \&\& tar cf - $files \) \| \( cd "$workdir" \&\& tar xf - \)
( cd "$srcdir" && $run tar cf - $files ) | ( $run cd "$workdir" && $run tar xf - )
go_p 'xargs rm -r' find "$workdir" -name .git -type d
case "x$gitcommit" in
x)
go tar zcf "$pkgname-$fullver.tar.gz" "$workdir"
sha256=`$run /usr/bin/shasum -a 256 "$pkgname-$fullver.tar.gz" | cut -f1 -d' '`
sedargs="$sedargs -e s/@SHA256@/$sha256/g"
;;
*)
set +e
go_r "$pkgname.patch" diff -Nru "$workdir.dummy" "$workdir"
set -e
;;
esac
go_r "$pkgname.info" /usr/bin/sed $sedargs "$srcdir/$pkgname.info.in"
}
myname=`basename "$0"`
case "x$myfullname" in
x*/*) mydir=`echo "$myfullname" | /usr/bin/sed 's|/[^/]*$||'` ;;
*) mydir=. ;;
esac
pkgname="xinitrc"
destdir=
srcdir="$mydir"
builddir="build"
firstpwd=`pwd`
mkinstalldirscmd="mkdir -p"
installcmd="install"
echocmd="echo"
# more portable way
#echo="printf '%s\n'"
run=
show="$echocmd"
mode=
while test "$#" -gt 0; do
case "x$1" in
x-n|x--dry-run) run=: ;;
x-q|x--quiet) show=: ;;
x-d|x--debug) set -x ;;
x-h|x--help) showhelp; exit ;;
x-*) badarg "$1"; exit ;;
x*=*) eval "$1" ;;
x*) mode="$1"; shift; break ;;
esac
shift
done
: ${prefix="/opt/sw"}
: ${exec_prefix="${prefix}"}
: ${bindir="${exec_prefix}/bin"}
: ${sbindir="${exec_prefix}/sbin"}
: ${libexecdir="${exec_prefix}/lib"}
: ${datadir="${prefix}/share"}
: ${sysconfdir="${prefix}/etc"}
: ${sharedstatedir="${prefix}/var"}
: ${localstatedir="${prefix}/var"}
: ${libdir="${exec_prefix}/lib"}
: ${includedir="${prefix}/include"}
: ${oldincludedir="/usr/include"}
: ${infodir="${prefix}/share/info"}
: ${mandir="${prefix}/share/man"}
: ${docdir="${prefix}/share/doc"}
: ${mydatadir="${datadir}/$pkgname"}
: ${mydocdir="${docdir}/$pkgname"}
case "x$mode" in
x|xhelp) showhelp; exit ;;
xbuild) dobuild "$@" ;;
xinstall) doinstall "$@" ;;
xclean) doclean "$@" ;;
xdistclean) dodistclean "$@" ;;
xfink) dofink "$@" ;;
*) badarg "$mode"; exit ;;
esac