#2 whitespaces unification, more sudo
Merged 2 years ago by pbrobinson. Opened 2 years ago by hrw.
hrw/arm-image-installer master  into  master

file modified
+130 -128

@@ -14,11 +14,11 @@ 

  

     --image=IMAGE    - xz compressed image file name

     --target=TARGET  - target board

- 		      [${TARGETS}]

+                      [${TARGETS}]

     --media=DEVICE   - media device file (/dev/[sdX|mmcblkX])

     --selinux=ON/OFF - Turn SELinux off/on as needed

     --norootpass     - Remove the root password

-     -y		    - Assumes yes, will not wait for confirmation

+    -y		    - Assumes yes, will not wait for confirmation

     --version	    - Display version and exit

     --resizefs	    - Resize root filesystem to fill media device

     --addconsole     - Add system console to extlinux.conf

@@ -30,91 +30,91 @@ 

  # and valid targets.

  DIR=$(dirname $0)

  if [ -d "/usr/share/arm-image-installer/boards.d" ]; then

-   BOARDDIR="/usr/share/arm-image-installer/boards.d"

+         BOARDDIR="/usr/share/arm-image-installer/boards.d"

  else

-   DIR=$(dirname $0)

-   BOARDDIR="${DIR}/boards.d"

+         DIR=$(dirname $0)

+         BOARDDIR="${DIR}/boards.d"

  fi

  TARGETS=$(ls -1 ${BOARDDIR})

  TARGETS=$(echo ${TARGETS} | sed -e 's/[[:space:]]/|/g')

  

  # check the args

  while [ $# -gt 0 ]; do

-     case $1 in

- 	--debug)

- 	    set -x

- 	    ;;

- 	-h|--help)

- 	    usage

- 	    exit 0

- 	    ;;

- 	--target*)

-             if echo $1 | grep '=' >/dev/null ; then

-                 TARGET=$(echo $1 | sed 's/^--target=//')

-             else

-                 TARGET=$2

-                 shift

-             fi

-             ;;

-     	--image*)

-             if echo $1 | grep '=' >/dev/null ; then

-                 IMAGE=$(echo $1 | sed 's/^--image=//')

-             else

-                 IMAGE=$2

-                 shift

-             fi

-             ;;

-     	--media*)

-             if echo $1 | grep '=' >/dev/null ; then

-                 MEDIA=$(echo $1 | sed 's/^--media=//')

-             else

-                 MEDIA=$2

-                 shift

- 	    fi

- 	    ;;

- 	--selinux*)

-             if echo $1 | grep '=' >/dev/null ; then

-                 SELINUX=$(echo $1 | sed 's/^--selinux=//')

-             else

-                 SELINUX=$2

-                 shift

-             fi

-             ;;

- 	--norootpass)

-             NOROOTPASS=1

-             ;;

- 	--resizefs)

-             RESIZEFS=1

-             ;;

- 	--addconsole)

-             CONSOLE=1

-             ;;

- 	--version)

- 	    echo "$(basename ${0})-"$VERSION""

- 	    exit 0

- 	    ;;

- 	-y)

- 	    NOASK=1

- 	    ;;

-     	*)

- 	    echo "$(basename ${0}): Error - ${1}"

-             usage

- 	    exit 1

-             ;;

-     	esac

-     shift

+         case $1 in

+                 --debug)

+                         set -x

+                         ;;

+                 -h|--help)

+                         usage

+                         exit 0

+                         ;;

+                 --target*)

+                         if echo $1 | grep '=' >/dev/null ; then

+                                 TARGET=$(echo $1 | sed 's/^--target=//')

+                         else

+                                 TARGET=$2

+                                 shift

+                         fi

+                         ;;

+                 --image*)

+                         if echo $1 | grep '=' >/dev/null ; then

+                                 IMAGE=$(echo $1 | sed 's/^--image=//')

+                         else

+                                 IMAGE=$2

+                                 shift

