From f70abcc03bc9173c6749c6ecc13d70a209ff329e 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 | 52 +++++++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/crossbuilder b/crossbuilder index 050b50a..0c263a5 100755 --- a/crossbuilder +++ b/crossbuilder @@ -162,7 +162,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 @@ -231,24 +231,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 -n "This is recommended for faster operation, and also in case there is not enough " + echo -e -n "space in your / partition. \n" 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}" sudo apt-get install -y zfsutils-linux fi @@ -261,6 +261,7 @@ setup_lxd () { # add automatic mount of zfs pool upon boot echo "zpool import -c /etc/zfs/zpool.cache -aN" | sudo tee /etc/rc.local else + echo "sudo lxd init --auto" sudo lxd init --auto fi fi @@ -276,13 +277,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 @@ -290,8 +290,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 @@ -308,7 +307,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 @@ -330,7 +329,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" @@ -341,7 +340,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" @@ -377,7 +376,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 @@ -593,7 +592,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/" @@ -649,8 +648,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 () { @@ -662,9 +661,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 @@ -765,7 +762,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 @@ -821,10 +818,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 @@ -835,8 +833,8 @@ if ! which lxd > /dev/null ; then sudo apt-get install -y lxd lxd-client 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 @@ -912,7 +910,7 @@ while [ "$1" != "" ]; do *) display_help echo "" - echo -e "${ERROR_COLOR}error: unknown option: $OPTION${NC}" + echo -e "${ERROR_COLOR}Error: unknown option: $OPTION${NC}" exit 1 ;; esac @@ -1148,7 +1146,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