setarch uname26 for DIST not in */*
[shellsnippets/shellsnippets.git] / mksh / debian-dev / c
1 #!/bin/mksh
2 #-
3 # Copyright © 2013, 2014
4 #       Thorsten “mirabilos” Glaser <t.glaser@tarent.de>
5 #
6 # Provided that these terms and disclaimer and all copyright notices
7 # are retained or reproduced in an accompanying document, permission
8 # is granted to deal in this work without restriction, including un‐
9 # limited rights to use, publicly perform, distribute, sell, modify,
10 # merge, give away, or sublicence.
11 #
12 # This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
13 # the utmost extent permitted by applicable law, neither express nor
14 # implied; without malicious intent or gross negligence. In no event
15 # may a licensor, author or contributor be held liable for indirect,
16 # direct, other damage, loss, or other issues arising in any way out
17 # of dealing in the work, even if advised of the possibility of such
18 # damage or existence of a defect, except proven that it results out
19 # of said person’s immediate fault when using the work as intended.
20 #-
21 # Simple-to-use wrapper around eatmydata plus cowbuilder to use with
22 # https://www.mirbsd.org/cvs.cgi/contrib/hosted/tg/deb/pbuilderrc to
23 # select the proper build chroot.
24 #
25 # Example:
26 # c lenny/i386 DEB_BUILD_OPTIONS=parallel=4 linux32 --build foo*.dsc
27
28 unset LANGUAGE
29 export LC_ALL=C
30 DIST=$1
31
32 # workaround for supporting old and new eatmydata; cf. #765579
33 eatmydata='LD_LIBRARY_PATH=/usr/lib/libeatmydata LD_PRELOAD=libeatmydata.so'
34 # disable for some distros without either
35 case ${DIST%/*} {
36 (sarge|sarge-*|etch|etch-*)
37         eatmydata=LD_PRELOAD=
38         ;;
39 }
40 if [[ $1 = --keepmydata ]]; then
41         eatmydata=LD_PRELOAD=
42         shift
43 fi
44
45 # construct command line
46 set -A cmd env "DIST=$DIST" LANG=C LC_CTYPE=C LC_NUMERIC=C \
47     LC_TIME=C LC_COLLATE=C LC_MONETARY=C LC_MESSAGES=C LC_PAPER=C \
48     LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=C \
49     LC_IDENTIFICATION=C LC_ALL=C $eatmydata
50 shift
51 while [[ $1 = *=* ]]; do
52         cmd[${#cmd[@]}]=$1
53         shift
54 done
55 setarch_seen=0
56 case $1 {
57 (--)
58         shift
59         ;;
60 (linux32|linux64)
61         cmd[${#cmd[@]}]=$1
62         shift
63         if [[ $1 = --uname-2.6 ]]; then
64                 cmd[${#cmd[@]}]=$1
65                 shift
66         fi
67         setarch_seen=1
68         ;;
69 }
70 #XXX add more architectures
71 case $DIST {
72 (*/amd64)       setarch_cmd=linux64 ;;
73 (*/i386)        setarch_cmd=linux32 ;;
74 (*/x32)         setarch_cmd=linux64 ;;
75 (*/*)           setarch_cmd= ;;
76 (*)             setarch_cmd=- ;;
77 }
78 case ${DIST%/*} {
79 (sarge|sarge-*)         setarch_26=1 ;;
80 (etch|etch-*)           setarch_26=1 ;;
81 (lenny|lenny-*)         setarch_26=1 ;;
82 (squeeze|squeeze-*)     setarch_26=1 ;;
83 (dapper|dapper-*)       setarch_26=1 ;;
84 (hardy|hardy-*)         setarch_26=1 ;;
85 (jaunty|jaunty-*)       setarch_26=1 ;;
86 (karmic|karmic-*)       setarch_26=1 ;;
87 (lucid|lucid-*)         setarch_26=1 ;;
88 (maverick|maverick-*)   setarch_26=1 ;;
89 (natty|natty-*)         setarch_26=1 ;;
90 (*)                     setarch_26=0 ;;
91 }
92 (( setarch_seen )) || case x$setarch_cmd {
93 (x)
94         print -ru2 "W: no setarch for architecture part of '$DIST'!"
95         ;;
96 (x-)
97         if (( setarch_26 )); then
98                 cmd[${#cmd[@]}]=setarch
99                 cmd[${#cmd[@]}]=uname26
100                 cmd[${#cmd[@]}]=--
101         fi
102         ;;
103 (*)
104         cmd[${#cmd[@]}]=$setarch_cmd
105         (( setarch_26 )) && cmd[${#cmd[@]}]=--uname-2.6
106         cmd[${#cmd[@]}]=--
107         ;;
108 }
109
110 set -x
111 exec sudo "${cmd[@]}" cowbuilder "$@"