Annotation of elwix/config/rc.subr, revision 1.10
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.10 ! misho 7: # $Id: rc.subr,v 1.9.2.4 2017/02/13 16:45:11 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: *)
1.10 ! misho 123: # chmod 0600 $1/etc/opieaccess;
! 124: # chmod 0600 $1/etc/opiekeys;
1.9 misho 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;
1.10 ! misho 134: chmod 0600 $1/etc/ssh/ssh_host_ed25519_key;
1.7 misho 135:
136: chmod 0440 $1/etc/sudoers;
137:
1.9 misho 138: # chgrp 80 $1/etc/config.xml;
139: # chmod 0660 $1/etc/config.xml;
1.7 misho 140:
141: mkdir -p $1/etc/mqtt;
142: chgrp -R 883 $1/etc/mqtt;
143: chown -R 883 $1/etc/mqtt;
144:
145: ln -sf /etc/rc.s $1/etc/rc.S
146:
147: ln -sf /usr/share/zoneinfo/${TIMEZONE} $1/etc/localtime;
148: ln -sf /usr/share/misc/termcap $1/etc/termcap;
149:
150: ln -sf /var/run/resolv.conf $1/etc/resolv.conf;
151:
1.9 misho 152: # ln -sf /elwix/pkg/etc/mk.conf $1/etc/mk.conf;
1.7 misho 153:
154: echo ${TARGET_ARCH} >$1/etc/platform;
155:
156: Create_etc_motd $1/etc/motd $3;
157:
158: CleanCVS $1
159: CleanCVS $1/etc
160: }
161:
162: # $1 = fs/elwix
163: MakeFS_home()
164: {
165: install -d $1/root/.ssh
166: [ -r ${CFGDIR}/root.skel/ssh/authorized_keys2 ] && \
167: install -v ${CFGDIR}/root.skel/ssh/authorized_keys2 $1/root/.ssh;
168:
169: install -v ${CFGDIR}/root.skel/cshrc $1/root/.cshrc;
170: install -v ${CFGDIR}/root.skel/login $1/root/.login;
171: install -v ${CFGDIR}/root.skel/logout $1/root/.logout;
172: install -v ${CFGDIR}/root.skel/profile $1/root/.profile;
173: install -v ${CFGDIR}/root.skel/vimrc $1/root/.vimrc;
174: }
175:
176: # $1 = fs/elwix
177: MakeFS_backup()
178: {
179: mkdir -p $1/altroot/backup
180:
181: cd $1
1.9 misho 182: # cp -p etc/config.xml altroot/backup
1.7 misho 183: tar -czf altroot/backup/.etc.tgz etc
184:
185: cd altroot
186: tar -czf backup/.var.tgz var
187: }
188:
189: # $1 = fs
190: MakeFS_boot()
191: {
192: InstallDir ${WORLD}/boot $1/boot
193:
194: install -m 644 ${CFGDIR}/boot/boot.config $1;
195:
1.9 misho 196: case ${TARGET} in
1.10 ! misho 197: i386|amd64)
! 198: install -m 444 ${CFGDIR}/boot/logo-elwix.4th $1/boot;
! 199: install -m 444 ${CFGDIR}/boot/brand-elwix.4th $1/boot;
1.9 misho 200: install -m 444 ${CFGDIR}/boot/menu.4th $1/boot;
201: ;;
202: *)
203: ;;
204: esac
1.7 misho 205:
206: install -m 444 ${KERNDEVHINTS} $1/boot/device.hints;
207:
208: if [ -r ${CFGDIR}/boot/loader_${TARGET_ARCH}.conf ]; then
209: install -m 644 ${CFGDIR}/boot/loader_${TARGET_ARCH}.conf $1/boot/loader.conf;
210: fi;
211: }
212:
1.1 misho 213: # $1 = ELWIX install list config
214: # $2 = From World dir
215: # $3 = To Dest dir
216: InstallList()
217: {
1.4 misho 218: local TMPFILE=$(mktemp -q /tmp/instlist.XXXXXX)
219: if [ $? -ne 0 ]; then
220: echo "Error:: Can't create temp file, exiting..."
221: exit 1
222: fi
223:
224: sed -nE -e 's/^ *([^ #]+) */\1/p' < $1 | tr ':' '\n' >$TMPFILE
225: cd $2
226: for i in $(cat $TMPFILE); do
227: if [ -x $i ]; then
228: echo "Strip '$i'"
1.9 misho 229: ${CEXEC} chflags -f noschg $i
230: ${CEXEC} strip -s $i
1.4 misho 231: fi
232: done
233: cd -
234: tar -C $2 -cvf - -T $TMPFILE | tar -C $3 -x -f -
235: rm -f $TMPFILE
1.1 misho 236: }
237:
238: # $1 = From dir
239: # $2 = To dir
1.2 misho 240: InstallDir()
1.1 misho 241: {
242: cd $1
243: pax -rw -pe -X . $2
244: cd -
245: }
246:
247: # $* = Program arguments for install tool
248: InstallProg()
249: {
250: install -c $*
251: }
1.2 misho 252:
253: # $1 = file_pattern
1.3 misho 254: # $2 = From dir
255: # $3 = To dir
1.2 misho 256: InstallFiles()
257: {
1.3 misho 258: if [ -d "$2" ]; then
259: cd $2
260: find . -type f -name "$1" |
261: tar -cvf - -T - | tar -C $3 -xf -
262: cd -
263: fi
264: }
265:
1.9 misho 266: # $1 = From dir
267: # $2 = To dir
268: InstallLibs()
269: {
270: ${CEXEC} find -X $2 ! -name "*.ko" -and -type f | \
271: xargs readelf -d 2>&- | grep "NEEDED" | sort | uniq | \
272: awk '($2 == "(NEEDED)") { print substr($5, 2, length($5) - 2); }' \
273: 2>/dev/null >${DEST}/elwix_mklibs.tmp
274: for i in $(cat ${DEST}/elwix_mklibs.tmp); do
275: echo $i
276: ${CEXEC} find $1 -type f -name $i -exec install -v {} $LIBS \\\;
277: ${CEXEC} chflags -f noschg $LIBS/$i
278: ${CEXEC} strip -s $LIBS/$i
279: done
280: # ${CEXEC} find -X $2 ! -name "*.ko" -and -type f -and -perm +111 | \
281: # xargs ldd -f "%p\n" 2> /dev/null | sort | uniq | \
282: # sed 's|^/||' >${DEST}/elwix_mklibs.conf
283: # InstallList ${DEST}/elwix_mklibs.conf $1 $2
284: }
285:
1.3 misho 286: # $1 = Directory for clean
287: CleanCVS()
288: {
289: find $1 -type d -name CVS -exec rm -rf {} \; >/dev/null 2>&1
290: find $1 -type f -name .#\* -exec rm -f {} \; >/dev/null 2>&1
1.2 misho 291: }
1.3 misho 292:
1.4 misho 293: # $1 = file_pattern
294: # $2 = From dir
295: StripFiles()
296: {
297: if [ -d "$2" ]; then
298: local TMPFILE=$(mktemp -q /tmp/instlist.XXXXXX)
299: if [ $? -ne 0 ]; then
300: echo "Error:: Can't create temp file, exiting..."
301: exit 1
302: fi
303:
304: cd $2
305: find . -type f -name "$1" >$TMPFILE
306: for i in $(cat $TMPFILE); do
307: if [ -x $i ]; then
308: echo "Strip '$i'"
1.9 misho 309: ${CEXEC} chflags -f noschg $i
310: ${CEXEC} strip -s $i
1.4 misho 311: fi
312: done
313: cd -
314: rm -f $TMPFILE
315: fi
316: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>