Quote variables containing pathes

Fixes #24
parent 27be6d27
......@@ -8,49 +8,49 @@
function convert_rootfs_to_img() {
image_size=$1
qemu-img create -f raw $IMAGE_DIR/rootfs.img $image_size
sudo mkfs.ext4 -O ^metadata_csum -O ^64bit -F $IMAGE_DIR/rootfs.img
sudo mount $IMAGE_DIR/rootfs.img $ROOTFS_DIR
sudo tar --numeric-owner -xpf $ROOTFS_TAR -C $ROOTFS_DIR
qemu-img create -f raw "$IMAGE_DIR/rootfs.img" $image_size
sudo mkfs.ext4 -O ^metadata_csum -O ^64bit -F "$IMAGE_DIR/rootfs.img"
sudo mount "$IMAGE_DIR/rootfs.img" "$ROOTFS_DIR"
sudo tar --numeric-owner -xpf "$ROOTFS_TAR" -C "$ROOTFS_DIR"
}
function convert_rootfs_to_dir() {
sudo tar --numeric-owner -xpf $ROOTFS_TAR -C $ROOTFS_DIR
sudo tar --numeric-owner -xpf "$ROOTFS_TAR" -C "$ROOTFS_DIR"
}
function convert_androidimage() {
if file $AND_IMAGE | grep "ext[2-4] filesystem"; then
cp $AND_IMAGE $IMAGE_DIR/system.img
if file "$AND_IMAGE" | grep "ext[2-4] filesystem"; then
cp "$AND_IMAGE" "$IMAGE_DIR/system.img"
else
simg2img $AND_IMAGE $IMAGE_DIR/system.img
simg2img "$AND_IMAGE" "$IMAGE_DIR/system.img"
fi
}
function shrink_images() {
[ -f $IMAGE_DIR/system.img ] && sudo e2fsck -fy $IMAGE_DIR/system.img >/dev/null
[ -f $IMAGE_DIR/system.img ] && sudo resize2fs -p -M $IMAGE_DIR/system.img
[ -f "$IMAGE_DIR/system.img" ] && sudo e2fsck -fy "$IMAGE_DIR/system.img" >/dev/null
[ -f "$IMAGE_DIR/system.img" ] && sudo resize2fs -p -M "$IMAGE_DIR/system.img"
}
function inject_androidimage() {
sudo mv $IMAGE_DIR/system.img $ROOTFS_DIR
sudo mv "$IMAGE_DIR/system.img" "$ROOTFS_DIR"
}
function unmount() {
sudo umount $ROOTFS_DIR
sudo umount "$ROOTFS_DIR"
}
function flash_img() {
adb push $IMAGE_DIR/rootfs.img /data/
adb push $IMAGE_DIR/system.img /data/
adb push "$IMAGE_DIR/rootfs.img" /data/
adb push "$IMAGE_DIR/system.img" /data/
}
function flash_dir() {
adb push $ROOTFS_DIR/* /data/halium-rootfs/
adb push "$ROOTFS_DIR"/* /data/halium-rootfs/
}
function clean() {
# Delete created files from last install
sudo rm $ROOTFS_DIR $IMAGE_DIR -rf
sudo rm "$ROOTFS_DIR" "$IMAGE_DIR" -rf
}
function clean_device() {
......
......@@ -31,39 +31,39 @@ function setup_passwd() {
pass=$2
if [ -z "$pass" ] ; then
echo "Please enter a new password for the user '$user':"
do_until_success sudo chroot $ROOTFS_DIR passwd $user
do_until_success sudo chroot "$ROOTFS_DIR" passwd $user
else
echo "I: Setting new password for the user '$user'"
echo $user:$pass | sudo chroot $ROOTFS_DIR chpasswd
echo $user:$pass | sudo chroot "$ROOTFS_DIR" chpasswd
fi
}
function chroot_run() {
sudo PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" DEBIAN_FRONTEND=noninteractive LANG=C RUNLEVEL=1 chroot $ROOTFS_DIR /bin/bash -c "$@"
sudo PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" DEBIAN_FRONTEND=noninteractive LANG=C RUNLEVEL=1 chroot "$ROOTFS_DIR" /bin/bash -c "$@"
}
function copy_ssh_key_root() {
if $DO_COPY_SSH_KEY ; then
D=$ROOTFS_DIR/root/.ssh
D="$ROOTFS_DIR/root/.ssh"
echo "I: Copying ssh key to the user 'root'"
sudo mkdir $D
sudo tee -a $D/authorized_keys < $SSH_KEY >/dev/null
sudo chmod 0700 $D
sudo chmod 0600 $D/authorized_keys
sudo mkdir "$D"
sudo tee -a "$D/authorized_key"s < $SSH_KEY >/dev/null
sudo chmod 0700 "$D"
sudo chmod 0600 "$D/authorized_keys"
fi
}
function copy_ssh_key_phablet() {
if $DO_COPY_SSH_KEY ; then
D=$ROOTFS_DIR/home/phablet/.ssh
D="$ROOTFS_DIR/home/phablet/.ssh"
echo "I: Copying ssh key to the user 'phablet'"
sudo mkdir $D
sudo tee -a $D/authorized_keys < $SSH_KEY >/dev/null
sudo chown -R 32011:32011 $D
sudo chmod 0700 $D
sudo chmod 0600 $D/authorized_keys
sudo mkdir "$D"
sudo tee -a "$D/authorized_keys" < $SSH_KEY >/dev/null
sudo chown -R 32011:32011 "$D"
sudo chmod 0700 "$D"
sudo chmod 0600 "$D/authorized_keys"
fi
}
......@@ -80,8 +80,8 @@ function post_install() {
*) qemu="qemu-arm-static" ;;
esac
sudo cp $(command -v $qemu) $ROOTFS_DIR/usr/bin
sudo cp /etc/resolv.conf $ROOTFS_DIR/etc/
sudo cp $(command -v $qemu) "$ROOTFS_DIR/usr/bin"
sudo cp /etc/resolv.conf "$ROOTFS_DIR/etc/"
case "$1" in
halium | debian-pm | reference)
setup_passwd root $ROOTPASSWORD
......@@ -92,7 +92,7 @@ function post_install() {
copy_ssh_key_phablet
fi
sudo rm -f $ROOTFS_DIR/etc/dropbear/dropbear_{dss,ecdsa,rsa}_host_key
sudo rm -f "$ROOTFS_DIR"/etc/dropbear/dropbear_{dss,ecdsa,rsa}_host_key
chroot_run "dpkg-reconfigure dropbear-run"
;;
debian-pm-caf)
......@@ -104,7 +104,7 @@ function post_install() {
copy_ssh_key_phablet
fi
sudo rm -f $ROOTFS_DIR/etc/dropbear/dropbear_{dss,ecdsa,rsa}_host_key
sudo rm -f "$ROOTFS_DIR"/etc/dropbear/dropbear_{dss,ecdsa,rsa}_host_key
chroot_run "dpkg-reconfigure dropbear-run"
echo "Adding repository for libhybris platform caf"
......@@ -126,30 +126,30 @@ function post_install() {
ut)
# Adapted from rootstock-ng
echo -n "enabling Mir ... "
sudo touch $ROOTFS_DIR/home/phablet/.display-mir
sudo touch "$ROOTFS_DIR/home/phablet/.display-mir"
echo "[done]"
echo -n "enabling SSH ... "
sudo sed -i 's/PasswordAuthentication=no/PasswordAuthentication=yes/g' $ROOTFS_DIR/etc/init/ssh.override
sudo sed -i 's/manual/start on startup/g' $ROOTFS_DIR/etc/init/ssh.override
sudo sed -i 's/manual/start on startup/g' $ROOTFS_DIR/etc/init/usb-tethering.conf
sudo sed -i 's/PasswordAuthentication=no/PasswordAuthentication=yes/g' "$ROOTFS_DIR/etc/init/ssh.override"
sudo sed -i 's/manual/start on startup/g' "$ROOTFS_DIR/etc/init/ssh.override"
sudo sed -i 's/manual/start on startup/g' "$ROOTFS_DIR/etc/init/usb-tethering.conf"
echo "[done]"
setup_passwd phablet $USERPASSWORD
copy_ssh_key_phablet
sudo mkdir -p $ROOTFS_DIR/android/firmware
sudo mkdir -p $ROOTFS_DIR/android/persist
sudo mkdir -p $ROOTFS_DIR/userdata
sudo mkdir -p "$ROOTFS_DIR/android/firmware"
sudo mkdir -p "$ROOTFS_DIR/android/persist"
sudo mkdir -p "$ROOTFS_DIR/userdata"
for link in cache data factory firmware persist system odm; do
sudo ln -s /android/$link $ROOTFS_DIR/$link
sudo ln -s /android/$link "$ROOTFS_DIR/$link"
done
sudo ln -s /system/lib/modules $ROOTFS_DIR/lib/modules
sudo ln -s /android/system/vendor $ROOTFS_DIR/vendor
[ -e rootfs/etc/mtab ] && sudo rm $ROOTFS_DIR/etc/mtab
sudo ln -s /proc/mounts $ROOTFS_DIR/etc/mtab
sudo ln -s /system/lib/modules "$ROOTFS_DIR/lib/modules"
sudo ln -s /android/system/vendor "$ROOTFS_DIR/vendor"
[ -e rootfs/etc/mtab ] && sudo rm "$ROOTFS_DIR/etc/mtab"
sudo ln -s /proc/mounts "$ROOTFS_DIR/etc/mtab"
;;
esac
sudo rm $ROOTFS_DIR/usr/bin/$qemu
sudo rm "$ROOTFS_DIR/usr/bin/$qemu"
}
......@@ -27,7 +27,7 @@ function quiet () {
out=quiet
# Include functions
source $LOCATION/functions/misc.sh
source "$LOCATION/functions/misc.sh"
# parse options
while [ -n "$1" ] ; do
......@@ -83,9 +83,9 @@ if [ "$#" -lt 2 ] || [ "$#" -gt 3 ]; then
exit
fi
export ROOTFS_TAR=$1
export AND_IMAGE=$2
if [ ! -f $ROOTFS_TAR ] || [ ! -f $AND_IMAGE ]; then
export ROOTFS_TAR="$1"
export AND_IMAGE="$2"
if [ ! -f "$ROOTFS_TAR" ] || [ ! -f "$AND_IMAGE" ]; then
usage
exit
fi
......@@ -99,8 +99,8 @@ export ROOTFS_DIR=$(mktemp -d .halium-install-rootfs.XXXXX)
export IMAGE_DIR=$(mktemp -d .halium-install-imgs.XXXXX)
# Logic that depends on the opts being parsed
source $LOCATION/functions/distributions.sh
source $LOCATION/functions/core.sh
source "$LOCATION/functions/distributions.sh"
source "$LOCATION/functions/core.sh"
# Always enforce cleanup on exit
trap clean_exit EXIT
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment