Annotation of elwix/install2img.sh, revision 1.7.6.1
1.2 misho 1: #!/bin/sh
2: #
3: # ELWIX install script for image
4: #
5: # (C) AITNET ltd - Sofia/Bulgaria <office@aitnet.org>
6: # by Michael Pounov <misho@elwix.org>
7: #
1.7.6.1 ! misho 8: # $Id: install2img.sh,v 1.7 2013/08/05 13:10:16 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 [ "${USER}" != "root" ]; then
20: echo
21: echo "ELWIX project is not configured - install must build under root !?!"
22: echo
23: exit 1
24: fi
25:
26: MNT="/mnt"
27: DEV=""
28:
29: mkdevice()
30: {
31: echo "+++ Make prepare file image ... "
1.3 misho 32: rm -f $1
33: dd if=/dev/zero of=$1 bs=1024 count=$2
1.2 misho 34:
1.3 misho 35: echo -n "+++ Assign memory device to image $1 ... "
36: DEV=`mdconfig -a -tvnode -f $1`
1.2 misho 37: echo $DEV
38:
39: if [ -z "$DEV" ]; then
1.3 misho 40: rm -f $1
1.2 misho 41: exit 3
42: fi
43: }
44:
45: initdev()
46: {
47: echo -n "+++ Init device label ... "
48: if disklabel -w $1; then
49: echo "OK"
50: else
51: echo "Failed!"
52: exit 3
53: fi
54:
1.7.6.1 ! misho 55: disklabel $1 2>&- | awk -vcfgsize=${CFG_NAND_SIZE:-65536} '($1 == "a:") {
! 56: cfgsize /= 512;
! 57: for (i = 1; i <= NF; i++) {
! 58: if (i == 2)
! 59: printf("%s ", $i - cfgsize);
! 60: else if (i == 3) {
! 61: offset = $i;
! 62: printf("%s ", cfgsize + offset);
! 63: } else
! 64: printf("%s ", $i);
! 65: }
! 66: printf("\n");
! 67: printf("g: %d %d cfg 0 0 0\n", cfgsize, offset);
! 68: next;
! 69: }
! 70: { printf("%s\n", $0); }' >/tmp/disklabel.tmp
! 71: if disklabel -R -m ${TARGET} $1 /tmp/disklabel.tmp; then
! 72: # rm -f /tmp/disklabel.tmp
! 73: echo "OK"
! 74: else
! 75: echo "Failed!"
! 76: exit 3
! 77: fi
! 78:
1.2 misho 79: if newfs -b8192 -f1024 -m0 -Lelwix ${1}a; then
80: echo "+++ Formatting ... OK"
81: else
82: echo "+++ Formatting ... Failed!"
83: exit 3
84: fi
85: }
86:
87: mountdev()
88: {
89: echo -n "+++ Mount device $1 to $MNT ... "
90: if mount /dev/${1}a $MNT; then
91: echo "OK"
92: else
93: echo "Failed!"
94: exit 4
95: fi
96: }
97:
98: umountdev()
99: {
100: echo -n "+++ Unmount $MNT ... "
101: if umount $MNT; then
102: echo "OK"
103: else
104: echo "Failed!"
105: exit 4
106: fi
107: }
108:
109: enablejfs()
110: {
111: if tunefs -n enable -j enable ${1}a; then
112: echo "Start FS Journaling ... OK"
113: else
114: echo "Start FS Journaling ... Failed!"
115: exit 6
116: fi
117: }
118:
119: boot2dev()
120: {
121: echo -n "+++ Installboot to device $1 ... "
1.3 misho 122: if disklabel -B -b ${WORLD}/boot/boot -m ${TARGET} $1; then
1.2 misho 123: echo "OK"
124: else
125: echo "Failed!"
126: exit 7
127: fi
128: }
129:
130: install2()
131: {
132: echo -n "+++ Install ELWIX OS from $1 into $MNT ... "
133: if tar -xzvpf $1 -C $MNT; then
134: echo "OK"
135: else
136: echo "Failed!"
137: exit 5
138: fi
139: }
140:
141: cleandev()
142: {
143: mdconfig -d -u $1
144: }
145:
146: gencksum()
147: {
148: echo -n "+++ Generate check sums ... "
1.3 misho 149: md5 $1 >$2
150: sha1 $1 >$3
1.2 misho 151: echo "OK"
152: }
153:
154: ### main()
155:
1.7 misho 156: if [ -z "$1" -o ! -r "$1" ]; then
1.2 misho 157: echo
1.7 misho 158: echo "Error:: ELWIX OS tar file '$1' not found!"
1.2 misho 159: echo
160: exit 2
1.7 misho 161: else
162: IMGNAME=$(basename $1 | sed -e "s/.tar.gz//")
163: MD5CHK="${REL}/${IMGNAME}.md5"
164: SHA1CHK="${REL}/${IMGNAME}.sha1"
165: IMG="${REL}/${IMGNAME}.img"
1.2 misho 166: fi
167:
1.7 misho 168: mkdevice $IMG ${2:-"${IMG_SIZE}"}
1.3 misho 169: initdev $DEV
170: mountdev $DEV
1.7 misho 171: install2 $1
1.3 misho 172: umountdev
173: #enablejfs $DEV
174: boot2dev $DEV
175: cleandev $DEV
176: gencksum $IMG $MD5CHK $SHA1CHK
177:
1.7 misho 178: echo "ELWIX OS image $IMGNAME complete."
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>