Annotation of elwix/config/rc.subr, revision 1.7.4.1
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.7.4.1 ! misho 7: # $Id: rc.subr,v 1.7 2013/08/05 13:10:16 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;
65: install -d -o 101 -g 101 altroot/var/log/quagga;
66: install -d -o 883 -g 883 altroot/var/mqtt;
67: install -d altroot/var/run;
68: install -d altroot/var/frm;
69: install -d -o 101 -g 101 altroot/var/run/quagga;
70: install -d altroot/var/spool;
71: install -d -o 66 -g 68 -m 0775 altroot/var/spool/lock;
72: install -d -g 1 altroot/var/spool/lpd;
73: install -d -g 1 altroot/var/spool/output;
74: install -d -g 1 altroot/var/spool/output/lpd;
75:
76: ln -fs /tmp altroot/var/tmp;
77:
78: touch altroot/var/run/utmp
79:
80: touch altroot/var/account/acct
81:
82: touch altroot/var/log/elwix
83: touch altroot/var/log/lastlog
84: touch altroot/var/log/wifi.log
85: touch altroot/var/log/utx.log
86:
87: touch altroot/var/log/auth.log
88: touch altroot/var/log/cron
89: touch altroot/var/log/console.log
90: touch altroot/var/log/debug.log
91: touch altroot/var/log/init.log
92: touch altroot/var/log/lpd-errs
93: touch altroot/var/log/maillog
94: touch altroot/var/log/messages
95: touch altroot/var/log/security
96: touch altroot/var/log/xferlog
97: touch altroot/var/log/ppp.log
98: chgrp 69 altroot/var/log/ppp.log
99:
100: install -v $2/resolv.safe altroot/var/run/resolv.conf
101:
102: chown -hR root:wheel .
103: cd -
104: }
105:
106: # $1 = fs/elwix
107: # $2 = config/etc/default
108: # $3 = name
109: MakeFS_etc()
110: {
111: InstallDir $2 $1/etc
112:
113: chown -R root:wheel $1/etc;
114:
115: chmod 0600 $1/etc/opieaccess;
116: chmod 0600 $1/etc/opiekeys;
117:
118: chmod 0600 $1/etc/master.passwd;
119: chmod 0600 $1/etc/spwd.db;
120: chmod 0600 $1/etc/ssh/ssh_host_dsa_key;
121: chmod 0600 $1/etc/ssh/ssh_host_key;
122: chmod 0600 $1/etc/ssh/ssh_host_rsa_key;
123: chmod 0600 $1/etc/ssh/ssh_host_ecdsa_key;
124:
125: chmod 0440 $1/etc/sudoers;
126:
127: chgrp 80 $1/etc/config.xml;
128: chmod 0660 $1/etc/config.xml;
129:
130: mkdir -p $1/etc/mqtt;
131: chgrp -R 883 $1/etc/mqtt;
132: chown -R 883 $1/etc/mqtt;
133:
134: ln -sf /etc/rc.s $1/etc/rc.S
135:
136: ln -sf /usr/share/zoneinfo/${TIMEZONE} $1/etc/localtime;
137: ln -sf /usr/share/misc/termcap $1/etc/termcap;
138:
139: ln -sf /var/run/resolv.conf $1/etc/resolv.conf;
140:
141: ln -sf /elwix/pkg/etc/mk.conf $1/etc/mk.conf;
142:
143: echo ${TARGET_ARCH} >$1/etc/platform;
144:
145: Create_etc_motd $1/etc/motd $3;
146:
147: CleanCVS $1
148: CleanCVS $1/etc
149: }
150:
151: # $1 = fs/elwix
152: MakeFS_home()
153: {
154: install -d $1/root/.ssh
155: [ -r ${CFGDIR}/root.skel/ssh/authorized_keys2 ] && \
156: install -v ${CFGDIR}/root.skel/ssh/authorized_keys2 $1/root/.ssh;
157:
158: install -v ${CFGDIR}/root.skel/cshrc $1/root/.cshrc;
159: install -v ${CFGDIR}/root.skel/login $1/root/.login;
160: install -v ${CFGDIR}/root.skel/logout $1/root/.logout;
161: install -v ${CFGDIR}/root.skel/profile $1/root/.profile;
162: install -v ${CFGDIR}/root.skel/vimrc $1/root/.vimrc;
163: }
164:
165: # $1 = fs/elwix
166: MakeFS_backup()
167: {
168: mkdir -p $1/altroot/backup
169:
170: cd $1
171: cp -p etc/config.xml altroot/backup
172: tar -czf altroot/backup/.etc.tgz etc
173:
174: cd altroot
175: tar -czf backup/.var.tgz var
176: }
177:
178: # $1 = fs
179: MakeFS_boot()
180: {
181: InstallDir ${WORLD}/boot $1/boot
182:
183: install -m 644 ${CFGDIR}/boot/boot.config $1;
184:
185: install -m 444 ${CFGDIR}/boot/beastie.4th $1/boot;
186: install -m 444 ${CFGDIR}/boot/brand.4th $1/boot;
187: install -m 444 ${CFGDIR}/boot/menu.4th $1/boot;
188:
189: install -m 444 ${KERNDEVHINTS} $1/boot/device.hints;
190:
191: if [ -r ${CFGDIR}/boot/loader_${TARGET_ARCH}.conf ]; then
192: install -m 644 ${CFGDIR}/boot/loader_${TARGET_ARCH}.conf $1/boot/loader.conf;
193: else
194: echo;
195: echo "Can't find right loader.conf for TARGET_ARCH=${TARGET_ARCH} ... loader.conf not installed!";
196: echo;
197: fi;
198: }
199:
1.1 misho 200: # $1 = ELWIX install list config
201: # $2 = From World dir
202: # $3 = To Dest dir
203: InstallList()
204: {
1.4 misho 205: local TMPFILE=$(mktemp -q /tmp/instlist.XXXXXX)
206: if [ $? -ne 0 ]; then
207: echo "Error:: Can't create temp file, exiting..."
208: exit 1
209: fi
210:
211: sed -nE -e 's/^ *([^ #]+) */\1/p' < $1 | tr ':' '\n' >$TMPFILE
212: cd $2
213: for i in $(cat $TMPFILE); do
214: if [ -x $i ]; then
215: echo "Strip '$i'"
216: strip -s $i
217: fi
218: done
219: cd -
220: tar -C $2 -cvf - -T $TMPFILE | tar -C $3 -x -f -
221: rm -f $TMPFILE
1.1 misho 222: }
223:
224: # $1 = From dir
225: # $2 = To dir
1.2 misho 226: InstallDir()
1.1 misho 227: {
228: cd $1
229: pax -rw -pe -X . $2
230: cd -
231: }
232:
233: # $* = Program arguments for install tool
234: InstallProg()
235: {
236: install -c $*
237: }
1.2 misho 238:
239: # $1 = file_pattern
1.3 misho 240: # $2 = From dir
241: # $3 = To dir
1.2 misho 242: InstallFiles()
243: {
1.3 misho 244: if [ -d "$2" ]; then
245: cd $2
246: find . -type f -name "$1" |
247: tar -cvf - -T - | tar -C $3 -xf -
248: cd -
249: fi
250: }
251:
252: # $1 = Directory for clean
253: CleanCVS()
254: {
255: find $1 -type d -name CVS -exec rm -rf {} \; >/dev/null 2>&1
256: find $1 -type f -name .#\* -exec rm -f {} \; >/dev/null 2>&1
1.2 misho 257: }
1.3 misho 258:
1.4 misho 259: # $1 = file_pattern
260: # $2 = From dir
261: StripFiles()
262: {
263: if [ -d "$2" ]; then
264: local TMPFILE=$(mktemp -q /tmp/instlist.XXXXXX)
265: if [ $? -ne 0 ]; then
266: echo "Error:: Can't create temp file, exiting..."
267: exit 1
268: fi
269:
270: cd $2
271: find . -type f -name "$1" >$TMPFILE
272: for i in $(cat $TMPFILE); do
273: if [ -x $i ]; then
274: echo "Strip '$i'"
275: strip -s $i
276: fi
277: done
278: cd -
279: rm -f $TMPFILE
280: fi
281: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>