+                         fi

+                         ;;

+                 --media*)

+                         if echo $1 | grep '=' >/dev/null ; then

+                                 MEDIA=$(echo $1 | sed 's/^--media=//')

+                         else

+                                 MEDIA=$2

+                                 shift

+                         fi

+                         ;;

+                 --selinux*)

+                         if echo $1 | grep '=' >/dev/null ; then

+                                 SELINUX=$(echo $1 | sed 's/^--selinux=//')

+                         else

+                                 SELINUX=$2

+                                 shift

+                         fi

+                         ;;

+                 --norootpass)

+                         NOROOTPASS=1

+                         ;;

+                 --resizefs)

+                         RESIZEFS=1

+                         ;;

+                 --addconsole)

+                         CONSOLE=1

+                         ;;

+                 --version)

+                         echo "$(basename ${0})-"$VERSION""

+                         exit 0

+                         ;;

+                 -y)

+                         NOASK=1

+                         ;;

+                 *)

+                         echo "$(basename ${0}): Error - ${1}"

+                         usage

+                         exit 1

+                         ;;

+         esac

+         shift

  done

  

  # ensure sudo user

  if [ "$(sudo whoami)" != "root" ] ; then

- 	echo "Error: This script requires 'sudo' privileges in order to write to disk & mount media."

- 	exit 1

+         echo "Error: This script requires 'sudo' privileges in order to write to disk & mount media."

+         exit 1

  fi

  

  # check to make sure populated

  if [ "$MEDIA" = "" ] ; then

-   usage

-   exit 1

+         usage

+         exit 1

  fi

  

  # change cubietruck target to uppercase

@@ -124,33 +124,33 @@ 

  

  # check for boards

  if [ "$TARGET" != "" -a ! -e "${BOARDDIR}/${TARGET}" ] ; then

-       echo "Error: You must choose a supported board or none at all." 

-       usage

-       exit 1

+         echo "Error: You must choose a supported board or none at all." 

+         usage

+         exit 1

  fi

  

  # image exists

  if [ ! -f "$IMAGE" ] && [ "$IMAGE" != "" ] ; then

-   echo "Error: $IMAGE not found! Please choose an existing image."

-   exit 1

+         echo "Error: $IMAGE not found! Please choose an existing image."

+         exit 1

  fi

  

  # device exists

  if [ ! -e "$MEDIA" ] ; then

-   echo "Error: $MEDIA not found! Please choose an existing device."

-   exit 1

+         echo "Error: $MEDIA not found! Please choose an existing device."

+         exit 1

  fi

  

  # check media type /dev/sdX or /dev/mmcblkX or loop device

  case $MEDIA in

-   	"/dev/mmcblk"*)

-     			BOOTPART="${MEDIA}p1"

- 			ROOTPART="${MEDIA}p3"

-     			;;

-   	*)

-     			BOOTPART="${MEDIA}1"

-                         ROOTPART="${MEDIA}3"

-     			;;

+         "/dev/mmcblk"*)

+                 BOOTPART="${MEDIA}p1"

+                 ROOTPART="${MEDIA}p3"

+                 ;;

+         *)

+                 BOOTPART="${MEDIA}1"

+                 ROOTPART="${MEDIA}3"

+                 ;;

  esac

  

  clear

@@ -159,17 +159,17 @@ 

  echo "====================================================="

  # Image if included

  if [ "$IMAGE" != "" ] ; then

- 	echo "= Selected Image:                                 "

- 	echo "= $IMAGE"

+         echo "= Selected Image:                                 "

+         echo "= $IMAGE"

  fi

  echo "= Selected Media : $MEDIA"

  # target hardware platform

  if [ "$TARGET" != "" ] ; then 

- 	echo "= U-Boot Target : $TARGET"

+         echo "= U-Boot Target : $TARGET"

  fi

  # SE Linux On/Off

  if [ "$SELINUX" != "" ] ; then

