Skip to content

Commit

Permalink
Fix lots of shellchecks. Fix unsupported cpu
Browse files Browse the repository at this point in the history
  • Loading branch information
luigi311 committed Dec 6, 2022
1 parent cbffe1e commit 0008ec5
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 58 deletions.
1 change: 1 addition & 0 deletions .shellcheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
external-sources=true
2 changes: 2 additions & 0 deletions scripts/caches.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

function createCaches {
mkdir -p "$IMG_CACHE"
}
Expand Down
17 changes: 8 additions & 9 deletions scripts/images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function initImageVars {
QEMU="$SNAP/usr/bin/qemu-system-x86_64"
fi
QEMU_ARGS="\
-cpu Haswell-v4 \
-cpu host \
-netdev user,id=ethernet.0,hostfwd=tcp:127.0.0.1:5555-:5555 \
-device rtl8139,netdev=ethernet.0 \
-device AC97 \
Expand All @@ -38,8 +38,8 @@ function initImageVars {
QEMU_ARGS="-device virtio-keyboard-pci -device virtio-mouse-pci $QEMU_ARGS"
elif [ "$(uname -s)" == "Darwin" ]; then
if [ "$ARCH" == "arm64" ]; then
EFI_1="$(dirname $(which qemu-img))/../share/qemu/edk2-aarch64-code.fd"
EFI_2="$(dirname $(which qemu-img))/../share/qemu/edk2-arm-vars.fd"
EFI_1="$(dirname "$(which qemu-img)")/../share/qemu/edk2-aarch64-code.fd"
EFI_2="$(dirname "$(which qemu-img)")/../share/qemu/edk2-arm-vars.fd"
QEMU=qemu-system-aarch64
QEMU_ARGS="\
-cpu cortex-a72 \
Expand All @@ -54,7 +54,7 @@ function initImageVars {
else
QEMU=qemu-system-x86_64
QEMU_ARGS="\
-cpu Haswell-v4 \
-cpu host \
-device intel-hda -device hda-output \
-device virtio-gpu-gl-pci \
-device virtio-keyboard-pci \
Expand All @@ -67,8 +67,6 @@ function initImageVars {

if [ "$HOST_ARCH" == "$ARCH" ]; then
QEMU_ARGS="-machine virt,accel=hvf,highmem=off $QEMU_ARGS"
else
QEMU_ARGS="$QEMU_ARGS"
fi
fi
}
Expand All @@ -94,6 +92,7 @@ function pullLatestImage {
}

