1
0

-corrected syntax bugs

This commit is contained in:
Daniel Tartavel 2018-07-19 22:00:59 +02:00
parent 079d0cc6cb
commit 767830d06f

View File

@ -36,10 +36,10 @@ function error()
echo -e "\e[1;31m$1\e[0m" echo -e "\e[1;31m$1\e[0m"
} }
SOURCE_PATH="`/bin/dirname \"$(readlink -f \"$0\")\"`" SOURCE_PATH="$(/bin/dirname \"$(readlink -f \"$0\")\")"
INSTALL_PATH="$SOURCE_PATH/arm" INSTALL_PATH="$SOURCE_PATH/arm"
FILES_PATH="$SOURCE_PATH/files" FILES_PATH="$SOURCE_PATH/files"
CMDNAME=`/bin/basename -z "$0"` CMDNAME=$(/bin/basename -z "$0")
#while read -r;do #while read -r;do
# for MAGEIA_VERSION in $REPLY # for MAGEIA_VERSION in $REPLY
@ -70,7 +70,7 @@ function help()
echo "--target target system (for now rpi, xu3, xu4)" echo "--target target system (for now rpi, xu3, xu4)"
echo "--config Path to config files" echo "--config Path to config files"
echo "--bootfs filesystem of boot partition (ext4 or vfat) default: etx4" echo "--bootfs filesystem of boot partition (ext4 or vfat) default: etx4"
echo "\nFor image size, make sure it fit on physical support. (Default size is 7 Go)" echo -e "\nFor image size, make sure it fit on physical support. (Default size is 7 Go)"
} }
@ -78,25 +78,25 @@ function help()
function clean() function clean()
{ {
title "Cleaning" title "Cleaning"
if ! [ -z `mountpoint -qd "$BUILD_PATH/dev"` ];then if ! [ -z "$(mountpoint -qd "$BUILD_PATH/dev")" ];then
info "Unmounting $BUILD_PATH/dev" info "Unmounting $BUILD_PATH/dev"
umount $BUILD_PATH/dev umount "$BUILD_PATH/dev"
if ! [ $? -ne 0 ];then if ! [ $? -ne 0 ];then
error "line $LINENO can't unmount $BUILD_PATH/dev : exiting" error "line $LINENO can't unmount $BUILD_PATH/dev : exiting"
exit 1 exit 1
fi fi
fi fi
if ! [ -z `mountpoint -qd "$BUILD_PATH/sys"` ];then if ! [ -z "$(mountpoint -qd "$BUILD_PATH/sys")" ];then
info "Unmounting $BUILD_PATH/sys" info "Unmounting $BUILD_PATH/sys"
umount $BUILD_PATH/sys umount "$BUILD_PATH/sys"
if ! [ $? -ne 0 ];then if ! [ $? -ne 0 ];then
error "line $LINENO can't unmount $BUILD_PATH/sys : exiting" error "line $LINENO can't unmount $BUILD_PATH/sys : exiting"
exit 1 exit 1
fi fi
fi fi
if ! [ -z `mountpoint -qd "$BUILD_PATH/proc"` ];then if ! [ -z "$(mountpoint -qd "$BUILD_PATH/proc")" ];then
info "Unmounting $BUILD_PATH/proc" info "Unmounting $BUILD_PATH/proc"
umount $BUILD_PATH/proc umount "$BUILD_PATH/proc"
if ! [ $? -ne 0 ];then if ! [ $? -ne 0 ];then
error "line $LINENO can't unmount $BUILD_PATH/proc : exiting" error "line $LINENO can't unmount $BUILD_PATH/proc : exiting"
exit 1 exit 1
@ -104,33 +104,33 @@ function clean()
fi fi
if [ -d "$BUILD_PATH" ];then if [ -d "$BUILD_PATH" ];then
info "Removing $BUILD_PATH" info "Removing $BUILD_PATH"
/bin/rm -Rf $BUILD_PATH /bin/rm -Rf "$BUILD_PATH"
else else
warning "$BUILD_PATH does not exists" warning "$BUILD_PATH does not exists"
fi fi
if [ -e "$IMAGE" ];then if [ -e "$IMAGE" ];then
info "Removing "$IMAGE"" info "Removing $IMAGE"
/bin/rm -f $INSTALL_PATH/$IMAGE /bin/rm -f "$INSTALL_PATH/$IMAGE"
else else
warning "$IMAGE does not exists" warning "$IMAGE does not exists"
fi fi
for LOOP in ` ls /dev/loop*[0-9]p1` for LOOP in $(ls /dev/loop*[0-9]p1)
do do
X=${LOOP:0:10} X=${LOOP:0:10}
if [ -e $X ];then if [ -e "$X" ];then
info "removing $X" info "removing $X"
partx -d $X partx -d "$X"
fi fi
done done
if [ -d "$BOOT" ];then if [ -d "$BOOT" ];then
info "Removing $BOOT" info "Removing $BOOT"
/bin/rmdir $BOOT /bin/rmdir "$BOOT"
else else
warning "$BOOT does not exists" warning "$BOOT does not exists"
fi fi
if [ -d "$ROOT" ];then if [ -d "$ROOT" ];then
info "Removing $ROOT" info "Removing $ROOT"
/bin/rmdir $ROOT /bin/rmdir "$ROOT"
else else
warning "$ROOT does not exists" warning "$ROOT does not exists"
fi fi
@ -162,17 +162,17 @@ function createchroot()
fi fi
title "Creating $BUILD_PATH" title "Creating $BUILD_PATH"
/bin/mkdir -p $BUILD_PATH/usr/bin $BUILD_PATH/usr/lib/binfmt.d /bin/mkdir -p "$BUILD_PATH/usr/bin $BUILD_PATH/usr/lib/binfmt.d"
if [ $? -ne 0 ];then if [ $? -ne 0 ];then
error "line $LINENO can't create $BUILD_PATH : exiting" error "line $LINENO can't create $BUILD_PATH : exiting"
exit 1 exit 1
fi fi
/bin/cp /bin/qemu-arm-static $BUILD_PATH/usr/bin/ /bin/cp /bin/qemu-arm-static "$BUILD_PATH/usr/bin/"
if [ $? -ne 0 ];then if [ $? -ne 0 ];then
error "line $LINENO can't copy /bin/qemu-user-static to $BUILD_PATH/usr/bin/ : exiting" error "line $LINENO can't copy /bin/qemu-user-static to $BUILD_PATH/usr/bin/ : exiting"
exit 1 exit 1
fi fi
/bin/cp /usr/lib/binfmt.d/qemu-arm-static.conf $BUILD_PATH/usr/lib/binfmt.d /bin/cp /usr/lib/binfmt.d/qemu-arm-static.conf "$BUILD_PATH/usr/lib/binfmt.d"
if [ $? -ne 0 ];then if [ $? -ne 0 ];then
error "line $LINENO can't copy /usr/lib/binfmt.d/qemu-arm-static.conf to $BUILD_PATH/usr/lib/binfmt.d : exiting" error "line $LINENO can't copy /usr/lib/binfmt.d/qemu-arm-static.conf to $BUILD_PATH/usr/lib/binfmt.d : exiting"
exit 1 exit 1
@ -182,14 +182,14 @@ function createchroot()
function addmedia() function addmedia()
{ {
title "Creating media $MIRROR" title "Creating media $MIRROR"
/sbin/urpmi.addmedia --urpmi-root $BUILD_PATH --distrib "$MIRROR" /sbin/urpmi.addmedia --urpmi-root "$BUILD_PATH" --distrib "$MIRROR"
err=$? err=$?
if [ $err -ne 0 ];then if [ $err -ne 0 ];then
error "line $LINENO error $err - can't add medias from $MIRROR : exiting" error "line $LINENO error $err - can't add medias from $MIRROR : exiting"
exit 1 exit 1
fi fi
title "activating non-free and tainted" title "activating non-free and tainted"
/sbin/urpmi.update --urpmi-root $BUILD_PATH --no-ignore Nonfree\ Release Nonfree\ Updates Tainted\ Release Tainted\ Updates /sbin/urpmi.update --urpmi-root "$BUILD_PATH" --no-ignore Nonfree\ Release Nonfree\ Updates Tainted\ Release Tainted\ Updates
err=$? err=$?
if [ $err -ne 0 ];then if [ $err -ne 0 ];then
error "line $LINENO error $err - can't activate medias : exiting" error "line $LINENO error $err - can't activate medias : exiting"
@ -254,7 +254,7 @@ function jumpchroot()
fi fi
info "making /etc/hostname" info "making /etc/hostname"
echo "$HOSTNAME" > "$BUILD_PATH"/etc/hostname echo "$HOSTNAME" > "$BUILD_PATH/etc/hostname"
info "copying second stage script in $BUILD_PATH" info "copying second stage script in $BUILD_PATH"
echo "/bin/cp $SOURCE_PATH/$CONFIG_PATH/second_stage_install.sh $BUILD_PATH/" echo "/bin/cp $SOURCE_PATH/$CONFIG_PATH/second_stage_install.sh $BUILD_PATH/"
@ -277,10 +277,10 @@ function jumpchroot()
$ROOT_PWD $ROOT_PWD
$ROOT_PWD $ROOT_PWD
EOF EOF
/sbin/useradd "$ID_USER" /sbin/useradd $ID_USER
/bin/passwd "$ID_USER" << EOF /bin/passwd $ID_USER << EOF
"$PASSWORD" $PASSWORD
"$PASSWORD" $PASSWORD
EOF" >>"$BUILD_PATH/second_stage_install.sh" EOF" >>"$BUILD_PATH/second_stage_install.sh"
@ -312,7 +312,7 @@ EOF" >>"$BUILD_PATH/second_stage_install.sh"
function verify_disk_space() function verify_disk_space()
{ {
title "Verifying if there is enough space on disk to make the image" title "Verifying if there is enough space on disk to make the image"
DISK_SPACE=`/usr/bin/df -BG --output=avail $INSTALL_PATH | sed '1d;s/[^0-9]//g'` DISK_SPACE=$(/usr/bin/df -BG --output=avail "$INSTALL_PATH" | sed '1d;s/[^0-9]//g')
info "Free disk space: ${DISK_SPACE}G" info "Free disk space: ${DISK_SPACE}G"
if [ $DISK_SPACE -lt $IMAGE_SIZE ];then if [ $DISK_SPACE -lt $IMAGE_SIZE ];then
warning "image size is greater than disk space" warning "image size is greater than disk space"
@ -327,10 +327,10 @@ function createxu3image()
{ {
title "Creating Odroid XU3-4 image" title "Creating Odroid XU3-4 image"
createimage createimage
if [ -z $BOOTFS ];then if [ -z "$BOOTFS" ];then
BOOTFS="ext4" BOOTFS="ext4"
fi fi
formatpartitions $BOOTFS ext4 formatpartitions "$BOOTFS" ext4
copyingsystem copyingsystem
} }
@ -339,9 +339,9 @@ function createrpiimage()
{ {
title "Creating Pi image" title "Creating Pi image"
if ! [ -d $FIRMWARE_PATH/$FIRMWARE_DIR ];then # the firmware directory does not exists if ! [ -d "$FIRMWARE_PATH/$FIRMWARE_DIR" ];then # the firmware directory does not exists
echo `ls *.zip| wc -l` echo "$(ls *.zip| wc -l)"
if [ `ls *.zip| wc -l` -eq 0 ];then # the firmware archive does not exists if [ "$(ls *.zip| wc -l)" -eq 0 ];then # the firmware archive does not exists
warning "The raspberry pi firmware need to be downloaded" warning "The raspberry pi firmware need to be downloaded"
info "Downloading FIRMWARE_FILENAME" info "Downloading FIRMWARE_FILENAME"
wget $FIRMWARE_DOWNLOAD_URL wget $FIRMWARE_DOWNLOAD_URL
@ -387,8 +387,8 @@ createimage()
exit 1 exit 1
fi fi
info "making partitions" info "making partitions"
DEVICE=`/sbin/losetup -f --show "$INSTALL_PATH/$IMAGE"` DEVICE=$(/sbin/losetup -f --show "$INSTALL_PATH/$IMAGE")
/sbin/fdisk $DEVICE << EOF /sbin/fdisk "$DEVICE" << EOF
n n
p p
1 1
@ -404,32 +404,32 @@ p
w w
EOF EOF
/sbin/losetup -d $DEVICE /sbin/losetup -d "$DEVICE"
DEVICE=`/sbin/partx -va "$INSTALL_PATH/$IMAGE" | /bin/grep -m 1 -E -o '/dev/loop.?'` DEVICE=$(/sbin/partx -va "$INSTALL_PATH/$IMAGE" | /bin/grep -m 1 -E -o '/dev/loop.?')
info "device $DEVICE" info "device $DEVICE"
info "partitions list:" info "partitions list:"
info `/sbin/partx -v "$INSTALL_PATH/$IMAGE"` info "$(/sbin/partx -v "$INSTALL_PATH/$IMAGE")"
BOOTP=${DEVICE}p1 BOOTP="${DEVICE}p1"
BOOT_UUID=`blkid -o value uuid $BOOTP | head -n 1` BOOT_UUID=$(blkid -o value uuid "$BOOTP" | head -n 1)
ROOTP=${DEVICE}p2 ROOTP="${DEVICE}p2"
ROOT_UUID=`blkid -o value uuid $ROOTP | head -n 1` ROOT_UUID=$(blkid -o value uuid "$ROOTP" | head -n 1)
} }
formatpartitions() formatpartitions()
{ {
info "Formatting partitions" info "Formatting partitions"
info "boot as $1" info "boot as $1"
/sbin/mkfs.$1 $BOOTP "/sbin/mkfs.$1" "$BOOTP"
if [ $? -ne 0 ];then if [ $? -ne 0 ];then
error "line $LINENO error formating $BOOTP : exiting" error "line $LINENO error formating $BOOTP : exiting"
/sbin/losetup -d $DEVICE /sbin/losetup -d "$DEVICE"
exit 1 exit 1
fi fi
info "root as $2" info "root as $2"
/sbin/mkfs.$2 $ROOTP "/sbin/mkfs.$2" "$ROOTP"
if [ $? -ne 0 ];then if [ $? -ne 0 ];then
error "line $LINENO error formating $ROOTP : exiting" error "line $LINENO error formating $ROOTP : exiting"
/sbin/losetup -d $DEVICE /sbin/losetup -d "$DEVICE"
exit 1 exit 1
fi fi
} }
@ -467,7 +467,7 @@ copyingsystem()
fi fi
info "copying Mageia image to root parition" info "copying Mageia image to root parition"
#/bin/rsync -a --exclude boot/ --exclude "qemu-arm-static*" "$BUILD_PATH/" "$ROOT/" /bin/rsync -a --exclude boot/ --exclude "qemu-arm-static*" "$BUILD_PATH/" "$ROOT/"
/bin/rsync -a "$BUILD_PATH/boot/" "$BOOT/" /bin/rsync -a "$BUILD_PATH/boot/" "$BOOT/"
info "making /etc/fstab" info "making /etc/fstab"
@ -479,7 +479,7 @@ $ROOT_UUID / ext4 defaults 0 0" > "$BUILD_PATH"/e
rpi) rpi)
info "copying raspberry firmware in /boot" info "copying raspberry firmware in /boot"
/bin/rsync -rlptDH "$FIRMWARE_PATH/firmware-stable/boot/" "$BOOT" /bin/rsync -rlptDH "$FIRMWARE_PATH/firmware-stable/boot/" "$BOOT"
cp -a $FIRMWARE_PATH/firmware-stable/extra/uname_string* $BOOT cp -a "$FIRMWARE_PATH/firmware-stable/extra/uname_string*" "$BOOT"
info "adding modules in /etc/modules" info "adding modules in /etc/modules"
echo "vchiq echo "vchiq
@ -489,8 +489,8 @@ brcmfmac
bcm2835-nrg" >> "$BUILD_PATH"/etc/modules bcm2835-nrg" >> "$BUILD_PATH"/etc/modules
info "copying modprobe.conf" info "copying modprobe.conf"
/bin/cp -a $SOURCE_PATH/$CONFIG_PATH/modprobe.conf $BUILD_PATH/etc/ /bin/cp -a "$SOURCE_PATH/$CONFIG_PATH/modprobe.conf" "$BUILD_PATH/etc/"
chown root:root $BUILD_PATH/etc/modprobe.conf chown root:root "$BUILD_PATH/etc/modprobe.conf"
info "making /boot/cmdline.txt" info "making /boot/cmdline.txt"
echo "dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait" > "$BOOT/cmdline.txt" echo "dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait" > "$BOOT/cmdline.txt"
@ -536,7 +536,7 @@ fi
# parsing commandline # parsing commandline
TEMP=`getopt -o h,a --long all,help,clean,create-chroot,addmedia,create-image,,config:,target:,chroot,bootfs:,install-basesystem,update-mirror,build-path:,size: -n $CMDNAME -- "$@"` TEMP=$(getopt -o h,a --long all,help,clean,create-chroot,addmedia,create-image,,config:,target:,chroot,bootfs:,install-basesystem,update-mirror,build-path:,size: -n $CMDNAME -- "$@")
if [ $? -ne 0 ] ; then error "line $LINENO Failed parsing options." >&2 ; exit 1 ; fi if [ $? -ne 0 ] ; then error "line $LINENO Failed parsing options." >&2 ; exit 1 ; fi
eval set -- "$TEMP" eval set -- "$TEMP"
@ -562,7 +562,7 @@ do
shift 2 shift 2
;; ;;
--build-path) --build-path)
INSTALL_PATH=$2 INSTALL_PATH="$2"
shift 2 shift 2
;; ;;
--chroot) --chroot)
@ -607,7 +607,7 @@ do
shift 2 shift 2
;; ;;
--config) --config)
CONFIG_PATH=$2 CONFIG_PATH="$2"
shift 2 shift 2
;; ;;
--bootfs) --bootfs)
@ -631,7 +631,7 @@ BUILD_PATH="$INSTALL_PATH/build"
ARM_VERSION="armv7hl" ARM_VERSION="armv7hl"
# path of config file # path of config file
if [ -z $SOURCE_PATH/$CONFIG_PATH ];then if ! [ -d "$SOURCE_PATH/$CONFIG_PATH" ];then
info " Config path do not exists, defaulting to ./$TARGET" info " Config path do not exists, defaulting to ./$TARGET"
CONFIG_PATH="$SOURCE_PATH/$TARGET" CONFIG_PATH="$SOURCE_PATH/$TARGET"
fi fi
@ -644,18 +644,18 @@ if [ -d "$SOURCE_PATH/$CONFIG_PATH" ];then
warning "Config file does not exists, do you want i copy template ? [Y|n] " warning "Config file does not exists, do you want i copy template ? [Y|n] "
read yn read yn
if [ -z $yn ] || [ $yn = "Y" ] || [ $yn = "y" ];then if [ -z $yn ] || [ $yn = "Y" ] || [ $yn = "y" ];then
/usr/bin/cp $SOURCE_PATH/config.template "$SOURCE_PATH/$CONFIG_PATH/config.txt" /usr/bin/cp "$SOURCE_PATH/config.template" "$SOURCE_PATH/$CONFIG_PATH/config.txt"
fi fi
/usr/bin/cp $SOURCE_PATH/config.template "$SOURCE_PATH/$CONFIG_PATH/config.txt" /usr/bin/cp "$SOURCE_PATH/config.template" "$SOURCE_PATH/$CONFIG_PATH/config.txt"
warning "You need now to modify the config file ($SOURCE_PATH/$CONFIG_PATH/config.txt) and relaunch the script" warning "You need now to modify the config file ($SOURCE_PATH/$CONFIG_PATH/config.txt) and relaunch the script"
exit 1 exit 1
fi fi
else else
warning "Config directory does not exists, do you want i make it and copy the template file in? [Y|n] " warning "Config directory does not exists, do you want i make it and copy the template file in? [Y|n] "
read yn read yn
if [ -z $yn || $yn = "Y" || $yn = "y" ];then if [ -z $yn ] || [ $yn = "Y" ] || [ $yn = "y" ];then
/usr/bin/mkdir $SOURCE_PATH/$CONFIG_PATH/ /usr/bin/mkdir "$SOURCE_PATH/$CONFIG_PATH/"
/usr/bin/cp $SOURCE_PATH/config.template "$SOURCE_PATH/$CONFIG_PATH/config.txt" /usr/bin/cp "$SOURCE_PATH/config.template" "$SOURCE_PATH/$CONFIG_PATH/config.txt"
warning "You need now to modify the config file ($SOURCE_PATH/$CONFIG_PATH/config.txt) and relaunch the script" warning "You need now to modify the config file ($SOURCE_PATH/$CONFIG_PATH/config.txt) and relaunch the script"
exit exit
fi fi
@ -724,7 +724,7 @@ case $OPT in
all) all)
verify_disk_space verify_disk_space
if [ $? -eq 1 ];then if [ $? -eq 1 ];then
echo "Not enough space on disk\nDo you want to continue anyway ? [Y,n]" echo -e "Not enough space on disk\nDo you want to continue anyway ? [Y,n]"
read yn read yn
if [ $yn = "n" ];then if [ $yn = "n" ];then
exit 6 exit 6