- 	echo "= SELINUX = $SELINUX"

+         echo "= SELINUX = $SELINUX"

  fi

  # Remove root password

  if [ "$NOROOTPASS" != "" ] ; then

@@ -191,38 +191,38 @@ 

  echo "*****************************************************"

  echo "*****************************************************"

  if [ "$NOASK" != 1 ] ; then 

- 	echo " "

- 	echo " Type 'YES' to proceed, anything else to exit now "

- 	echo " "

- # wait for agreement

- 	read -p "= Proceed? " PROCEED

- 	if [ "$(echo ${PROCEED} | tr [:lower:] [:upper:])" != "YES" ] ; then

- 		echo "User exit, no image written."

- 		exit 0

- 	fi

+         echo " "

+         echo " Type 'YES' to proceed, anything else to exit now "

+         echo " "

+         # wait for agreement

+         read -p "= Proceed? " PROCEED

+         if [ "$(echo ${PROCEED} | tr [:lower:] [:upper:])" != "YES" ] ; then

+                 echo "User exit, no image written."

+                 exit 0

+         fi

  fi

  # umount before starting

  umount $MEDIA* &> /dev/null

  

  # Write the disk image to media

  if [ "$IMAGE" != "" ] ; then

- 	echo "= Writing: "

- 	echo "= $IMAGE "

- 	echo "= To: $MEDIA ...."

- 	xzcat $IMAGE | dd of=$MEDIA bs=4M; sync; sleep 3

- 	echo "= Writing image complete!"

- # read the new partition table

- 	partprobe "$MEDIA"

+         echo "= Writing: "

+         echo "= $IMAGE "

+         echo "= To: $MEDIA ...."

+         xzcat $IMAGE | dd of=$MEDIA bs=4M; sync; sleep 3

+         echo "= Writing image complete!"

+         # read the new partition table

+         partprobe "$MEDIA"

  fi

  

  # resize root filesystem before mounting

  if [ "$RESIZEFS" != "" ] ; then

- 	echo "= Resizing $MEDIA ...."

- 	sync

- 	echo ", +" | sfdisk -N 3 "$MEDIA"

- 	fsck.ext4 -fy "$ROOTPART"

- 	partprobe "$MEDIA"

- 	resize2fs "$ROOTPART"

+         echo "= Resizing $MEDIA ...."

+         sync

+         echo ", +" | sfdisk -N 3 "$MEDIA"

+         fsck.ext4 -fy "$ROOTPART"

+         partprobe "$MEDIA"

+         resize2fs "$ROOTPART"

  fi

  

  # make temp mount points

@@ -232,28 +232,28 @@ 

  

  # turn off selinux

  if [ "$SELINUX" != "" ] ; then

- 	if [ "$(echo ${SELINUX} | tr [:lower:] [:upper:])" = "OFF" ] ; then

-       		echo "= Turning SELinux off ..."

- 	        sed -i 's/append/& enforcing=0/' /tmp/boot/extlinux/extlinux.conf

- # turn on selinux

- 	elif [ "$(echo ${SELINUX} | tr [:lower:] [:upper:])" = "ON" ] ; then

-     		echo "= Turning SELinux on ..."

- 		sed -i 's/ enforcing=0//' /tmp/boot/extlinux/extlinux.conf

- 	fi

+         if [ "$(echo ${SELINUX} | tr [:lower:] [:upper:])" = "OFF" ] ; then

+                 echo "= Turning SELinux off ..."

+                 sed -i 's/append/& enforcing=0/' /tmp/boot/extlinux/extlinux.conf

+                 # turn on selinux

+         elif [ "$(echo ${SELINUX} | tr [:lower:] [:upper:])" = "ON" ] ; then

+                 echo "= Turning SELinux on ..."

+                 sed -i 's/ enforcing=0//' /tmp/boot/extlinux/extlinux.conf

+         fi

  fi

  # Remove root password

  if [ "$NOROOTPASS" = "1" ] ; then

