--- elwix/install2img.sh 2011/09/25 21:31:46 1.1.2.3 +++ elwix/install2img.sh 2021/03/11 13:59:50 1.9 @@ -5,7 +5,7 @@ # (C) AITNET ltd - Sofia/Bulgaria # by Michael Pounov # -# $Id: install2img.sh,v 1.1.2.3 2011/09/25 21:31:46 misho Exp $ +# $Id: install2img.sh,v 1.9 2021/03/11 13:59:50 misho Exp $ # [ -r ./config/rc.elwix ] && . ./config/rc.elwix @@ -29,15 +29,15 @@ DEV="" mkdevice() { echo "+++ Make prepare file image ... " - rm -f $IMG - dd if=/dev/zero of=${IMG} bs=1024 count=${IMG_SIZE} + rm -f $1 + dd if=/dev/zero of=$1 bs=1024 count=$2 - echo -n "+++ Assign memory device to image ... " - DEV=`mdconfig -a -tvnode -f ${IMG}` + echo -n "+++ Assign memory device to image $1 ... " + DEV=`mdconfig -a -tvnode -f $1` echo $DEV if [ -z "$DEV" ]; then - rm -f $IMG + rm -f $1 exit 3 fi } @@ -52,6 +52,41 @@ initdev() exit 3 fi + if [ X"$2" != X"no" ]; then + disklabel $1 2>&- | awk -vcfgsize=${CFG_NAND_SIZE:-65536} '($1 == "a:") { + cfgsize /= 512; + bootoff = $3; + freesize = $2 - cfgsize; + imgsize = freesize / 2; + + printf(" a: %d %d unused 0 0 0\n", imgsize, cfgsize + bootoff); + printf(" f: %d %d unused 0 0 0\n", imgsize, imgsize + cfgsize + bootoff); + printf(" g: %d %d cfg 0 0 0\n", cfgsize, bootoff); + next; + } + { printf("%s\n", $0); }' >/tmp/disklabel.tmp + else + disklabel $1 2>&- | awk -vcfgsize=${CFG_NAND_SIZE:-65536} '($1 == "a:") { + cfgsize /= 512; + bootoff = $3; + freesize = $2 - cfgsize; + imgsize = freesize; + + printf(" a: %d %d unused 0 0 0\n", imgsize, cfgsize + bootoff); + printf(" g: %d %d cfg 0 0 0\n", cfgsize, bootoff); + next; + } + { printf("%s\n", $0); }' >/tmp/disklabel.tmp + fi + + if disklabel -R -m ${TARGET} $1 /tmp/disklabel.tmp; then + rm -f /tmp/disklabel.tmp + echo "OK" + else + echo "Failed!" + exit 3 + fi + if newfs -b8192 -f1024 -m0 -Lelwix ${1}a; then echo "+++ Formatting ... OK" else @@ -95,7 +130,7 @@ enablejfs() boot2dev() { echo -n "+++ Installboot to device $1 ... " - if disklabel -B -b ${WORLD}/boot/boot -m ${TARGET} ${1}; then + if disklabel -B -b ${WORLD}/boot/boot -m ${TARGET} $1; then echo "OK" else echo "Failed!" @@ -114,6 +149,38 @@ install2() fi } +mkbak2() +{ + if [ X"$2" != X"no" ]; then + echo "+++ Syncing ELWIX OS image as backup OS image into ${1}f ..." + if dd if=/dev/${1}a of=/dev/${1}f; then + tunefs -L elwix2 /dev/${1}f + echo "OK" + else + echo "Failed!" + exit 8 + fi + else + echo "+++ Make ELWIX OS system image partion for upgrade into ${REL}/sys4up_${IMGNAME}.bin ..." + if dd if=/dev/${1}a of=${REL}/sys4up_${IMGNAME}.bin; then + echo "OK" + else + echo "Failed!" + exit 9 + fi + fi + + if [ ! -f ${REL}/sys4up_${IMGNAME}.bin ]; then + echo "+++ Make ELWIX OS system image partion for upgrade into ${REL}/sys4up_${IMGNAME}.bin ..." + if dd if=/dev/${1}a of=${REL}/sys4up_${IMGNAME}.bin; then + echo "OK" + else + echo "Failed!" + exit 9 + fi + fi +} + cleandev() { mdconfig -d -u $1 @@ -122,32 +189,36 @@ cleandev() gencksum() { echo -n "+++ Generate check sums ... " - md5 ${IMG} >${MD5CHK} - sha1 ${IMG} >${SHA1CHK} + md5 $1 >$2 + sha1 $1 >$3 echo "OK" } ### main() -if [ ! -r ${1:-"${REL}/${OS}"} ]; then +if [ -z "$1" -o ! -r "$1" ]; then echo - echo "Error:: ELWIX OS file not found!" + echo "Error:: ELWIX OS tar file '$1' not found!" + echo "Syntax:: ./install2img.sh [CF size] [yes == make secondary backup image]" echo exit 2 +else + IMGNAME=$(basename $1 | sed -e "s/.tar.gz//") + MD5CHK="${REL}/${IMGNAME}${3:+"_2nd"}.md5" + SHA1CHK="${REL}/${IMGNAME}${3:+"_2nd"}.sha1" + IMG="${REL}/${IMGNAME}${3:+"_2nd"}.img" fi -mkdevice - -initdev $DEV - +mkdevice $IMG ${2:-"${IMG_SIZE}"} +initdev $DEV ${3:-"no"} mountdev $DEV -install2 ${1:-"$REL/$OS"} +install2 $1 umountdev - #enablejfs $DEV boot2dev $DEV - +mkbak2 $DEV ${3:-"no"} cleandev $DEV +gencksum $IMG $MD5CHK $SHA1CHK +gencksum ${REL}/sys4up_${IMGNAME}.bin ${REL}/sys4up_${IMGNAME}.md5 ${REL}/sys4up_${IMGNAME}.sha1 -gencksum -echo "ELWIX OS image complete." +echo "ELWIX OS image ${IMGNAME}${3:+"_2nd"} complete."