diff options
author | Waldemar Brodkorb <wbx@openadk.org> | 2010-10-31 19:51:33 +0100 |
---|---|---|
committer | Waldemar Brodkorb <wbx@openadk.org> | 2010-10-31 19:51:33 +0100 |
commit | 8f5add1754284c4e0f6162797b20b5d08b2e2882 (patch) | |
tree | efdbb6e29576ae5347acb7c85aa7064f3eef1b80 /scripts/install-rb532.sh | |
parent | 119fb7326416a7d22f2aa89cc3c3b9d686030f43 (diff) |
rework installation scripts for block devices
Avoid sfdisk, parted and chroot to be more portable.
Compile Host grub in target/tools, only used for ibmx40 target
right now. Add pt - partition table manager from OpenWrt with some
additions and portability fixes.
Cfgfs support missing, coming soon.
Diffstat (limited to 'scripts/install-rb532.sh')
-rwxr-xr-x | scripts/install-rb532.sh | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/scripts/install-rb532.sh b/scripts/install-rb532.sh new file mode 100755 index 000000000..9011388c7 --- /dev/null +++ b/scripts/install-rb532.sh @@ -0,0 +1,152 @@ +#!/usr/bin/env bash +# This file is part of the OpenADK project. OpenADK is copyrighted +# material, please see the LICENCE file in the top-level directory. + +if [ $(id -u) -ne 0 ];then + printf "Installation is only possible as root\n" + exit 1 +fi + +printf "Checking if sfdisk is installed" +sfdisk=$(which sfdisk) + +if [ ! -z $sfdisk -a -x $sfdisk ];then + printf "...okay\n" +else + printf "...failed\n" + exit 1 +fi + +printf "Checking if parted is installed" +parted=$(which parted) + +if [ ! -z $parted -a -x $parted ];then + printf "...okay\n" +else + printf "...failed\n" + exit 1 +fi + +printf "Checking if mke2fs is installed" +mke2fs=$(which mke2fs) + +if [ ! -z $mke2fs -a -x $mke2fs ];then + printf "...okay\n" +else + printf "...failed\n" + exit 1 +fi + +printf "Checking if tune2fs is installed" +tune2fs=$(which tune2fs) + +if [ ! -z $tune2fs -a -x $tune2fs ];then + printf "...okay\n" +else + printf "...failed\n" + exit 1 +fi + +if [ -z $1 ];then + printf "Please give your compact flash or USB device as first parameter\n" + exit 1 +else + if [ -z $2 ];then + printf "Please give your install tar archive as second parameter\n" + exit 2 + fi + if [ -f $2 ];then + printf "Installing $2 on $1\n" + else + printf "$2 is not a file, Exiting\n" + exit 1 + fi + if [ -z $3 ];then + printf "Please give the kernel as third parameter\n" + exit 2 + fi + if [ -f $3 ];then + printf "Installing $3 on $1\n" + else + printf "$3 is not a file, Exiting\n" + exit 1 + fi + if [ -b $1 ];then + printf "Using $1 as CF/USB disk for installation\n" + printf "This will destroy all data on $1, are you sure?\n" + printf "Type "y" to continue\n" + read y + if [ "$y" = "y" ];then + $sfdisk -l $1 2>&1 |grep 'No medium' + if [ $? -eq 0 ];then + exit 1 + else + printf "Starting with installation\n" + fi + else + printf "Exiting.\n" + exit 1 + fi + else + printf "Sorry $1 is not a block device\n" + exit 1 + fi +fi + + +if [ $(mount | grep $1| wc -l) -ne 0 ];then + printf "Block device $1 is in use, please umount first.\n" + exit 1 +fi + + +if [ $($sfdisk -l $1 2>/dev/null|grep Empty|wc -l) -ne 4 ];then + printf "Partitions already exist, should I wipe them?\n" + printf "Type y to continue\n" + read y + if [ $y = "y" ];then + printf "Wiping existing partitions\n" + dd if=/dev/zero of=$1 bs=512 count=1 >/dev/null 2>&1 + else + printf "Exiting.\n" + exit 1 + fi +fi + +printf "Create partition and filesystem for rb532\n" +rootpart=${1}2 +$parted -s $1 mklabel msdos +sleep 2 +maxsize=$(env LC_ALL=C $parted $1 -s unit cyl print |awk '/^Disk/ { print $3 }'|sed -e 's/cyl//') +rootsize=$(($maxsize-2)) + +$parted -s $1 unit cyl mkpart primary ext2 0 1 +$parted -s $1 unit cyl mkpart primary ext2 1 $rootsize +$parted -s $1 unit cyl mkpart primary fat32 $rootsize $maxsize +$parted -s $1 set 1 boot on +$sfdisk --change-id $1 1 27 +$sfdisk --change-id $1 3 88 +sleep 2 +$mke2fs ${1}2 +sync +dd if=$3 of=${1}1 bs=2048 +sync +sleep 2 +$tune2fs -c 0 -i 0 -m 1 ${rootpart} >/dev/null +if [ $? -eq 0 ];then + printf "Successfully disabled filesystem checks on ${rootpart}\n" +else + printf "Disabling filesystem checks failed, Exiting.\n" + exit 1 +fi + +tmp=$(mktemp -d) +mount -t ext2 ${rootpart} $tmp +printf "Extracting install archive\n" +tar -C $tmp -xzpf $2 +printf "Fixing permissions\n" +chmod 1777 $tmp/tmp +chmod 4755 $tmp/bin/busybox +umount $tmp +printf "Successfully installed.\n" +exit 0 |