-         	echo "= Removing the root password."

- 	        sed -i 's/root:x:/root::/' /tmp/root/etc/passwd

+         echo "= Removing the root password."

+         sed -i 's/root:x:/root::/' /tmp/root/etc/passwd

  fi

  # determine uboot and write to disk 

  if [ "$TARGET" = "" ]; then

- 	echo "= No U-boot will be written."

- 	TARGET="Mystery Board"

+         echo "= No U-boot will be written."

+         TARGET="Mystery Board"

  else

- 	PREFIX=/tmp/root

- 	. "${BOARDDIR}/${TARGET}"

- 	# Add console

+         PREFIX=/tmp/root

+         . "${BOARDDIR}/${TARGET}"

+         # Add console

          if [ "$CONSOLE" = "1" ] && [ "$SYSCON" != "" ] ; then

                  echo "= Adding console $SYSCON to extlinux.conf ..."

                  sed -i "s|append|& console=$SYSCON|" /tmp/boot/extlinux/extlinux.conf

@@ -266,3 +266,5 @@ 

  echo ""

  echo "= Installation Complete! Insert into the "$TARGET" and boot."

  exit 0

+ 

+ # vi: tabstop=8 softtabstop=0 expandtab shiftwidth=8 smarttab

file modified
+60 -52

@@ -16,86 +16,92 @@ 

  

  # check the args

  while [ $# -gt 0 ]; do

-     case $1 in

-         --debug)

-             set -x

-             ;;

-         -h|--help)

-             usage

-             ;;

- 	--media*)

-             if echo $1 | grep '=' >/dev/null ; then

-                 MEDIA=$(echo $1 | sed 's/^--media=//')

-             else

-                 MEDIA=$2

-                 shift

-             fi

-             ;;

- 	--url*)

- 	    if echo $1 | grep '=' >/dev/null ; then

- 		URL=$(echo $1 | sed 's/^--url=//')

- 	    else

- 		URL=$2

- 		shift

- 	    fi

-             ;;

-         *)

-             echo "$(basename ${0}): Error - ${1}"

-             usage

-             exit 1

-             ;;

+         case $1 in

+                 --debug)

+                         set -x

+                         ;;

+                 -h|--help)

+                         usage

+                         ;;

+                 --media*)

+                         if echo $1 | grep '=' >/dev/null ; then

+                                 MEDIA=$(echo $1 | sed 's/^--media=//')

+                         else

+                                 MEDIA=$2

+                                 shift

+                         fi

+                         ;;

+                 --url*)

+                         if echo $1 | grep '=' >/dev/null ; then

+                                 URL=$(echo $1 | sed 's/^--url=//')

+                         else

+                                 URL=$2

+                                 shift

+                         fi

+                         ;;

+                 *)

+                         echo "$(basename ${0}): Error - ${1}"

+                         usage

+                         exit 1

+                         ;;

          esac

-     shift

+         shift

  done

  

+ # ensure user

+ if [ "$(sudo whoami)" != "root" ] ; then

+         echo "Error: This script requires 'sudo' privileges in order to write to disk & mount media."

+         exit 1

+ fi

+ 

  # check if media exists

  if [[ ! -e $MEDIA ]] ; then 

- 	echo "Missing media"

- 	usage

- 	exit 1

+         echo "Missing media"

+         usage

+         exit 1

  fi 

  # check if url specified if not use mastermirror

  if [[ $URL = '' ]] ; then

- 	URL="http://dl.fedoraproject.org/pub/fedora/linux/releases/22/Server/armhfp/os/"

+         URL="http://dl.fedoraproject.org/pub/fedora/linux/releases/22/Server/armhfp/os/"

  fi

  

  # unmount media

  echo "= Umounting $MEDIA."

- sudo umount $MEDIA* &> /dev/null

+ umount $MEDIA* &> /dev/null

  

  # create partition 

  echo "= Creating partition."

