2 ##############################################
3 # Script for Secure Linux Project #
4 # Copyright(c) 2005, 2006 by Roland Haeder #
5 ##############################################
6 # Purpose: Creates the USB sticks and makes #
7 # *binary* backups of your old once #
8 ##############################################
9 # This software is licensed under the GNU #
10 # General Public License Version 2 or either #
11 # and comes with ABSOLUTELY NO WARRANTY #
12 # neither implied nor explicit. #
13 ##############################################
15 . ./.settings.sh || exit 3
17 if test -b $STICK_DEVICE; then
18 # Stick is a real device
19 echo "WARNING! REAL DEVICE $STICK_DEVICE ENTERED! PLEASE MAKE BACKUP BEFORE CONTINUE!"
20 echo "Please insert first stick now ($MASTER_USER) before continue."
22 echo "Press RETURN to continue or CTRL+C to abort here."
24 DEVICE="$STICK_DEVICE"
25 echo -n "$0: Preparing backups... "
26 BACKUP="$BASEDIR/backups/"
27 mkdir $BACKUP > /dev/null 2>&1
28 for user in $USERS; do
29 mkdir $BACKUP/$user > /dev/null 2>&1
35 losetup -d /dev/loop6 > /dev/null 2>&1
36 losetup -d $DEVICE > /dev/null 2>&1
37 if test -e $STICK_DEVICE; then
39 echo "$0: Using image $STICK_DEVICE."
40 losetup $DEVICE $STICK_DEVICE
42 if test $STICK_SIZE -gt 0; then
44 echo "$0: Creating testing image $STICK_DEVICE."
45 dd if=/dev/zero of=$STICK_DEVICE bs=1k count=$STICK_SIZE
46 losetup $DEVICE $STICK_DEVICE
48 # Invalid size / cannot detect!
49 echo "$0: Please provide a size for image $STICK_DEVICE!"
55 # Clean an existing .md5sums file
56 if test ! -e "$BASEDIR/initrd/.md5sums"; then
57 echo -n "" > $BASEDIR/initrd/.md5sums
59 mv $BASEDIR/initrd/.md5sums $BASEDIR/.md5sums
62 if test -b $STICK_DEVICE; then
63 if test ! -e "$BASEDIR/.backuped"; then
64 # Now let's setup all sticks
65 echo "$0: Will now do a binary backup of your sticks."
66 for user in $USERS; do
67 rmmod usb-storage > /dev/null 2>&1
68 echo "Please insert USB stick for $user and press RETURN to continue."
70 insmod -kv $USB_STORAGE delay_use=0 > /dev/null 2>&1
72 for ((FAILED=1, TRY=1; ($FAILED != 0) && (TRY <= 15); TRY++)) do
73 # Auto-detect size here
74 SSIZE=`fdisk -s $DEVICE`
75 # DEBUG: echo "Code=$? (Size=$(($SSIZE/1024)) MB)"
76 if test "$?" == "0"; then
81 if test "$FAILED" == "0"; then
82 echo -n "$0: Binary backup of $DEVICE for $user... "
83 dd if=$DEVICE of=$BACKUP/$user/stick.img bs=1k count=$SSIZE $CONVERT > /dev/null 2>&1
85 if test "$CODE" == "0"; then
87 echo -n "$0: Compressing... "
88 bzip2 -9f $BACKUP/$user/stick.img >/dev/null 2>&1
91 echo "failed. (Code=$CODE)"
95 echo "$0: Too many attemnts to read from $DEVICE!"
99 echo "$0: Binary backup complete."
100 echo -n "" > "$BASEDIR/.backuped"
103 echo "$0: Running make_part() on all sticks now."
104 for user in $USERS; do
105 if test ! -e "$BASEDIR/.stick_$user"; then
106 # Create filename for the image
107 FILE="$BASEDIR/setup/images/key-$user.img"
109 rmmod usb-storage > /dev/null 2>&1
110 echo "Please insert USB stick for $user and press RETURN to continue."
112 echo "WARNING! You will loose data after this point!"
114 insmod $USB_STORAGE delay_use=0 > /dev/null 2>&1
115 for ((FAILED=1, TRY=1; ($FAILED != 0) && ($TRY <= 15); TRY++)) do
116 # Auto-detect size here
117 #echo "$0: Scanning..."
118 SSIZE=`fdisk -s $DEVICE`
120 #echo "$0: Code=$CODE"
121 if test "$CODE" == "0"; then
125 #echo "$0: Sleeping..."
129 if test "$FAILED" == "0"; then
130 echo "$0: Slept $TRY seconds."
131 # Total size for the parted command (again)
132 SIZE="$(($SSIZE/1024))"
133 SIZE_TARGET=`stat --format="%s" $FILE`
135 # Continue with creating new partitions...
136 echo "$0: Creating partition on $DEVICE..."
143 echo "$0: Too many attemnts to read from $DEVICE!"
146 echo -n "" > "$BASEDIR/.stick_$user"
148 echo "$0: Skipping stick for $user."
152 # Do we need to update STICK_START?
153 if test "$STICK_START" == "xxx"; then
154 echo "$0: Fatal error. Please remove one of the .stick_user files to setup STICK_START!"
158 # Total size for the parted command
159 SIZE="$(($SSIZE/1024))"
161 # For testing purposes only first user
162 echo "$0: Using $MASTER_USER for testing."
164 # Create "partitions" on the image
170 # Set user for the first user
173 # Create filename for the image
174 FILE="$BASEDIR/setup/images/key-$user.img"
176 # Use MASTER_USER for testing purposes
177 echo "$0: Using image $FILE."
178 SIZE_TARGET=`stat --format="%s" $FILE`
184 if test -e "$BASEDIR/.md5sums"; then
185 cat $BASEDIR/.md5sums $BASEDIR/initrd/.md5sums >> $BASEDIR/.dummy
186 rm $VERBOSE $BASEDIR/.md5sums
187 mv $VERBOSE $BASEDIR/.dummy $BASEDIR/initrd/.md5sums
190 # Creating image/stick now completed
192 echo "$0: All done now."
194 echo "Now it's time for executing finish.sh to finish setup."