function runImage {
# shellcheck source=/dev/null
source "$IMG_CACHE/$NAME/info.sh"

EFI_ARGS=""
Expand Down Expand Up @@ -125,7 +124,7 @@ function listImages {
echo ""

CACHE_IMAGES=$(ls "$IMG_CACHE")
if [ "$CACHE_IMAGES" == "" ]; then
if [ -z "$CACHE_IMAGES" ]; then
echo "No images found"
return 0
fi
Expand All @@ -136,9 +135,9 @@ function listImages {
continue;
fi
if [ -f "$IMG_CACHE/$i/info.sh" ]; then
IMG_ARCH=$(cat "$IMG_CACHE/$i/info.sh" | awk -F"=" '{ print $2 }')
IMG_ARCH=$(awk -F"=" '{ print $2 }' < "$IMG_CACHE/$i/info.sh")
fi
if [ "$IMG_ARCH" == "" ]; then
if [ -z "$IMG_ARCH" ]; then
IMG_ARCH="$ARCH"
fi
printf "\t- %s (%s)\n" "$i" "$IMG_ARCH"
Expand Down
2 changes: 2 additions & 0 deletions scripts/mounts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,7 @@ function startVirtiofsd {
while [ ! -e "$VIRTIOFS_SOCK" ]; do
sleep 0.1
done

# shellcheck disable=SC2034 # Variable used externally by other scripts
VIRTIOFS_ACTIVE=1
}
17 changes: 9 additions & 8 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ function warnMissingData {
echo "This directory will contain your VM images and source code."

while [ "$IS_VALID" == "0" ]; do
printf "Path ($DEFAULT_DATA_ROOT): "
read NEW_DATA_ROOT
printf "Path (%s): " "$DEFAULT_DATA_ROOT"
read -r NEW_DATA_ROOT

if [[ -z $NEW_DATA_ROOT ]]; then
NEW_DATA_ROOT="$DEFAULT_DATA_ROOT"
fi

NEW_DATA_ROOT="$(realpath $NEW_DATA_ROOT)"
NEW_DATA_ROOT=$(realpath "$NEW_DATA_ROOT")
if [ -d "$NEW_DATA_ROOT" ]; then
IS_VALID=1
continue;
else
read -p "Path does not exist, do you want create it? [Y/n]" yn
read -r -p "Path does not exist, do you want create it? [Y/n]" yn
case $yn in
[Nn]* ) ;;
* ) mkdir -p "$NEW_DATA_ROOT"; break;;
Expand All @@ -75,6 +75,7 @@ function warnMissingData {
echo "DATA_ROOT=$NEW_DATA_ROOT" > "$CONFIG_ROOT/config.sh"
echo "SRC_ROOT=$NEW_DATA_ROOT/sources" >> "$CONFIG_ROOT/config.sh"
echo "USER=$USER" >> "$CONFIG_ROOT/config.sh"
# shellcheck source=/dev/null
source "$CONFIG_ROOT/config.sh"
}

Expand Down Expand Up @@ -105,7 +106,7 @@ function checkSsh {
if [ "$IS_INSTALLED" -ne 1 ]; then
echo "WARNING: The OpenSSH server seems to be missing or not activated, please install it using your package manager."
while true; do
read -p "Would you like to do that automatically now [y/n]? " yn
read -r -p "Would you like to do that automatically now [y/n]? " yn
case $yn in
[Yy]* ) tryInstallSshd; break;;
[Nn]* ) break;;
Expand All @@ -118,7 +119,7 @@ function checkSsh {
if [ "$OUTPUT" != "Remote Login: On" ]; then
echo "WARNING: SSH doesn't seem to be enabled!"
while true; do
read -p "Would you like to enable it now [y/n]? " yn
read -r -p "Would you like to enable it now [y/n]? " yn
case $yn in
[Yy]* ) tryInstallSshd; break;;
[Nn]* ) break;;
Expand All @@ -130,7 +131,7 @@ function checkSsh {
}

