Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 112 lines (97 sloc) 2.885 kB
47833c7 Initial checkin of SD Factory
mgrundy authored
1 #!/bin/bash
2
3 #set -x
4
39343de Potential problems fixed and usability enhancements
mgrundy authored
5
6 if [ "$1" == "--help" ] || [[ $# -lt 3 ]]; then
7 echo "$0 devname rootfs.tar volume-label"
8 echo "But that is just the beginning, you also need"
9 echo "a rootfs.tar.list.md5 which is a md5sum of every file in"
10 echo "the tarball, so we can verify the filesystem is created correctly"
11 exit 1
12 elif [[ $EUID -ne 0 ]]; then
13 echo "You need superuser privs to do anything constructive, sudo please"
14 exit 1
15 fi
16
17 if [ ! -b $1 ]; then
18 echo "The first argument has to be the block device we're writing to"
19 exit
20 fi
21
22 if [ ! -e $2 ]; then
23 echo "The second argument is the uncompressed tarball you want to load on the sd card"
24 exit
25 fi
26
27
47833c7 Initial checkin of SD Factory
mgrundy authored
28 DEVNAME=$1
29 DEVSNAME=${1/\/dev\//}
30 sleep 5
39343de Potential problems fixed and usability enhancements
mgrundy authored
31 /bin/umount ${DEVNAME}* > /dev/null 2>&1
47833c7 Initial checkin of SD Factory
mgrundy authored
32 dd if=/dev/zero of=$DEVNAME bs=1024 count=1024
33 if [ $? != "0" ];then
39343de Potential problems fixed and usability enhancements
mgrundy authored
34 echo "Partition table wipe \(dd\) failed"
47833c7 Initial checkin of SD Factory
mgrundy authored
35 ./errorlognotify.sh $DEVSNAME "partition wipe on $DEVNAME failed. Aborting."
36 exit -1
37 fi
38 echo "Partitioning Disk $DEVNAME"
39 echo "d
40 n
41 p
42 1
43
44
45 a
46 1
47 w
39343de Potential problems fixed and usability enhancements
mgrundy authored
48 " | fdisk $DEVNAME > /dev/null 2>&1
47833c7 Initial checkin of SD Factory
mgrundy authored
49 /bin/umount $DEVNAME\1
50 sleep 5
51 echo "Formatting $DEVNAME"
39343de Potential problems fixed and usability enhancements
mgrundy authored
52 /sbin/mkfs.ext3 $DEVNAME\1 > /dev/null 2>&1
47833c7 Initial checkin of SD Factory
mgrundy authored
53 if [ "$?" -ne "0" ] ; then
54 ./errorlognotify.sh $DEVSNAME "mkfs.ext3 on $DEVNAME freaking failed. Aborting."
55 exit -1
56 fi
57 /sbin/e2label $DEVNAME\1 "$3 `date +%m%d%y`"
58 if [ "$?" -ne "0" ] ; then
59 ./errorlognotify.sh $DEVSNAME "setting the label on $DEVNAME failed. Aborting."
60 exit -1
61 fi
62
63 if [ ! -d /mnt/verify-$DEVSNAME ]; then mkdir -p /mnt/verify-$DEVSNAME; fi
64 /bin/mount $DEVNAME\1 /mnt/verify-$DEVSNAME
65 if [ "$?" -ne "0" ] ; then
66 ./errorlognotify.sh $DEVSNAME "Unable to mount $DEVNAME. Aborting."
67 exit -1
68 fi
69 PREVDIR=$(pwd)
70 cd /mnt/verify-$DEVSNAME
71 echo "Writing BUG image $2 to $DEVNAME"
72 /bin/tar xf ${PREVDIR}/$2
73 if [ "$?" -ne "0" ] ; then
74 ./errorlognotify.sh $DEVSNAME "Failed writing the image to $DEVNAME. Aborting."
75 exit -1
76 fi
77 sleep 1
78 echo "Flushing and umounting $DEVNAME"
79 cd $PREVDIR
80 /bin/umount $DEVNAME\1
81 if [ "$?" -ne "0" ] ; then
82 ./errorlognotify.sh $DEVSNAME "umount fail on $DEVNAME Aborting."
83 exit -1
84 fi
85
86 echo "Checking Filesystem Consistency $DEVNAME"
87 /sbin/e2fsck -f -y $DEVNAME\1
88 if [ "$?" -ne "0" ] ; then
89 ./errorlognotify.sh $DEVSNAME "e2fsck exited with $? on $DEVNAME , screw it, it is toast"
90 exit -1
91 fi
92
93 echo "Verifying $DEVNAME file list against master"
94 sleep 1
95 if [ ! -d /mnt/verify-$DEVSNAME ]; then mkdir -p /mnt/verify-$DEVSNAME; fi
96 /bin/mount -r $DEVNAME\1 /mnt/verify-$DEVSNAME
97 PREVDIR=$(pwd)
98 cd /mnt/verify-$DEVSNAME
475af00 Switch md5sum from --quiet to --status
mgrundy authored
99 md5sum --status -c $PREVDIR/${2}.list.md5
47833c7 Initial checkin of SD Factory
mgrundy authored
100 if [ "$?" -ne "0" ] ; then
101 ./errorlognotify.sh $DEVSNAME "The file image on $DEVNAME is not consistent with master image."
102 cd $PREVDIR
103 /bin/umount $DEVNAME\1
104 exit -1
105 fi
106 cd $PREVDIR
107 /bin/umount $DEVNAME\1
108
109 echo "W00t! Factory image complete on $DEVNAME" >> ${DEVSNAME}.log
110 #echo "W00t! Factory image complete on $DEVNAME"
111
Something went wrong with that request. Please try again.