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