Annotation of elwix/build_fs.sh, revision 1.6
1.2 misho 1: #!/bin/sh
2: #
3: # ELWIX Build script for ELWIX CompactFlash image
4: #
5: # (C) AITNET ltd - Sofia/Bulgaria <office@aitnet.org>
6: # by Michael Pounov <misho@elwix.org>
7: #
1.5 misho 8: # $Id: build_fs.sh,v 1.4.2.2 2013/01/27 23:20:15 misho Exp $
1.2 misho 9: #
10:
11: [ -r ./config/rc.elwix ] && . ./config/rc.elwix
12: if [ X"${ELWIX_IS_CONFIGURED}" != X"YES" ]; then
13: echo
14: echo "ELWIX project is not configured !?!"
15: echo
16: exit 1
17: fi
18:
19: if [ ! -d ${BSDSRC} ]; then
20: echo
21: echo "ELWIX project is not configured - missing BSD sources !?!"
22: echo
23: exit 1
24: fi
25:
26: if [ "${USER}" != "root" ]; then
27: echo
28: echo "ELWIX project is not configured - FS must build under root !?!"
29: echo
30: exit 1
31: fi
32:
33: clean_fsdir()
34: {
35: echo "+++ Clean ELWIX FS ..."
1.5 misho 36: rm -rf ${FS} ${FS_LITE} ${FS_LITE128}
1.2 misho 37:
38: echo "+++ Clean ELWIX FS release ..."
1.5 misho 39: rm -rf ${REL}/${OS} ${REL}/${OS_LITE} ${REL}/${OS_LITE128}
1.2 misho 40: }
41:
42: build_fsdir()
43: {
44: echo "+++ Build ELWIX FS directory ..."
1.4 misho 45: mkdir -p $1
1.2 misho 46:
1.4 misho 47: cd $1
1.2 misho 48:
49: # altroot
50: install -d altroot;
51: # altroot/var
52: install -d altroot/var;
53: install -d altroot/var/account;
54: install -d altroot/var/at;
55: install -d altroot/var/at/jobs;
56: install -d altroot/var/at/spool;
1.4 misho 57: install -d -g 63 -m 0770 altroot/var/authpf;
1.2 misho 58: install -d -m 0750 altroot/var/cron;
59: install -d -m 0700 altroot/var/cron/tabs;
60: install -d altroot/var/db;
61: install -d -m 0555 altroot/var/empty;
62: install -d altroot/var/log;
1.4 misho 63: install -d -o 101 -g 101 altroot/var/log/quagga;
64: install -d -o 883 -g 883 altroot/var/mqtt;
1.2 misho 65: install -d altroot/var/named;
66: install -d altroot/var/run;
1.4 misho 67: install -d altroot/var/sys;
68: install -d -o 53 -g 53 altroot/var/run/named;
69: install -d -o 101 -g 101 altroot/var/run/quagga;
1.2 misho 70: install -d altroot/var/spool;
1.4 misho 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;
1.2 misho 75: # boot
76: install -d boot;
77: # cf
78: install -d cf;
79: # etc
80: install -d etc;
1.4 misho 81: install -d -o 883 -g 883 etc/mqtt;
1.2 misho 82: # exports
83: install -d exports;
84: # home
85: install -d home;
86: # root
87: install -d -m 0700 root;
1.4 misho 88: # pkg
89: install -d pkg;
90: install -d pkg/db;
91: install -d pkg/lib;
1.2 misho 92: # tftpboot
93: install -d tftpboot;
94:
95: chown -hR root:wheel .
96: cd -
97: }
98:
99: mkboot()
100: {
101: echo "+++ Build ELWIX FS boot directory ..."
102: InstallDir ${WORLD}/boot $1/boot
103:
104: install -m 644 ${CFGDIR}/boot/boot.config $1;
1.3 misho 105:
106: install -m 444 ${CFGDIR}/boot/beastie.4th $1/boot;
107: install -m 444 ${CFGDIR}/boot/brand.4th $1/boot;
108: install -m 444 ${CFGDIR}/boot/menu.4th $1/boot;
109:
110: install -m 444 ${KERNDEVHINTS} $1/boot/device.hints;
1.2 misho 111:
112: if [ -r ${CFGDIR}/boot/loader_${TARGET_ARCH}.conf ]; then
113: install -m 644 ${CFGDIR}/boot/loader_${TARGET_ARCH}.conf $1/boot/loader.conf;
114: else
115: echo;
116: echo "Can't find right loader.conf for TARGET_ARCH=${TARGET_ARCH} ... loader.conf not installed!";
117: echo;
118: fi;
119: }
120:
121: mkvar()
122: {
123: echo "+++ Build ELWIX FS var directory ..."
124: ln -s /tmp $1/altroot/var/tmp
125:
1.5 misho 126: touch $1/altroot/var/run/utmp
127:
128: touch $1/altroot/var/account/acct
129:
1.2 misho 130: touch $1/altroot/var/log/elwix
131: touch $1/altroot/var/log/lastlog
132: touch $1/altroot/var/log/wifi.log
1.5 misho 133: touch $1/altroot/var/log/utx.log
1.2 misho 134:
135: touch $1/altroot/var/log/auth.log
136: touch $1/altroot/var/log/cron
137: touch $1/altroot/var/log/console.log
138: touch $1/altroot/var/log/debug.log
1.5 misho 139: touch $1/altroot/var/log/init.log
1.2 misho 140: touch $1/altroot/var/log/lpd-errs
141: touch $1/altroot/var/log/maillog
142: touch $1/altroot/var/log/messages
143: touch $1/altroot/var/log/security
144: touch $1/altroot/var/log/xferlog
145: touch $1/altroot/var/log/ppp.log
146: chgrp network $1/altroot/var/log/ppp.log
147:
148: InstallDir ${WORLD}/var/named $1/altroot/var/named
149: InstallList ${ELWIX_BSDSRC} ${BSDSRC} $1/altroot/var/named
150: install -v ${FS_ETC}/resolv.safe $1/altroot/var/run/resolv.conf
151: }
152:
153: create_etc_motd()
154: {
1.4 misho 155: ELWIX_VER="ELWIX$2-${VERSION}_${TARGET_ARCH}";
1.2 misho 156: ELWIX_HDR_MOTD="${ELWIX_VER} :: Build date ${BUILD_DATE}";
157:
158: awk -v fo="${1:-motd}" 'BEGIN { print "'"${ELWIX_HDR_MOTD}"'" > fo; } { print $0 >> fo; }' \
159: ${CFGDIR}/elwix_signature.txt;
160: }
161:
162: create_etc_fstab()
163: {
164: cat >$1 <<_EOF
1.4 misho 165: # Automatic generated fstab for ELWIX$2 at ${BUILD_DATE}
1.2 misho 166: #
167: /dev/ufs/elwix /elwix ufs ro 0 1
168: md3 /tmp mfs rw,-s8m,-oasync,-S 0 0
169: md4 /var mfs rw,-s16m,-S 0 0
170: _EOF
171: }
172:
173: mketc()
174: {
175: echo "+++ Build ELWIX FS etc directory ..."
176: InstallDir ${FS_ETC} $1/etc
177:
178: chown -R root:wheel $1/etc;
179:
180: chmod 0600 $1/etc/opieaccess;
181: chmod 0600 $1/etc/opiekeys;
182:
183: chmod 0600 $1/etc/master.passwd;
184: chmod 0600 $1/etc/spwd.db;
185: chmod 0600 $1/etc/ssh/ssh_host_dsa_key;
186: chmod 0600 $1/etc/ssh/ssh_host_key;
187: chmod 0600 $1/etc/ssh/ssh_host_rsa_key;
1.3 misho 188: chmod 0600 $1/etc/ssh/ssh_host_ecdsa_key;
1.2 misho 189:
190: chmod 0440 $1/etc/sudoers;
191:
1.4 misho 192: chgrp 80 $1/etc/config.xml;
1.2 misho 193: chmod 0660 $1/etc/config.xml;
194:
1.4 misho 195: chgrp -R 883 $1/etc/mqtt;
196: chown -R 883 $1/etc/mqtt;
197:
1.2 misho 198: ln -sf /etc/rc.s $1/etc/rc.S
199:
200: ln -sf /usr/share/zoneinfo/${TIMEZONE} $1/etc/localtime;
201: ln -sf /usr/share/misc/termcap $1/etc/termcap;
202:
203: ln -sf /var/named/etc/namedb $1/etc/namedb;
204: ln -sf /var/run/resolv.conf $1/etc/resolv.conf;
205:
1.4 misho 206: ln -sf /elwix/pkg/etc/mk.conf $1/etc/mk.conf;
207:
1.2 misho 208: echo ${TARGET_ARCH} >$1/etc/platform;
209:
1.4 misho 210: create_etc_motd $1/etc/motd $2;
211: create_etc_fstab $1/etc/fstab $2;
212:
213: echo "+++ ELWIX clean CVS tags ..."
214: CleanCVS $1
215: CleanCVS $1/etc
1.2 misho 216: }
217:
218: mkbackup()
219: {
220: echo "+++ Build ELWIX FS backup factory default directory ..."
221: mkdir -p $1/altroot/backup
222:
223: cd $1
1.4 misho 224: cp -p etc/config.xml altroot/backup
1.2 misho 225: tar -czf altroot/backup/.etc.tgz etc
1.4 misho 226:
1.2 misho 227: cd altroot
228: tar -czf backup/.var.tgz var
229: }
230:
231: mkhome()
232: {
233: echo "+++ Build ELWIX FS root home directory ..."
234: install -d $1/root/.ssh
235: [ -r ${CFGDIR}/root.skel/ssh/authorized_keys2 ] && \
236: install -v ${CFGDIR}/root.skel/ssh/authorized_keys2 $1/root/.ssh;
237:
238: install -v ${CFGDIR}/root.skel/cshrc $1/root/.cshrc;
239: install -v ${CFGDIR}/root.skel/login $1/root/.login;
240: install -v ${CFGDIR}/root.skel/logout $1/root/.logout;
241: install -v ${CFGDIR}/root.skel/profile $1/root/.profile;
242: install -v ${CFGDIR}/root.skel/vimrc $1/root/.vimrc;
243: }
244:
245: install_fsdir()
246: {
1.4 misho 247: echo "+++ Install ELWIX FS $1 in bundle OS install file ..."
248: OSZ=""
249:
250: install -v ${REL}/${ROOTFS_KERN} $1/boot/kernel
1.2 misho 251:
1.5 misho 252: case "$2" in
253: _[Ll][Ii][Tt][Ee]_128)
254: install -d $1/usr
255: cd $1/usr
256: pax -r -z -pe -f ${REL}/${ROMFS_IMG}
257: cd -
258:
259: install -d $1/usr/local
260: cd $1/usr/local
261: pax -r -z -pe -f ${REL}/${ROMFS_IMG2}
262: cd -
263:
264: OSZ=${REL}/${OS_LITE128}
265: ;;
266: _[Ll][Ii][Tt][Ee])
267: install -d $1/usr
268: cd $1/usr
269: pax -r -z -pe -f ${REL}/${ROMFS_IMG}
270: cd -
271:
272: OSZ=${REL}/${OS_LITE}
273: ;;
274: *)
275: install -v ${REL}/${ROMFS_IMG} \
276: $1/altroot/elwix-firmware-${VERSION}_${TARGET_ARCH}
277: ln $1/altroot/elwix-firmware-${VERSION}_${TARGET_ARCH} \
278: $1/altroot/${ROMFS_IMG}
279: ln -s /elwix/altroot/elwix-firmware-${VERSION}_${TARGET_ARCH} \
280: $1/${ROMFS_IMG}
281:
282: install -v ${REL}/${ROMFS_IMG2} \
283: $1/altroot/elwix-firmware2-${VERSION}_${TARGET_ARCH}
284: ln $1/altroot/elwix-firmware2-${VERSION}_${TARGET_ARCH} \
285: $1/altroot/${ROMFS_IMG2}
286: ln -s /elwix/altroot/elwix-firmware2-${VERSION}_${TARGET_ARCH} \
287: $1/${ROMFS_IMG2}
288:
289: OSZ=${REL}/${OS}
290: ;;
291: esac
1.2 misho 292:
1.4 misho 293: cd $1
294: tar -czvf $OSZ .
1.2 misho 295: }
296:
297: ### main()
298: if [ ! -r ${REL}/${ROOTFS_KERN} -o ! -r ${REL}/${ROMFS_IMG} ]; then
299: echo
300: echo "Error:: not found kernel or firmware elwix files ..."
301: echo
302: echo " For fix this issue, please re-run build_rootfs.sh or build_romfs.sh"
303: echo
304: exit 1
305: fi
306:
307: clean_fsdir
1.4 misho 308:
309: build_fsdir ${FS}
310: build_fsdir ${FS_LITE}
1.5 misho 311: build_fsdir ${FS_LITE128}
1.2 misho 312:
313: mkboot ${FS}
1.4 misho 314: mkboot ${FS_LITE}
1.5 misho 315: mkboot ${FS_LITE128}
1.4 misho 316:
1.2 misho 317: mkhome ${FS}
1.4 misho 318: mkhome ${FS_LITE}
1.5 misho 319: mkhome ${FS_LITE128}
1.4 misho 320:
1.2 misho 321: mkvar ${FS}
1.4 misho 322: mkvar ${FS_LITE}
1.5 misho 323: mkvar ${FS_LITE128}
1.4 misho 324:
1.2 misho 325: mketc ${FS}
1.4 misho 326: mketc ${FS_LITE} "_lite"
1.5 misho 327: mketc ${FS_LITE128} "_lite_128"
1.4 misho 328:
1.2 misho 329: mkbackup ${FS}
1.4 misho 330: mkbackup ${FS_LITE}
1.5 misho 331: mkbackup ${FS_LITE128}
1.2 misho 332:
1.4 misho 333: install_fsdir ${FS}
334: install_fsdir ${FS_LITE} "_lite"
1.5 misho 335: install_fsdir ${FS_LITE128} "_lite_128"
1.2 misho 336:
337: echo "+++ Complete build ELWIX FS"
338: echo "ELWIX finish version ${VERSION}, Good luck!"
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>