From 6b3a451e497f63d3377096350a8cca1f76767a2c Mon Sep 17 00:00:00 2001 From: jEzEk Date: Sun, 12 Sep 2021 17:33:39 +0200 Subject: [PATCH] Syntax, structure, indent and unneeded logic fixes - Fix unset usage. - Fix some missing -e in echo where needed. - Add some echos, before running some commands. - Minor alignment fixes. - Don't use 'newgrp' upon lxd install, seems to have no effect. - Unify command output redirection formatting. - Make some multi-line commands to be in one line. --- crossbuilder | 47 ++++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/crossbuilder b/crossbuilder index 3c6f75c..3d69918 100755 --- a/crossbuilder +++ b/crossbuilder @@ -225,7 +225,7 @@ check_lxd_accessible () { # /bin/lxd is replaced with a script which tells you to install the lxd snap # on later versions of Ubuntu. LXD=`which lxd` - if (grep 'snap install lxd' "$LXD" >/dev/null) && [ ! -f /snap/bin/lxd ] ; then + if (grep 'snap install lxd' "$LXD" > /dev/null) && [ ! -f /snap/bin/lxd ] ; then $LXD exit 1 fi @@ -315,24 +315,24 @@ setup_lxd () { echo "this for you." echo "Press Enter to start" read KEY - unset $KEY + unset KEY # Ubuntu 16.04 specific workaround to set up sudo dpkg-reconfigure -p medium lxd fi if [ -n "$ENCRYPTED_HOME" ] ; then - echo -e -n "${ERROR_COLOR}Your home folder is encrypted. $PROGRAM_NAME will use priviledged " + echo -e -n "${ERROR_COLOR}Your home folder is encrypted. $PROGRAM_NAME will use privileged " echo -e -n "LXD containers and the default storage backend (slower).\n${NC}" sudo lxd init --auto else echo -e -n "${POSITIVE_COLOR}Would you like to setup LXD with ZFS in your home directory? (y/n) \n${NC}" echo -n "This is recommended for faster operation, and also in case there is not enough " - echo -n "space in your / partition. \n" + echo -e "space in your / partition." read REPLY echo if [ "$REPLY" = y ] then - if ! which zpool > /dev/null ; then + if ! which zpool > /dev/null 2>&1; then echo -e "${POSITIVE_COLOR}Installing ZFS.${NC}" if which apt-get > /dev/null 2>&1 ; then echo "sudo apt-get install -y zfsutils-linux" @@ -369,13 +369,12 @@ config_container_dir_mount () { } start_container () { - STATUS=$(lxc query "/1.0/containers/${LXD_CONTAINER}/state" | \ - jq --raw-output '.status') + STATUS=$(lxc query "/1.0/containers/${LXD_CONTAINER}/state" | jq --raw-output '.status') if [ $STATUS = 'Stopped' ]; then # lxc start may give a failure code. It also may not, so we check # again in a bit. if ! lxc start $LXD_CONTAINER; then - echo $LXD_CONTAINER_FAILURE_MSG + echo -e $LXD_CONTAINER_FAILURE_MSG exit 1 fi fi @@ -383,8 +382,7 @@ start_container () { # Unfortunately we need to check again. We check for Started this time # because the monitor may be hung with the container failing, which will # give us much different output - STATUS=$(lxc query "/1.0/containers/${LXD_CONTAINER}/state" | \ - jq --raw-output '.status') + STATUS=$(lxc query "/1.0/containers/${LXD_CONTAINER}/state" | jq --raw-output '.status') if [ "$STATUS" != 'Running' ]; then echo $LXD_CONTAINER_FAILURE_MSG exit 1 @@ -401,7 +399,7 @@ nonsdk_container_setup () { focal) ubports_repo_line="deb http://repo2.ubports.com/ $container_ubuntu_version main" ;; esac if [ -n "$ubports_repo_line" ]; then - exec_container_root "echo '$ubports_repo_line' >/etc/apt/sources.list.d/ubports.list" + exec_container_root "echo '$ubports_repo_line' > /etc/apt/sources.list.d/ubports.list" fi # Skip multiarch setup if not crossbuilding @@ -423,7 +421,7 @@ nonsdk_container_setup () { exec_container_root "sed -E \ -e 's:(archive|security)\.ubuntu\.com/ubuntu/:ports.ubuntu.com/ubuntu-ports/:' \ -e 's:^deb :deb [arch=${TARGET_ARCH}] :' \ - /etc/apt/sources.list >/etc/apt/sources.list.d/ports.list" + /etc/apt/sources.list > /etc/apt/sources.list.d/ports.list" exec_container_root "sed -i -E \ -e 's:^deb :deb [arch=${HOST_ARCH}] :' \ /etc/apt/sources.list" @@ -434,7 +432,7 @@ nonsdk_container_setup () { -e 's:ports\.ubuntu\.com/ubuntu-ports/ ([a-z]+)-security :security.ubuntu.com/ubuntu/ \1-security :' \ -e 's:ports\.ubuntu\.com/ubuntu-ports/ ([a-z-]+):archive.ubuntu.com/ubuntu/ \1 :' \ -e 's:^deb :deb [arch=${TARGET_ARCH}] :' \ - /etc/apt/sources.list >/etc/apt/sources.list.d/non-ports.list" + /etc/apt/sources.list > /etc/apt/sources.list.d/non-ports.list" exec_container_root "sed -i -E \ -e 's:^deb :deb [arch=${HOST_ARCH}] :' \ /etc/apt/sources.list" @@ -482,7 +480,7 @@ create_container () { exec_container_root "add-apt-repository -y ppa:ubports-developers/overlay" exec_container_root "add-apt-repository 'deb http://repo.ubports.com vivid main' >> /etc/apt/sources.list" fi - wget -qO - "https://repo.ubports.com/keyring.gpg" | exec_container_root 'cat >/etc/apt/trusted.gpg.d/ubports-keyring.gpg' + wget -qO - "https://repo.ubports.com/keyring.gpg" | exec_container_root 'cat > /etc/apt/trusted.gpg.d/ubports-keyring.gpg' if ! echo "$LXD_IMAGE" | grep -q "ubuntu-sdk"; then nonsdk_container_setup fi @@ -704,7 +702,7 @@ install_foreign () { exec_container "mkdir -p foreign && cd foreign && apt-get download $dep && dpkg-deb -R $dep* tmp" exec_container "grep -vi '^multi' foreign/tmp/DEBIAN/control > foreign/tmp/DEBIAN/control.tmp" exec_container "mv foreign/tmp/DEBIAN/control.tmp foreign/tmp/DEBIAN/control" - exec_container "echo 'Multi-Arch: foreign' >> foreign/tmp/DEBIAN/control" + exec_container "echo 'Multi-Arch: foreign' >> foreign/tmp/DEBIAN/control" exec_container "cd foreign && dpkg-deb -b tmp $dep*" exec_container_root "dpkg -i $SOURCE_PATH_CONTAINER/foreign/$dep*" exec_container "rm -r foreign/" @@ -760,8 +758,8 @@ copy_build_to_container () { lxc file push $SCRIPT_DIR/$CREATE_REPO_SCRIPT $LXD_CONTAINER$SOURCE_REPOSITORY/ exec_container $SOURCE_REPOSITORY/$CREATE_REPO_SCRIPT $SOURCE_REPOSITORY - exec_container_root "echo 'deb [trusted=yes] file://$SOURCE_REPOSITORY/ /' >/etc/apt/sources.list.d/localrepo.list" - exec_container_root "printf 'Package: *\nPin: release o=local\nPin-Priority: 2000' >/etc/apt/preferences.d/localrepo.pref" + exec_container_root "echo 'deb [trusted=yes] file://$SOURCE_REPOSITORY/ /' > /etc/apt/sources.list.d/localrepo.list" + exec_container_root "printf 'Package: *\nPin: release o=local\nPin-Priority: 2000' > /etc/apt/preferences.d/localrepo.pref" } clean () { @@ -773,9 +771,7 @@ check_for_container_network() { NETWORK_UP=0 for i in `seq 1 10` do - if lxc query "/1.0/containers/${LXD_CONTAINER}/state" | \ - jq -e '.network.eth0.addresses | any( .family == "inet" )' \ - > /dev/null 2>&1 ; then + if lxc query "/1.0/containers/${LXD_CONTAINER}/state" | jq -e '.network.eth0.addresses | any( .family == "inet" )' > /dev/null 2>&1 ; then NETWORK_UP=1 break fi @@ -894,7 +890,7 @@ deploy_to_device () { fi; # setup sudo on device - exec_device "printf '#\041/bin/sh\necho $DEVICE_PASSWORD' >/tmp/askpass.sh" + exec_device "printf '#\041/bin/sh\necho $DEVICE_PASSWORD' > /tmp/askpass.sh" exec_device chmod +x /tmp/askpass.sh # check password is correct @@ -1068,10 +1064,11 @@ if stat --file-system $HOME | grep ecrypt ; then fi if [ -e "/snap/bin/lxc" ]; then + echo "Force privileged container" FORCE_PRIVILEGED=1 fi -if ! which lxd > /dev/null ; then +if ! which lxd > /dev/null 2>&1 ; then echo -e "${POSITIVE_COLOR}$PROGRAM_NAME uses LXD to download dependencies and build.${NC}" echo -e -n "${POSITIVE_COLOR}Would you like to install LXD? (y/n) ${NC}" read REPLY @@ -1094,8 +1091,8 @@ if ! which lxd > /dev/null ; then fi setup_lxd ensure_lxd_subuid - newgrp lxd - sudo usermod -a -G lxd $(whoami) + echo "Adding user to lxd group" + sudo usermod -a -G lxd $(whoami) echo -e "${ERROR_COLOR}LXD is now setup but will only work after you restart your computer.${NC}" exit 0 else @@ -1365,7 +1362,7 @@ else *) display_help echo "" - echo -e "${ERROR_COLOR}error: unknown command: $COMMAND${NC}" + echo -e "${ERROR_COLOR}Error: unknown command: $COMMAND${NC}" exit 1 ;; esac