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