function setup {
bash $SCRIPTPATH/scripts/prerequisites.sh
bash "$SCRIPTPATH/scripts/prerequisites.sh"
warnMissingPlugs
warnMissingData

Expand Down Expand Up @@ -166,7 +167,7 @@ function setup {
chmod 700 "$HOME/.ssh"
fi
echo "Inserting ssh key into authorized keys list"
echo "$PUBKEY_CONTENTS" >> $HOME/.ssh/authorized_keys
echo "$PUBKEY_CONTENTS" >> "$HOME/.ssh/authorized_keys"
fi
fi
}
3 changes: 3 additions & 0 deletions scripts/vars.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env bash
# shellcheck disable=SC2034 # Variables used externally by other scripts

CODENAME=Archangel
VERSION=0.0.0-rc0

Expand Down
3 changes: 2 additions & 1 deletion snap/local/runner
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# set pulse when using old -soundhw option
if echo "$@" |grep -q soundhw; then
export QEMU_AUDIO_DRV="pa"
export QEMU_PA_SERVER="/run/user/$(id -u)/pulse/native"
QEMU_PA_SERVER="/run/user/$(id -u)/pulse/native"
export QEMU_PA_SERVER
fi

exec "$@"
76 changes: 36 additions & 40 deletions ubuntu-touch-pdk
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ TMPDIR=""
trap ctrl_c INT

function ctrl_c {
echo "CTRL-C received"
for JOB in `jobs -p`; do
kill -9 $JOB
printf "\n\nCTRL-C received\n"
for JOB in $(jobs -p); do
kill -9 "$JOB"
done
exit 1
}
Expand All @@ -32,14 +32,12 @@ NAME=default
ARCH="$HOST_ARCH"

function printHelp {
echo "usage: $0 <options> <command> [<command> ..]"
echo ""
echo "Options:"
printf "\t-a=|--arch=: Architecture override (optional, defaults to '$HOST_ARCH')\n"
printf "usage: %s <options> <command> [<command> ..]\n\n" "$0"
printf "Options:\n"
printf "\t-a=|--arch=: Architecture override (optional, defaults to '%s')\n" "$HOST_ARCH"
printf "\t Possible values: arm64, amd64\n"
printf "\t-n=|--name=: Name of the image (optional, defaults to 'default')\n"
echo ""
echo "Commands:"
printf "\t-n=|--name=: Name of the image (optional, defaults to 'default')\n\n"
printf "Commands:\n"
printf "\tsetup: Host OS preparations (recommended for first-time use)\n"
printf "\tclear: Clean up all images\n"
printf "\tpull: Download pre-generated image\n"
Expand Down Expand Up @@ -100,48 +98,48 @@ while [[ $# -gt 0 ]]; do
done

# Read common script variables
source $SCRIPTPATH/scripts/vars.sh
source "$SCRIPTPATH/scripts/vars.sh"
initCommonVars
mkdir -p "$CONFIG_ROOT"

# Source the config if available
if [ -f "$CONFIG_ROOT/config.sh" ]; then
# shellcheck source=/dev/null
source "$CONFIG_ROOT/config.sh"
IMG_CACHE="$DATA_ROOT/pdk-image-cache"
fi

if [ "$PRINT_VERSION" == "yes" ]; then
echo "$VERSION ($CODENAME)"
printf "%s (%s)" "$VERSION" "$CODENAME"
exit 0
fi

function printSeparator {
echo "#####################################"
printf "#####################################\n"
}

printSeparator
echo "Ubuntu Touch Platform Development Kit"
printf "Ubuntu Touch Platform Development Kit\n"
printSeparator
echo ""
echo "Executing tasks:"
printf "\tSetup? $SETUP\n"
printf "\tClear cache? $CLEARCACHE\n"
printf "\tList? $LIST\n"
printf "\tPull image? $PULL_IMG\n"
printf "\tRun an image? $RUN\n"

source $SCRIPTPATH/scripts/caches.sh
source $SCRIPTPATH/scripts/setup.sh
source $SCRIPTPATH/scripts/images.sh
source $SCRIPTPATH/scripts/mounts.sh
printf "\nExecuting tasks:\n"
printf "\tSetup? %s\n" "$SETUP"
printf "\tClear cache? %s\n" "$CLEARCACHE"
printf "\tList? %s\n" "$LIST"
printf "\tPull image? %s\n" "$PULL_IMG"
printf "\tRun an image? %s\n\n" "$RUN"

source "$SCRIPTPATH/scripts/caches.sh"
source "$SCRIPTPATH/scripts/setup.sh"
source "$SCRIPTPATH/scripts/images.sh"
source "$SCRIPTPATH/scripts/mounts.sh"
initImageVars
initSettingsVars

echo ""

# Warn when something's not right
if [ "$DATA_ROOT" == "" ] || [ "$SETUP" == "yes" ]; then
echo "WARNING: You haven't set up your environment yet. Continuing with setup..."
if [ -z "$DATA_ROOT" ] || [ "$SETUP" == "yes" ]; then
# Warn when something's not right
if [ -z "$DATA_ROOT" ]; then
printf "WARNING: You haven't set up your environment yet. Continuing with setup...\n"
fi
setup
generateSettingsImage
copySettingsIntoImage
Expand All @@ -164,25 +162,23 @@ fi

# Aaand run it!
if [ "$RUN" == "yes" ]; then
echo ""
echo "Name of the environment: $NAME"
echo ""
printf "\nName of the environment: %s\n\n" "$NAME"
if [ ! -d "$IMG_CACHE/$NAME" ]; then
echo "Cache directory for image '$NAME' doesn't exist."
echo "Consider pulling or creating an image yourself."
printf "Cache directory for image '%s' doesn't exist.\n" "$NAME"
printf "Consider pulling or creating an image yourself.\n"
exit 1
fi
if [ ! -f "$IMG_CACHE/$NAME/hdd.raw" ]; then
echo "Hard disk for image '$NAME' doesn't exist."
echo "Consider pulling or creating an image yourself."
printf "Hard disk for image '%s' doesn't exist." "$NAME"
printf "Consider pulling or creating an image yourself."
exit 1
fi
startVirtiofsd
runImage
fi

for JOB in `jobs -p`; do
kill -9 $JOB
for JOB in $(jobs -p); do
kill -9 "$JOB"
done

exit 0

0 comments on commit 0008ec5

Please sign in to comment.