diff options
author | Paul Kocialkowski <contact@paulk.fr> | 2012-08-15 13:47:48 +0200 |
---|---|---|
committer | Paul Kocialkowski <contact@paulk.fr> | 2012-08-15 13:47:48 +0200 |
commit | 219c3b068fbf197207e39f446ba508a3b4004a14 (patch) | |
tree | 0efef9980ef51c3b4b9bc37f5478c17c3b8b98c7 | |
parent | ac166b0c4ae8c7a1a5a799d3bf51725f959f5c04 (diff) | |
download | device_goldelico_gta04-219c3b068fbf197207e39f446ba508a3b4004a14.zip device_goldelico_gta04-219c3b068fbf197207e39f446ba508a3b4004a14.tar.gz device_goldelico_gta04-219c3b068fbf197207e39f446ba508a3b4004a14.tar.bz2 |
replicant_gta04_install.sh: Create both install and system sdcard
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
-rwxr-xr-x | replicant_gta04_install.sh | 190 |
1 files changed, 171 insertions, 19 deletions
diff --git a/replicant_gta04_install.sh b/replicant_gta04_install.sh index 804d4a4..09ac0ca 100755 --- a/replicant_gta04_install.sh +++ b/replicant_gta04_install.sh @@ -17,22 +17,31 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +# # Env vars +# export LC_ALL=C +# # Global vars +# +TYPE="" DRIVE="" DRIVE_NAME="" DRIVE_SIZE="" DRIVE_CYLINDERS="" DRIVE_PART="" -SYSTEM_AR="" +FILES_BASE="./" MOUNT_BASE="/media" +# # Functions +# + +# Display display_banner() { echo "Replicant GTA04 installer" @@ -40,13 +49,22 @@ display_banner() { } display_help() { - echo "Usage: $0 [DRIVE] [SYSTEM]" + echo "Usage: $0 [TYPE] [DRIVE]" + echo "" + echo "Arguments:" + echo "- The [TYPE] argument can either be:" + echo " * \"install\" to create an install sdcard" + echo " * \"system\" to create a system sdcard" + echo "- The [DRIVE] argument is the sdcard drive node and can be omitted" echo "" - echo "Notes: " - echo "- The [DRIVE] argument can be omitted" - echo "- The [SYSTEM] argument must be a tar archive" + echo "Notes:" + echo "The following files must be present in the directory where you run the script:" + echo "* bootloader.img boot.scr boot.img (install)" + echo "* system.tar.bz2 (system)" } +# Drive + drive_select_list() { drives_dir="/dev/disk/by-id/" @@ -95,13 +113,15 @@ drive_select() echo "" } -drive_write_confirm() { +drive_select_confirm() { if [ "$DRIVE" = "" ] then echo "Wrong drive block" exit 1 fi + list=$( mount | grep $DRIVE | sed "s|$DRIVE[0-9]* on \([^ ]*\) .*|\1|g" ) + echo "This is going to erase the following drive:" if [ "$DRIVE_NAME" != "" ] @@ -111,6 +131,17 @@ drive_write_confirm() { echo "- $DRIVE" fi + for mount_point in $list + do + mount_point_dir=$( dirname $mount_point ) + if [ "$mount_point_dir" != "/media" ] && [ "$mount_point_dir" != "/mnt" ] && [ "$mount_point" != "/media" ] && [ "$mount_point" != "/mnt" ] + then + echo "" + echo "Warning: the drive is mounted as $mount_point!" + echo "This is probably not the drive you want to use!" + fi + done + echo "" echo -n "Are you sure? " read confirm @@ -125,11 +156,42 @@ drive_write_confirm() { } drive_umount() { - umount $DRIVE* 2> /dev/null + list=$( mount | grep $DRIVE | sed "s|$DRIVE[0-9]* on \([^ ]*\) .*|\1|g" ) + + for mount_point in $list + do + echo "Unmounting $mount_point" + + umount "$mount_point" + if [ $? != 0 ] + then + echo "Unmounting $mount_point failed, arborting!" + exit 1 + fi + done } drive_empty() { + # Backup + dd if="$DRIVE" of=".drive_start_backup" bs=1024 count=1024 + dd if=/dev/zero of="$DRIVE" bs=1024 count=1024 + if [ $? != 0 ] + then + echo "Emptying the drive failed, aborting!" + exit 1 + fi +} + +drive_rescue() { + if [ -f ".drive_start_backup" ] + then + echo -n "Something went wrong, do you want to restore drive start backup? " + if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ] + then + dd if=".drive_start_backup" of="$DRIVE" bs=1024 count=1024 + fi + fi } drive_infos_get() { @@ -137,7 +199,67 @@ drive_infos_get() { DRIVE_CYLINDERS=$( echo "$DRIVE_SIZE/255/63/512" | bc ) } -drive_partitions_set() { +drive_eject() { + rm -rf ".drive_start_backup" + eject "$DRIVE" +} + +# Install + +install_partitions_set() { + { + echo ",,0c" + } | sfdisk -D -H 255 -S 63 -C "$DRIVE_CYLINDERS" "$DRIVE" + if [ $? != 0 ] + then + drive_rescue + exit 1 + fi + + sleep 1 + + mkfs.vfat -F 32 -n "install" "${DRIVE}1" + + sleep 1 +} + +install_write() { + echo "Writing install files" + + mkdir -p "$MOUNT_BASE/install" + mount "${DRIVE}1" "$MOUNT_BASE/install" + + cp "bootloader.img" "$MOUNT_BASE/install" + if [ $? != 0 ] + then + exit 1 + fi + + cp "boot.scr" "$MOUNT_BASE/install" + if [ $? != 0 ] + then + exit 1 + fi + + cp "boot.img" "$MOUNT_BASE/install" + if [ $? != 0 ] + then + exit 1 + fi + + dir=$( pwd ) + echo "Syncing files" + cd "$MOUNT_BASE/install" + sync + cd "$dir" + + umount "$MOUNT_BASE/install" + rmdir "$MOUNT_BASE/install" +} + +# System + +system_partitions_set() { system_size=$( echo "(250 * 1024 * 1024) / ($DRIVE_SIZE/$DRIVE_CYLINDERS)" | bc ) data_size=$( echo "(250 * 1024 * 1024) / ($DRIVE_SIZE/$DRIVE_CYLINDERS)" | bc ) cache_size=$( echo "(100 * 1024 * 1024) / ($DRIVE_SIZE/$DRIVE_CYLINDERS)" | bc ) @@ -148,11 +270,20 @@ drive_partitions_set() { echo ",$cache_size,83" echo ",,0c" } | sfdisk -D -H 255 -S 63 -C "$DRIVE_CYLINDERS" "$DRIVE" + if [ $? != 0 ] + then + drive_rescue + exit 1 + fi + + sleep 1 mkfs.ext2 -L "system" "${DRIVE}1" mkfs.ext2 -L "data" "${DRIVE}2" mkfs.ext2 -L "cache" "${DRIVE}3" mkfs.vfat -F 32 -n "storage" "${DRIVE}4" + + sleep 1 } system_write() { @@ -160,7 +291,15 @@ system_write() { mkdir -p "$MOUNT_BASE/system" mount "${DRIVE}1" "$MOUNT_BASE/system" - tar -p -xf $SYSTEM_AR -C "$MOUNT_BASE/system" "system" + + tar -p -xf "system.tar.bz2" -C "$MOUNT_BASE/system/" --strip-components=1 "system/" + if [ $? != 0 ] + then + umount "$MOUNT_BASE/system" + rmdir "$MOUNT_BASE/system" + + exit 1 + fi dir=$( pwd ) echo "Syncing files" @@ -177,10 +316,6 @@ display_end() { echo "Your drive is now ready to be used!" } -drive_eject() { - eject "$DRIVE" -} - # Script start if [ $# -eq 0 ] @@ -191,27 +326,44 @@ fi if [ $# -eq 1 ] then - SYSTEM_AR=$1 + TYPE=$1 fi if [ $# -eq 2 ] then - DRIVE=$1 - SYSTEM_AR=$2 + TYPE=$1 + DRIVE=$2 fi display_banner +if [ "$TYPE" != "install" ] && [ "$TYPE" != "system" ] +then + display_help + exit 1 +fi + if [ "$DRIVE" = "" ] then drive_select fi -drive_write_confirm +# Drive +drive_select_confirm drive_umount drive_empty drive_infos_get -drive_partitions_set -system_write + +# Install/System +if [ "$TYPE" = "install" ] +then + install_partitions_set + install_write +else + system_partitions_set + system_write +fi + +# Finishing display_end drive_eject |