- sudo parted -s $MEDIA mklabel msdos &> /dev/null

- sudo parted -s -a optimal $MEDIA mkpart primary ext4 1 512 &> /dev/null

+ parted -s $MEDIA mklabel msdos &> /dev/null

+ parted -s -a optimal $MEDIA mkpart primary ext4 1 512 &> /dev/null

  

  # re-read table

- sudo partprobe $MEDIA

+ partprobe $MEDIA

  

  # check media type /dev/sdX or /dev/mmcblkX

  case $MEDIA in

          "/dev/mmcblk"*)

-                         PART1="${MEDIA}p1"

-                         ;;

+                 PART1="${MEDIA}p1"

+                 ;;

          *)

-                         PART1="${MEDIA}1"

-                         ;;

+                 PART1="${MEDIA}1"

+                 ;;

  esac

  

  # create filesystem

  echo "= Creating filesystem."

- sudo mkfs.ext4 $PART1 &> /dev/null

+ mkfs.ext4 $PART1 &> /dev/null

  

  # create temp dir

  echo "= Making temporary directory."

- sudo rm -rf /tmp/install-card

+ rm -rf /tmp/install-card

  mkdir /tmp/install-card

- sudo mount $PART1 /tmp/install-card

+ mount $PART1 /tmp/install-card

  

  # get pxe images and dtb files

- sudo /usr/bin/rsync -ahH rsync://dl.fedoraproject.org/pub/fedora/linux/releases/22/Server/armhfp/os/images/pxeboot/ /tmp/install-card/

+ /usr/bin/rsync -ahH rsync://dl.fedoraproject.org/pub/fedora/linux/releases/22/Server/armhfp/os/images/pxeboot/ /tmp/install-card/

  

  # make and populate the extlinux.conf

- sudo mkdir /tmp/install-card/extlinux/

+ mkdir /tmp/install-card/extlinux/

  cat > /tmp/extlinux.conf << EOF

  # extlinux.conf generated by script

  ui menu.c32

@@ -106,12 +112,14 @@ 

  totaltimeout 600

  

  label Fedora 22_Server Installer for ARM

- 	kernel /vmlinuz

- 	append inst.repo=$URL

- 	fdtdir /dtb/

- 	initrd /initrd.img

+ kernel /vmlinuz

+ append inst.repo=$URL

+ fdtdir /dtb/

+ initrd /initrd.img

  EOF

- sudo mv /tmp/extlinux.conf /tmp/install-card/extlinux/

+ mv /tmp/extlinux.conf /tmp/install-card/extlinux/

  sync

- sudo umount $MEDIA* &> /dev/null

+ umount $MEDIA* &> /dev/null

  echo "= Complete!"

+ 

+ # vi: tabstop=8 softtabstop=0 expandtab shiftwidth=8 smarttab

file modified
+60 -58

@@ -20,51 +20,51 @@ 

  

  # check the args

  while [ $# -gt 0 ]; do

-     case $1 in

-         --debug)

-             set -x

-             ;;

-         -h|--help)

-             usage

-             ;;

-         --target*)

-             if echo $1 | grep '=' >/dev/null ; then

-                 TARGET=$(echo $1 | sed 's/^--target=//')

-             else

-                 TARGET=$2

-                 shift

-             fi

-             ;;

-         --media*)

-             if echo $1 | grep '=' >/dev/null ; then

-                 MEDIA=$(echo $1 | sed 's/^--media=//')

-             else

-                 MEDIA=$2

-                 shift

-             fi

-             ;;

- 	--tag*)

-             if echo $1 | grep '=' >/dev/null ; then

-                 KOJI_TAG=$(echo $1 | sed 's/^--tag=//')

-             else

-                 KOJI_TAG=$2

-                 shift

-             fi

-             ;;

-         *)

-             echo "$(basename ${0}): Error - ${1}"

-             usage

-             exit 1

-             ;;

