Annotation of elwix/config/rc.subr, revision 1.10.2.6
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.6! misho 7: # $Id: rc.subr,v 1.10.2.5 2017/06/19 20:26: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;
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:
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
187: MakeFS_boot()
188: {
189: InstallDir ${WORLD}/boot $1/boot
190:
191: install -m 644 ${CFGDIR}/boot/boot.config $1;
192:
1.9 misho 193: case ${TARGET} in
1.10 misho 194: i386|amd64)
195: install -m 444 ${CFGDIR}/boot/logo-elwix.4th $1/boot;
196: install -m 444 ${CFGDIR}/boot/brand-elwix.4th $1/boot;
1.9 misho 197: install -m 444 ${CFGDIR}/boot/menu.4th $1/boot;
198: ;;
199: *)
200: ;;
201: esac
1.7 misho 202:
203: install -m 444 ${KERNDEVHINTS} $1/boot/device.hints;
204:
205: if [ -r ${CFGDIR}/boot/loader_${TARGET_ARCH}.conf ]; then
206: install -m 644 ${CFGDIR}/boot/loader_${TARGET_ARCH}.conf $1/boot/loader.conf;
207: fi;
208: }
209:
1.1 misho 210: # $1 = ELWIX install list config
211: # $2 = From World dir
212: # $3 = To Dest dir
213: InstallList()
214: {
1.4 misho 215: local TMPFILE=$(mktemp -q /tmp/instlist.XXXXXX)
216: if [ $? -ne 0 ]; then
217: echo "Error:: Can't create temp file, exiting..."
218: exit 1
219: fi
220:
221: sed -nE -e 's/^ *([^ #]+) */\1/p' < $1 | tr ':' '\n' >$TMPFILE
222: cd $2
223: for i in $(cat $TMPFILE); do
224: if [ -x $i ]; then
225: echo "Strip '$i'"
1.9 misho 226: ${CEXEC} chflags -f noschg $i
227: ${CEXEC} strip -s $i
1.4 misho 228: fi
229: done
230: cd -
231: tar -C $2 -cvf - -T $TMPFILE | tar -C $3 -x -f -
232: rm -f $TMPFILE
1.1 misho 233: }
234:
235: # $1 = From dir
236: # $2 = To dir
1.2 misho 237: InstallDir()
1.1 misho 238: {
239: cd $1
240: pax -rw -pe -X . $2
241: cd -
242: }
243:
244: # $* = Program arguments for install tool
245: InstallProg()
246: {
247: install -c $*
248: }
1.2 misho 249:
250: # $1 = file_pattern
1.3 misho 251: # $2 = From dir
252: # $3 = To dir
1.2 misho 253: InstallFiles()
254: {
1.3 misho 255: if [ -d "$2" ]; then
256: cd $2
257: find . -type f -name "$1" |
258: tar -cvf - -T - | tar -C $3 -xf -
259: cd -
260: fi
261: }
262:
1.9 misho 263: # $1 = From dir
264: # $2 = To dir
265: InstallLibs()
266: {
267: ${CEXEC} find -X $2 ! -name "*.ko" -and -type f | \
268: xargs readelf -d 2>&- | grep "NEEDED" | sort | uniq | \
269: awk '($2 == "(NEEDED)") { print substr($5, 2, length($5) - 2); }' \
270: 2>/dev/null >${DEST}/elwix_mklibs.tmp
271: for i in $(cat ${DEST}/elwix_mklibs.tmp); do
272: echo $i
273: ${CEXEC} find $1 -type f -name $i -exec install -v {} $LIBS \\\;
274: ${CEXEC} chflags -f noschg $LIBS/$i
275: ${CEXEC} strip -s $LIBS/$i
276: done
277: # ${CEXEC} find -X $2 ! -name "*.ko" -and -type f -and -perm +111 | \
278: # xargs ldd -f "%p\n" 2> /dev/null | sort | uniq | \
279: # sed 's|^/||' >${DEST}/elwix_mklibs.conf
280: # InstallList ${DEST}/elwix_mklibs.conf $1 $2
281: }
282:
1.3 misho 283: # $1 = Directory for clean
284: CleanCVS()
285: {
286: find $1 -type d -name CVS -exec rm -rf {} \; >/dev/null 2>&1
287: find $1 -type f -name .#\* -exec rm -f {} \; >/dev/null 2>&1
1.2 misho 288: }
1.3 misho 289:
1.4 misho 290: # $1 = file_pattern
291: # $2 = From dir
292: StripFiles()
293: {
294: if [ -d "$2" ]; then
295: local TMPFILE=$(mktemp -q /tmp/instlist.XXXXXX)
296: if [ $? -ne 0 ]; then
297: echo "Error:: Can't create temp file, exiting..."
298: exit 1
299: fi
300:
301: cd $2
302: find . -type f -name "$1" >$TMPFILE
303: for i in $(cat $TMPFILE); do
304: if [ -x $i ]; then
305: echo "Strip '$i'"
1.9 misho 306: ${CEXEC} chflags -f noschg $i
307: ${CEXEC} strip -s $i
1.4 misho 308: fi
309: done
310: cd -
311: rm -f $TMPFILE
312: fi
313: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>