Annotation of elwix/config/rc.subr, revision 1.9
1.1 misho 1: #
2: # ELWIX project build helper subroutines
3: #
4: # (C) AITNET ltd - Sofia/Bulgaria <office@aitnet.org>
5: # by Michael Pounov <misho@elwix.org>
6: #
1.9 ! misho 7: # $Id: rc.subr,v 1.8.2.8 2014/01/30 08:49:04 misho Exp $
1.1 misho 8: #
9:
10: ### Dont edit this file !!!
11:
12: CheckVer()
13: {
14: [ -z "$1" -o ! -r "$1" ] && return 1
15:
16: cat $1 | awk '($1 == "ELWIX") { split($3, arr, ":"); printf("%s", arr[2]); }'
17: return 0
18: }
19:
20: SnitVer()
21: {
22: install -d ${TOPDIR}
23:
24: V=$(CheckVer $1)
25:
26: if [ $? -ne 0 ]; then
27: # file not found
28: return 1
29: elif [ X"$V" != X"${VERSION}" ]; then
30: # different ELWIX version
31: return 2
32: fi
33:
34: # already present file with same version
35: return 0
36: }
37:
1.7 misho 38: Create_etc_motd()
39: {
40: ELWIX_VER="ELWIX-${VERSION}_$2_${TARGET_ARCH}";
41: ELWIX_HDR_MOTD="${ELWIX_VER} :: Build date ${BUILD_DATE}";
42:
43: awk -v fo="${1:-motd}" 'BEGIN { print "'"${ELWIX_HDR_MOTD}"'" > fo; } { print $0 >> fo; }' \
44: ${CFGDIR}/elwix_signature.txt;
45: }
46:
47: # $1 = fs/elwix
48: # $2 = config/etc/default
49: MakeFS_var()
50: {
51: cd $1
52:
53: install -d altroot;
54: install -d altroot/var;
55: install -d altroot/var/account;
56: install -d altroot/var/at;
57: install -d altroot/var/at/jobs;
58: install -d altroot/var/at/spool;
59: install -d -g 63 -m 0770 altroot/var/authpf;
60: install -d -m 0750 altroot/var/cron;
61: install -d -m 0700 altroot/var/cron/tabs;
62: install -d altroot/var/db;
63: install -d -m 0555 altroot/var/empty;
64: install -d altroot/var/log;
1.8 misho 65: install -d -o 80 -g 80 -m 0700 altroot/var/log/lighttpd;
1.7 misho 66: install -d -o 101 -g 101 altroot/var/log/quagga;
67: install -d -o 883 -g 883 altroot/var/mqtt;
1.8 misho 68: install -d altroot/var/frm;
1.7 misho 69: install -d altroot/var/run;
1.8 misho 70: install -d -o 80 -g 80 altroot/var/run/lighttpd;
1.7 misho 71: install -d -o 101 -g 101 altroot/var/run/quagga;
72: install -d altroot/var/spool;
73: install -d -o 66 -g 68 -m 0775 altroot/var/spool/lock;
1.8 misho 74: install -d -o 80 -g 80 -m 0775 altroot/var/spool/lighttpd;
75: install -d -o 80 -g 80 altroot/var/spool/lighttpd/sockets;
1.7 misho 76: install -d -g 1 altroot/var/spool/lpd;
77: install -d -g 1 altroot/var/spool/output;
78: install -d -g 1 altroot/var/spool/output/lpd;
1.8 misho 79: install -d -o 59 -g 59 altroot/var/unbound;
1.7 misho 80:
81: ln -fs /tmp altroot/var/tmp;
82:
83: touch altroot/var/run/utmp
84:
85: touch altroot/var/account/acct
86:
87: touch altroot/var/log/elwix
88: touch altroot/var/log/lastlog
89: touch altroot/var/log/wifi.log
90: touch altroot/var/log/utx.log
91:
92: touch altroot/var/log/auth.log
93: touch altroot/var/log/cron
94: touch altroot/var/log/console.log
95: touch altroot/var/log/debug.log
96: touch altroot/var/log/init.log
97: touch altroot/var/log/lpd-errs
98: touch altroot/var/log/maillog
99: touch altroot/var/log/messages
100: touch altroot/var/log/security
101: touch altroot/var/log/xferlog
102: touch altroot/var/log/ppp.log
103: chgrp 69 altroot/var/log/ppp.log
104:
105: install -v $2/resolv.safe altroot/var/run/resolv.conf
106:
107: cd -
108: }
109:
110: # $1 = fs/elwix
111: # $2 = config/etc/default
112: # $3 = name
113: MakeFS_etc()
114: {
115: InstallDir $2 $1/etc
116:
117: chown -R root:wheel $1/etc;
118:
1.9 ! misho 119: case "$3" in
! 120: uboot)
! 121: ;;
! 122: *)
! 123: chmod 0600 $1/etc/opieaccess;
! 124: chmod 0600 $1/etc/opiekeys;
! 125: ;;
! 126: esac
1.7 misho 127:
128: chmod 0600 $1/etc/master.passwd;
129: chmod 0600 $1/etc/spwd.db;
130: chmod 0600 $1/etc/ssh/ssh_host_dsa_key;
131: chmod 0600 $1/etc/ssh/ssh_host_key;
132: chmod 0600 $1/etc/ssh/ssh_host_rsa_key;
133: chmod 0600 $1/etc/ssh/ssh_host_ecdsa_key;
134:
135: chmod 0440 $1/etc/sudoers;
136:
1.9 ! misho 137: # chgrp 80 $1/etc/config.xml;
! 138: # chmod 0660 $1/etc/config.xml;
1.7 misho 139:
140: mkdir -p $1/etc/mqtt;
141: chgrp -R 883 $1/etc/mqtt;
142: chown -R 883 $1/etc/mqtt;
143:
144: ln -sf /etc/rc.s $1/etc/rc.S
145:
146: ln -sf /usr/share/zoneinfo/${TIMEZONE} $1/etc/localtime;
147: ln -sf /usr/share/misc/termcap $1/etc/termcap;
148:
149: ln -sf /var/run/resolv.conf $1/etc/resolv.conf;
150:
1.9 ! misho 151: # ln -sf /elwix/pkg/etc/mk.conf $1/etc/mk.conf;
1.7 misho 152:
153: echo ${TARGET_ARCH} >$1/etc/platform;
154:
155: Create_etc_motd $1/etc/motd $3;
156:
157: CleanCVS $1
158: CleanCVS $1/etc
159: }
160:
161: # $1 = fs/elwix
162: MakeFS_home()
163: {
164: install -d $1/root/.ssh
165: [ -r ${CFGDIR}/root.skel/ssh/authorized_keys2 ] && \
166: install -v ${CFGDIR}/root.skel/ssh/authorized_keys2 $1/root/.ssh;
167:
168: install -v ${CFGDIR}/root.skel/cshrc $1/root/.cshrc;
169: install -v ${CFGDIR}/root.skel/login $1/root/.login;
170: install -v ${CFGDIR}/root.skel/logout $1/root/.logout;
171: install -v ${CFGDIR}/root.skel/profile $1/root/.profile;
172: install -v ${CFGDIR}/root.skel/vimrc $1/root/.vimrc;
173: }
174:
175: # $1 = fs/elwix
176: MakeFS_backup()
177: {
178: mkdir -p $1/altroot/backup
179:
180: cd $1
1.9 ! misho 181: # cp -p etc/config.xml altroot/backup
1.7 misho 182: tar -czf altroot/backup/.etc.tgz etc
183:
184: cd altroot
185: tar -czf backup/.var.tgz var
186: }
187:
188: # $1 = fs
189: MakeFS_boot()
190: {
191: InstallDir ${WORLD}/boot $1/boot
192:
193: install -m 644 ${CFGDIR}/boot/boot.config $1;
194:
1.9 ! misho 195: case ${TARGET} in
! 196: i386)
! 197: install -m 444 ${CFGDIR}/boot/beastie.4th $1/boot;
! 198: install -m 444 ${CFGDIR}/boot/brand.4th $1/boot;
! 199: install -m 444 ${CFGDIR}/boot/menu.4th $1/boot;
! 200: ;;
! 201: *)
! 202: ;;
! 203: esac
1.7 misho 204:
205: install -m 444 ${KERNDEVHINTS} $1/boot/device.hints;
206:
207: if [ -r ${CFGDIR}/boot/loader_${TARGET_ARCH}.conf ]; then
208: install -m 644 ${CFGDIR}/boot/loader_${TARGET_ARCH}.conf $1/boot/loader.conf;
209: fi;
210: }
211:
1.1 misho 212: # $1 = ELWIX install list config
213: # $2 = From World dir
214: # $3 = To Dest dir
215: InstallList()
216: {
1.4 misho 217: local TMPFILE=$(mktemp -q /tmp/instlist.XXXXXX)
218: if [ $? -ne 0 ]; then
219: echo "Error:: Can't create temp file, exiting..."
220: exit 1
221: fi
222:
223: sed -nE -e 's/^ *([^ #]+) */\1/p' < $1 | tr ':' '\n' >$TMPFILE
224: cd $2
225: for i in $(cat $TMPFILE); do
226: if [ -x $i ]; then
227: echo "Strip '$i'"
1.9 ! misho 228: ${CEXEC} chflags -f noschg $i
! 229: ${CEXEC} strip -s $i
1.4 misho 230: fi
231: done
232: cd -
233: tar -C $2 -cvf - -T $TMPFILE | tar -C $3 -x -f -
234: rm -f $TMPFILE
1.1 misho 235: }
236:
237: # $1 = From dir
238: # $2 = To dir
1.2 misho 239: InstallDir()
1.1 misho 240: {
241: cd $1
242: pax -rw -pe -X . $2
243: cd -
244: }
245:
246: # $* = Program arguments for install tool
247: InstallProg()
248: {
249: install -c $*
250: }
1.2 misho 251:
252: # $1 = file_pattern
1.3 misho 253: # $2 = From dir
254: # $3 = To dir
1.2 misho 255: InstallFiles()
256: {
1.3 misho 257: if [ -d "$2" ]; then
258: cd $2
259: find . -type f -name "$1" |
260: tar -cvf - -T - | tar -C $3 -xf -
261: cd -
262: fi
263: }
264:
1.9 ! misho 265: # $1 = From dir
! 266: # $2 = To dir
! 267: InstallLibs()
! 268: {
! 269: ${CEXEC} find -X $2 ! -name "*.ko" -and -type f | \
! 270: xargs readelf -d 2>&- | grep "NEEDED" | sort | uniq | \
! 271: awk '($2 == "(NEEDED)") { print substr($5, 2, length($5) - 2); }' \
! 272: 2>/dev/null >${DEST}/elwix_mklibs.tmp
! 273: for i in $(cat ${DEST}/elwix_mklibs.tmp); do
! 274: echo $i
! 275: ${CEXEC} find $1 -type f -name $i -exec install -v {} $LIBS \\\;
! 276: ${CEXEC} chflags -f noschg $LIBS/$i
! 277: ${CEXEC} strip -s $LIBS/$i
! 278: done
! 279: # ${CEXEC} find -X $2 ! -name "*.ko" -and -type f -and -perm +111 | \
! 280: # xargs ldd -f "%p\n" 2> /dev/null | sort | uniq | \
! 281: # sed 's|^/||' >${DEST}/elwix_mklibs.conf
! 282: # InstallList ${DEST}/elwix_mklibs.conf $1 $2
! 283: }
! 284:
1.3 misho 285: # $1 = Directory for clean
286: CleanCVS()
287: {
288: find $1 -type d -name CVS -exec rm -rf {} \; >/dev/null 2>&1
289: find $1 -type f -name .#\* -exec rm -f {} \; >/dev/null 2>&1
1.2 misho 290: }
1.3 misho 291:
1.4 misho 292: # $1 = file_pattern
293: # $2 = From dir
294: StripFiles()
295: {
296: if [ -d "$2" ]; then
297: local TMPFILE=$(mktemp -q /tmp/instlist.XXXXXX)
298: if [ $? -ne 0 ]; then
299: echo "Error:: Can't create temp file, exiting..."
300: exit 1
301: fi
302:
303: cd $2
304: find . -type f -name "$1" >$TMPFILE
305: for i in $(cat $TMPFILE); do
306: if [ -x $i ]; then
307: echo "Strip '$i'"
1.9 ! misho 308: ${CEXEC} chflags -f noschg $i
! 309: ${CEXEC} strip -s $i
1.4 misho 310: fi
311: done
312: cd -
313: rm -f $TMPFILE
314: fi
315: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>