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