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: #
8: # $Id: build_fs.sh,v 1.10.2.3 2016/12/20 14:40:20 misho Exp $
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"
36: chflags -Rf nosunlink $1
37: rm -rf $1 $2
38: }
39:
40: build_fsdir()
41: {
42: echo "+++ Build ELWIX FS directory ... $1"
43: mkdir -p $1
44:
45: cd $1
46:
47: # altroot
48: install -d altroot;
49: # altroot/var
50: install -d altroot/var;
51: install -d altroot/var/account;
52: install -d altroot/var/at;
53: install -d altroot/var/at/jobs;
54: install -d altroot/var/at/spool;
55: install -d -g 63 -m 0770 altroot/var/authpf;
56: install -d -m 0750 altroot/var/cron;
57: install -d -m 0700 altroot/var/cron/tabs;
58: install -d altroot/var/db;
59: install -d -m 0555 altroot/var/empty;
60: install -d altroot/var/log;
61: install -d -o 101 -g 101 altroot/var/log/quagga;
62: install -d -o 883 -g 883 altroot/var/mqtt;
63: install -d altroot/var/named;
64: install -d altroot/var/run;
65: install -d altroot/var/sys;
66: install -d -o 53 -g 53 altroot/var/run/named;
67: install -d -o 101 -g 101 altroot/var/run/quagga;
68: install -d altroot/var/spool;
69: install -d -o 66 -g 68 -m 0775 altroot/var/spool/lock;
70: install -d -g 1 altroot/var/spool/lpd;
71: install -d -g 1 altroot/var/spool/output;
72: install -d -g 1 altroot/var/spool/output/lpd;
73: # boot
74: install -d boot;
75: # cf
76: install -d cf;
77: case ${TARGET} in
78: i386)
79: ln -fs /dev/ada0g cf/map.cfg
80: ;;
81: mips)
82: ln -fs /dev/map/cfg cf/map.cfg
83: ;;
84: esac
85: # etc
86: install -d etc;
87: install -d -o 883 -g 883 etc/mqtt;
88: # exports
89: install -d exports;
90: # home
91: install -d home;
92: # root
93: install -d -m 0750 root;
94: # pkg
95: install -d pkg;
96: install -d pkg/db;
97: install -d pkg/lib;
98: # tftpboot
99: install -d tftpboot;
100:
101: chown -hR root:wheel .
102: cd -
103: }
104:
105: create_etc_fstab()
106: {
107: cat >$1/etc/fstab <<_EOF
108: # Automatic generated fstab for ELWIX $2 at ${BUILD_DATE}
109: #
110: /dev/ufs/elwix /elwix ufs ro 0 1
111: md3 /tmp mfs rw,-s8m,-oasync,-S,-n 0 0
112: md4 /var mfs rw,-s16m,-S,-n 0 0
113: _EOF
114: }
115:
116: update_etc_cfexec()
117: {
118: echo "mount = \"/elwix\"" >> $1/etc/cfexec.conf
119: }
120:
121: install_fsdir()
122: {
123: echo "+++ Install ELWIX RootFS $1 in bundle OS install file ..."
124: OSZ=""
125:
126: install -v ${REL}/${ROOTFS_KERN} $1/boot/kernel/kernel.gz
127:
128: case "$2" in
129: [Ee][Xx][Tt])
130: install -d $1/usr
131: cd $1/usr
132: pax -r -z -pe -f ${REL}/${ROMFS_IMG}
133: cd -
134:
135: install -d $1/usr/local
136: cd $1/usr/local
137: pax -r -z -pe -f ${REL}/${ROMFS_IMG2}
138: cd -
139:
140: OSZ=${REL}/${OS_EXT}
141: ;;
142: *)
143: install -v ${REL}/${ROMFS_IMG} \
144: $1/altroot/elwix-firmware-${VERSION}_${TARGET_ARCH}
145: ln $1/altroot/elwix-firmware-${VERSION}_${TARGET_ARCH} \
146: $1/altroot/${ROMFS_IMG}
147: ln -s /elwix/altroot/elwix-firmware-${VERSION}_${TARGET_ARCH} \
148: $1/${ROMFS_IMG}
149:
150: install -v ${REL}/${ROMFS_IMG2} \
151: $1/altroot/elwix-firmware2-${VERSION}_${TARGET_ARCH}
152: ln $1/altroot/elwix-firmware2-${VERSION}_${TARGET_ARCH} \
153: $1/altroot/${ROMFS_IMG2}
154: ln -s /elwix/altroot/elwix-firmware2-${VERSION}_${TARGET_ARCH} \
155: $1/${ROMFS_IMG2}
156:
157: OSZ=${REL}/${OS}
158: ;;
159: esac
160:
161: cd $1
162: tar -czvf $OSZ .
163:
164: echo "+++ Completed ELWIX RootFS $1 --> $OSZ"
165: }
166:
167: ### main()
168: if [ ! -r ${REL}/${ROOTFS_KERN} -o ! -r ${REL}/${ROMFS_IMG} ]; then
169: echo
170: echo "Error:: not found kernel or firmware elwix files ..."
171: echo
172: echo " For fix this issue, please re-run build_rootfs.sh or build_romfs.sh"
173: echo
174: exit 1
175: fi
176:
177: clean_fsdir ${FS} ${REL}/${OS} || exit 1
178: clean_fsdir ${FS_EXT} ${REL}/${OS_EXT} || exit 1
179:
180: build_fsdir ${FS} || exit 1
181: build_fsdir ${FS_EXT} || exit 1
182:
183: MakeFS_home ${FS} || exit 1
184: MakeFS_home ${FS_EXT} || exit 1
185:
186: MakeFS_var ${FS} ${FS_ETC} || exit 1
187: MakeFS_var ${FS_EXT} ${FS_EXT_ETC} || exit 1
188:
189: MakeFS_etc ${FS} ${FS_ETC} || exit 1
190: MakeFS_etc ${FS_EXT} ${FS_EXT_ETC} ext || exit 1
191:
192: create_etc_fstab ${FS} || exit 1
193: create_etc_fstab ${FS_EXT} ext || exit 1
194:
195: update_etc_cfexec ${FS} || exit 1
196: update_etc_cfexec ${FS_EXT} ext || exit 1
197:
198: MakeFS_backup ${FS} || exit 1
199: MakeFS_backup ${FS_EXT} || exit 1
200:
201: MakeFS_boot ${FS} || exit 1
202: MakeFS_boot ${FS_EXT} || exit 1
203:
204: install_fsdir ${FS} || exit 1
205: install_fsdir ${FS_EXT} ext || exit 1
206:
207: echo "+++ Complete build ELWIX RootFS system"
208: echo "ELWIX RootFS finish version ${VERSION}, Good luck!"
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>