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"
}
SOURCE_PATH="`/bin/dirname \"$(readlink -f \"$0\")\"`"
SOURCE_PATH="$(/bin/dirname \"$(readlink -f \"$0\")\")"
INSTALL_PATH="$SOURCE_PATH/arm"
FILES_PATH="$SOURCE_PATH/files"
CMDNAME=`/bin/basename -z "$0"`
CMDNAME=$(/bin/basename -z "$0")
#while read -r;do
# for MAGEIA_VERSION in $REPLY
@ -70,7 +70,7 @@ function help()
echo "--target target system (for now rpi, xu3, xu4)"
echo "--config Path to config files"
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()
{
title "Cleaning"
if ! [ -z `mountpoint -qd "$BUILD_PATH/dev"` ];then
if ! [ -z "$(mountpoint -qd "$BUILD_PATH/dev")" ];then
info "Unmounting $BUILD_PATH/dev"
umount $BUILD_PATH/dev
umount "$BUILD_PATH/dev"
if ! [ $? -ne 0 ];then
error "line $LINENO can't unmount $BUILD_PATH/dev : exiting"
exit 1
fi
fi
if ! [ -z `mountpoint -qd "$BUILD_PATH/sys"` ];then
if ! [ -z "$(mountpoint -qd "$BUILD_PATH/sys")" ];then
info "Unmounting $BUILD_PATH/sys"
umount $BUILD_PATH/sys
umount "$BUILD_PATH/sys"
if ! [ $? -ne 0 ];then
error "line $LINENO can't unmount $BUILD_PATH/sys : exiting"
exit 1
fi
fi
if ! [ -z `mountpoint -qd "$BUILD_PATH/proc"` ];then
if ! [ -z "$(mountpoint -qd "$BUILD_PATH/proc")" ];then
info "Unmounting $BUILD_PATH/proc"
umount $BUILD_PATH/proc
umount "$BUILD_PATH/proc"
if ! [ $? -ne 0 ];then
error "line $LINENO can't unmount $BUILD_PATH/proc : exiting"
exit 1
@ -104,33 +104,33 @@ function clean()
fi
if [ -d "$BUILD_PATH" ];then
info "Removing $BUILD_PATH"
/bin/rm -Rf $BUILD_PATH
/bin/rm -Rf "$BUILD_PATH"
else
warning "$BUILD_PATH does not exists"
fi
if [ -e "$IMAGE" ];then
info "Removing "$IMAGE""
/bin/rm -f $INSTALL_PATH/$IMAGE
info "Removing $IMAGE"
/bin/rm -f "$INSTALL_PATH/$IMAGE"
else
warning "$IMAGE does not exists"
fi
for LOOP in ` ls /dev/loop*[0-9]p1`
for LOOP in $(ls /dev/loop*[0-9]p1)
do
X=${LOOP:0:10}
if [ -e $X ];then
if [ -e "$X" ];then
info "removing $X"
partx -d $X
partx -d "$X"
fi
done
if [ -d "$BOOT" ];then
info "Removing $BOOT"
/bin/rmdir $BOOT
/bin/rmdir "$BOOT"
else
warning "$BOOT does not exists"
fi
if [ -d "$ROOT" ];then
info "Removing $ROOT"
/bin/rmdir $ROOT
/bin/rmdir "$ROOT"
else
warning "$ROOT does not exists"
fi
@ -162,17 +162,17 @@ function createchroot()
fi
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
error "line $LINENO can't create $BUILD_PATH : exiting"
exit 1
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
error "line $LINENO can't copy /bin/qemu-user-static to $BUILD_PATH/usr/bin/ : exiting"
exit 1
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
error "line $LINENO can't copy /usr/lib/binfmt.d/qemu-arm-static.conf to $BUILD_PATH/usr/lib/binfmt.d : exiting"
exit 1
@ -182,14 +182,14 @@ function createchroot()
function addmedia()
{
title "Creating media $MIRROR"
/sbin/urpmi.addmedia --urpmi-root $BUILD_PATH --distrib "$MIRROR"
/sbin/urpmi.addmedia --urpmi-root "$BUILD_PATH" --distrib "$MIRROR"
err=$?
if [ $err -ne 0 ];then
error "line $LINENO error $err - can't add medias from $MIRROR : exiting"
exit 1
fi
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=$?
if [ $err -ne 0 ];then
error "line $LINENO error $err - can't activate medias : exiting"
@ -254,7 +254,7 @@ function jumpchroot()
fi
info "making /etc/hostname"
echo "$HOSTNAME" > "$BUILD_PATH"/etc/hostname
echo "$HOSTNAME" > "$BUILD_PATH/etc/hostname"
info "copying second stage script in $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
EOF
/sbin/useradd "$ID_USER"
/bin/passwd "$ID_USER" << EOF
"$PASSWORD"
"$PASSWORD"
/sbin/useradd $ID_USER
/bin/passwd $ID_USER << EOF
$PASSWORD
$PASSWORD
EOF" >>"$BUILD_PATH/second_stage_install.sh"
@ -312,7 +312,7 @@ EOF" >>"$BUILD_PATH/second_stage_install.sh"
function verify_disk_space()
{
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"
if [ $DISK_SPACE -lt $IMAGE_SIZE ];then
warning "image size is greater than disk space"
@ -327,10 +327,10 @@ function createxu3image()
{
title "Creating Odroid XU3-4 image"
createimage
if [ -z $BOOTFS ];then
if [ -z "$BOOTFS" ];then
BOOTFS="ext4"
fi
formatpartitions $BOOTFS ext4
formatpartitions "$BOOTFS" ext4
copyingsystem
}
@ -339,9 +339,9 @@ function createrpiimage()
{
title "Creating Pi image"
if ! [ -d $FIRMWARE_PATH/$FIRMWARE_DIR ];then # the firmware directory does not exists
echo `ls *.zip| wc -l`
if [ `ls *.zip| wc -l` -eq 0 ];then # the firmware archive does not exists
if ! [ -d "$FIRMWARE_PATH/$FIRMWARE_DIR" ];then # the firmware directory does not exists
echo "$(ls *.zip| wc -l)"
if [ "$(ls *.zip| wc -l)" -eq 0 ];then # the firmware archive does not exists
warning "The raspberry pi firmware need to be downloaded"
info "Downloading FIRMWARE_FILENAME"
wget $FIRMWARE_DOWNLOAD_URL
@ -387,8 +387,8 @@ createimage()
exit 1
fi
info "making partitions"
DEVICE=`/sbin/losetup -f --show "$INSTALL_PATH/$IMAGE"`
/sbin/fdisk $DEVICE << EOF
DEVICE=$(/sbin/losetup -f --show "$INSTALL_PATH/$IMAGE")
/sbin/fdisk "$DEVICE" << EOF
n
p
1
@ -404,32 +404,32 @@ p
w
EOF
/sbin/losetup -d $DEVICE
DEVICE=`/sbin/partx -va "$INSTALL_PATH/$IMAGE" | /bin/grep -m 1 -E -o '/dev/loop.?'`
/sbin/losetup -d "$DEVICE"
DEVICE=$(/sbin/partx -va "$INSTALL_PATH/$IMAGE" | /bin/grep -m 1 -E -o '/dev/loop.?')
info "device $DEVICE"
info "partitions list:"
info `/sbin/partx -v "$INSTALL_PATH/$IMAGE"`
BOOTP=${DEVICE}p1
BOOT_UUID=`blkid -o value uuid $BOOTP | head -n 1`
ROOTP=${DEVICE}p2
ROOT_UUID=`blkid -o value uuid $ROOTP | head -n 1`
info "$(/sbin/partx -v "$INSTALL_PATH/$IMAGE")"
BOOTP="${DEVICE}p1"
BOOT_UUID=$(blkid -o value uuid "$BOOTP" | head -n 1)
ROOTP="${DEVICE}p2"
ROOT_UUID=$(blkid -o value uuid "$ROOTP" | head -n 1)
}
formatpartitions()
{
info "Formatting partitions"
info "boot as $1"
/sbin/mkfs.$1 $BOOTP
"/sbin/mkfs.$1" "$BOOTP"
if [ $? -ne 0 ];then
error "line $LINENO error formating $BOOTP : exiting"
/sbin/losetup -d $DEVICE
/sbin/losetup -d "$DEVICE"
exit 1
fi
info "root as $2"
/sbin/mkfs.$2 $ROOTP
"/sbin/mkfs.$2" "$ROOTP"
if [ $? -ne 0 ];then
error "line $LINENO error formating $ROOTP : exiting"
/sbin/losetup -d $DEVICE
/sbin/losetup -d "$DEVICE"
exit 1
fi
}
@ -467,7 +467,7 @@ copyingsystem()
fi
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/"
info "making /etc/fstab"
@ -479,7 +479,7 @@ $ROOT_UUID / ext4 defaults 0 0" > "$BUILD_PATH"/e
rpi)
info "copying raspberry firmware in /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"
echo "vchiq
@ -489,8 +489,8 @@ brcmfmac
bcm2835-nrg" >> "$BUILD_PATH"/etc/modules
info "copying modprobe.conf"
/bin/cp -a $SOURCE_PATH/$CONFIG_PATH/modprobe.conf $BUILD_PATH/etc/
chown root:root $BUILD_PATH/etc/modprobe.conf
/bin/cp -a "$SOURCE_PATH/$CONFIG_PATH/modprobe.conf" "$BUILD_PATH/etc/"
chown root:root "$BUILD_PATH/etc/modprobe.conf"
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"
@ -536,7 +536,7 @@ fi
# 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
eval set -- "$TEMP"
@ -562,7 +562,7 @@ do
shift 2
;;
--build-path)
INSTALL_PATH=$2
INSTALL_PATH="$2"
shift 2
;;
--chroot)
@ -607,7 +607,7 @@ do
shift 2
;;
--config)
CONFIG_PATH=$2
CONFIG_PATH="$2"
shift 2
;;
--bootfs)
@ -631,7 +631,7 @@ BUILD_PATH="$INSTALL_PATH/build"
ARM_VERSION="armv7hl"
# 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"
CONFIG_PATH="$SOURCE_PATH/$TARGET"
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] "
read yn
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
/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"
exit 1
fi
else
warning "Config directory does not exists, do you want i make it and copy the template file in? [Y|n] "
read yn
if [ -z $yn || $yn = "Y" || $yn = "y" ];then
/usr/bin/mkdir $SOURCE_PATH/$CONFIG_PATH/
/usr/bin/cp $SOURCE_PATH/config.template "$SOURCE_PATH/$CONFIG_PATH/config.txt"
if [ -z $yn ] || [ $yn = "Y" ] || [ $yn = "y" ];then
/usr/bin/mkdir "$SOURCE_PATH/$CONFIG_PATH/"
/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"
exit
fi
@ -724,7 +724,7 @@ case $OPT in
all)
verify_disk_space
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
if [ $yn = "n" ];then
exit 6