~jocave/checkbox/hybrid-amd-gpu-mods

« back to all changes in this revision

Viewing changes to scripts/optical_write_test

  • Committer: Zygmunt Krynicki
  • Date: 2013-05-17 13:54:25 UTC
  • mto: This revision was merged to the branch mainline in revision 2130.
  • Revision ID: zygmunt.krynicki@canonical.com-20130517135425-cxcenxx5t0qrtbxd
checkbox-ng: add CheckBoxNG sub-project

CheckBoxNG (or lowercase as checkbox-ng, pypi:checkbox-ng) is a clean
implementation of CheckBox on top of PlainBox. It provides a new
executable, 'checkbox' that has some of the same commands that were
previously implemented in the plainbox package.

In particular CheckBoxNG comes with the 'checkbox sru' command
(the same one as in plainbox). Later on this sub-command will be removed
from plainbox.

CheckBoxNG depends on plainbox >= 0.3

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
 
3
TEMP_DIR='/tmp/optical-test'
 
4
ISO_NAME='optical-test.iso'
 
5
SAMPLE_FILE_PATH='/usr/share/example-content/'
 
6
SAMPLE_FILE='Ubuntu_Free_Culture_Showcase'
 
7
MD5SUM_FILE='optical_test.md5'
 
8
START_DIR=$PWD
 
9
 
 
10
create_working_dirs(){
 
11
    # First, create the temp dir and cd there
 
12
    echo "Creating Temp directory and moving there ..."
 
13
    mkdir -p $TEMP_DIR || return 1
 
14
    cd $TEMP_DIR
 
15
    echo "Now working in $PWD ..."
 
16
    }
 
17
 
 
18
get_sample_data(){
 
19
    # Get our sample files
 
20
    echo "Getting sample files from $SAMPLE_FILE_PATH ..."
 
21
    cp -a $SAMPLE_FILE_PATH/$SAMPLE_FILE $TEMP_DIR
 
22
    return $?
 
23
}
 
24
 
 
25
generate_md5(){
 
26
    # Generate the md5sum
 
27
    echo "Generating md5sums of sample files ..."
 
28
    CUR_DIR=$PWD
 
29
    cd $SAMPLE_FILE
 
30
    md5sum * > $TEMP_DIR/$MD5SUM_FILE
 
31
    # Check the sums for paranoia sake
 
32
    check_md5 $TEMP_DIR/$MD5SUM_FILE
 
33
    rt=$?
 
34
    cd $CUR_DIR
 
35
    return $rt
 
36
}
 
37
 
 
38
check_md5(){
 
39
    echo "Checking md5sums ..."
 
40
    md5sum -c $1
 
41
    return $?
 
42
}
 
43
 
 
44
generate_iso(){
 
45
    # Generate ISO image
 
46
    echo "Creating ISO Image ..."
 
47
    genisoimage -r -J -o $ISO_NAME $SAMPLE_FILE
 
48
    return $?
 
49
}
 
50
 
 
51
burn_iso(){
 
52
    #Burn the ISO with wodim
 
53
    echo "Sleeping 10 seconds in case drive is not yet ready ..."
 
54
    sleep 10
 
55
    echo "Beginning image burn ..."
 
56
    wodim -eject dev=$OPTICAL_DRIVE $ISO_NAME
 
57
    rt=$?
 
58
    return $rt
 
59
}
 
60
 
 
61
check_disk(){
 
62
    TIMEOUT=300
 
63
    SLEEP_COUNT=0
 
64
    INTERVAL=3
 
65
 
 
66
    # Give the tester up to 5 minutes to reload the newly created CD/DVD
 
67
    echo "Waiting up to 5 minutes for drive to be mounted ..."
 
68
    while true; do
 
69
        sleep $INTERVAL
 
70
        SLEEP_COUNT=`expr $SLEEP_COUNT + $INTERVAL`
 
71
        
 
72
        mount $OPTICAL_DRIVE 2>&1 |egrep -q "already mounted"
 
73
        rt=$?
 
74
        if [ $rt -eq 0 ]; then
 
75
            echo "Drive appears to be mounted now"
 
76
            break
 
77
        fi
 
78
        
 
79
        # If they exceed the timeout limit, make a best effort to load the tray
 
80
        # in the next steps
 
81
        if [ $SLEEP_COUNT -ge $TIMEOUT ]; then
 
82
            echo "WARNING: TIMEOUT Exceeded and no mount detected!"
 
83
            break
 
84
        fi
 
85
    done
 
86
 
 
87
        
 
88
    echo "Deleting original data files ..."
 
89
    rm -rf $SAMPLE_FILE
 
90
    if [ ! -z "$(mount | grep $OPTICAL_DRIVE)" ]; then
 
91
        MOUNT_PT=$(mount | grep $OPTICAL_DRIVE | awk '{print $3}')
 
92
        echo "Disk is mounted to $MOUNT_PT"
 
93
    else
 
94
        echo "Attempting best effort to mount $OPTICAL_DRIVE on my own"
 
95
        MOUNT_PT=$TEMP_DIR/mnt
 
96
        echo "Creating temp mount point: $MOUNT_PT ..."
 
97
        mkdir $MOUNT_PT
 
98
        echo "Mounting disk to mount point ..."
 
99
        mount $OPTICAL_DRIVE $MOUNT_PT
 
100
        rt=$?
 
101
        if [ $rt -ne 0 ]; then
 
102
            echo "ERROR: Unable to re-mount $OPTICAL_DRIVE!" >&2
 
103
            return 1
 
104
        fi
 
105
    fi
 
106
    echo "Copying files from ISO ..."
 
107
    cp $MOUNT_PT/* $TEMP_DIR
 
108
    check_md5 $MD5SUM_FILE
 
109
    return $?
 
110
}
 
111
 
 
112
cleanup(){
 
113
    echo "Moving back to original location"
 
114
    cd $START_DIR
 
115
    echo "Now residing in $PWD"
 
116
    echo "Cleaning up ..."
 
117
    umount $MOUNT_PT
 
118
    rm -fr $TEMP_DIR
 
119
    echo "Ejecting spent media ..."
 
120
    eject $OPTICAL_DRIVE
 
121
}
 
122
 
 
123
failed(){
 
124
    echo $1
 
125
    echo "Attempting to clean up ..."
 
126
    cleanup
 
127
    exit 1
 
128
}
 
129
 
 
130
if [ -e $1 ]; then
 
131
    OPTICAL_DRIVE=$(readlink -f $1)
 
132
else
 
133
    OPTICAL_DRIVE='/dev/sr0'
 
134
fi    
 
135
 
 
136
create_working_dirs || failed "Failed to create working directories"
 
137
get_sample_data || failed "Failed to copy sample data"
 
138
generate_md5 || failed "Failed to generate initial md5"
 
139
generate_iso || failed "Failed to create ISO image"
 
140
burn_iso || failed "Failed to burn ISO image"
 
141
check_disk || failed "Failed to verify files on optical disk"
 
142
cleanup || failed "Failed to clean up"
 
143
exit 0