+         case $1 in

+                 --debug)

+                         set -x

+                         ;;

+                 -h|--help)

+                         usage

+                         ;;

+                 --target*)

+                         if echo $1 | grep '=' >/dev/null ; then

+                                 TARGET=$(echo $1 | sed 's/^--target=//')

+                         else

+                                 TARGET=$2

+                                 shift

+                         fi

+                         ;;

+                 --media*)

+                         if echo $1 | grep '=' >/dev/null ; then

+                                 MEDIA=$(echo $1 | sed 's/^--media=//')

+                         else

+                                 MEDIA=$2

+                                 shift

+                         fi

+                         ;;

+                 --tag*)

+                         if echo $1 | grep '=' >/dev/null ; then

+                                 KOJI_TAG=$(echo $1 | sed 's/^--tag=//')

+                         else

+                                 KOJI_TAG=$2

+                                 shift

+                         fi

+                         ;;

+                 *)

+                         echo "$(basename ${0}): Error - ${1}"

+                         usage

+                         exit 1

+                         ;;

          esac

-     shift

+         shift

  done

  

  if [ -d "/usr/share/arm-image-installer/boards.d" ]; then

-   BOARDDIR="/usr/share/arm-image-installer/boards.d"

+         BOARDDIR="/usr/share/arm-image-installer/boards.d"

  else

-   DIR=$(dirname $0)

-   BOARDDIR="${DIR}/boards.d"

+         DIR=$(dirname $0)

+         BOARDDIR="${DIR}/boards.d"

  fi

  TARGETS=$(ls -1 ${DIR}/${BOARDDIR})

  TARGETS=$(echo ${TARGETS} | sed -e 's/[[:space:]]/|/g')

@@ -82,25 +82,25 @@ 

          exit 1

  fi

  if [[ $KOJI_TAG != '' ]] ; then

- 	if [[ ! -f /usr/bin/koji ]]; then

- 	 echo "Please install koji-utils for this option."

- 	 exit 1

- 	 else

- 	PREFIX='/tmp/root/'

- 	sudo rm -rf /tmp/root &> /dev/null

- 	mkdir $PREFIX

+         if [[ ! -f /usr/bin/koji ]]; then

+                 echo "Please install koji-utils for this option."

+                 exit 1

+         else

+                 PREFIX='/tmp/root/'

+                 sudo rm -rf /tmp/root &> /dev/null

+                 mkdir $PREFIX

  

- #get the latest uboot

- 	pushd $PREFIX &> /dev/null

- 	if [ $KOJI_TAG = f22 ]; then

- 		koji download-build --arch=armv7hl --latestfrom=$KOJI_TAG uboot-tools

- 		else

- 		koji download-build --arch=noarch --latestfrom=$KOJI_TAG uboot-tools

- 	fi

- 	# unpack uboot

- 	rpm2cpio uboot-images*.rpm | cpio -idv &> /dev/null

- 	popd &> /dev/null

- fi

+                 #get the latest uboot

+                 pushd $PREFIX &> /dev/null

+                 if [ $KOJI_TAG = f22 ]; then

+                         koji download-build --arch=armv7hl --latestfrom=$KOJI_TAG uboot-tools

+                 else

+                         koji download-build --arch=noarch --latestfrom=$KOJI_TAG uboot-tools

+                 fi

+                 # unpack uboot

+                 rpm2cpio uboot-images*.rpm | cpio -idv &> /dev/null

+                 popd &> /dev/null

+         fi

  fi

  # determine uboot and write to disk 

  if [ "$TARGET" = "" ]; then

@@ -111,3 +111,5 @@ 

  fi

  

  echo "= Complete!"

+ 

+ # vi: tabstop=8 softtabstop=0 expandtab shiftwidth=8 smarttab

All scripts set to 8 spaces, reindented. Sudo use in create-install-media handled as in arm-image-installer.

Pull-Request has been merged by pbrobinson

2 years ago