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