From d2a99c8ff4ccfcb29fe4d1994b6e4b0ab1e50a92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Fri, 23 Feb 2024 11:17:04 +0100 Subject: [PATCH] Fix shellcheck issues --- ynh-dev | 109 +++++++++++++++++++++++++++----------------------------- 1 file changed, 52 insertions(+), 57 deletions(-) diff --git a/ynh-dev b/ynh-dev index f10d635..9c2eba5 100755 --- a/ynh-dev +++ b/ynh-dev @@ -1,4 +1,5 @@ #!/usr/bin/env bash +# shellcheck disable=SC2155,SC2164,SC2034 function show_usage() { cat </dev/null + if ! sudo lxc info "$BOX" &>/dev/null then - if ! sudo lxc image info $BOX-base &>/dev/null + if ! sudo lxc image info "$BOX-base" &>/dev/null then LXC_BASE="ynh-dev-$DIST-amd64-$YNH_BRANCH-base" - sudo lxc launch yunohost:$LXC_BASE $BOX -c security.nesting=true -c security.privileged=true \ + sudo lxc launch "yunohost:$LXC_BASE" "$BOX" -c security.nesting=true -c security.privileged=true \ || critical "Failed to launch the container ?" else - sudo lxc launch $BOX-base $BOX -c security.nesting=true -c security.privileged=true + sudo lxc launch "$BOX-base" "$BOX" -c security.nesting=true -c security.privileged=true fi - sudo lxc config device add $BOX ynhdev-shared-folder disk path=/ynh-dev source="$(readlink -f $(pwd))" + sudo lxc config device add "$BOX" ynhdev-shared-folder disk path=/ynh-dev source="$(readlink -f "$(pwd)")" info "Now attaching to the container" else info "Attaching to existing container" @@ -201,8 +202,8 @@ function attach_ynhdev() local DIST=${1:-bookworm} local YNH_BRANCH=${3:-unstable} local BOX=${2:-ynh-dev}-${DIST}-${YNH_BRANCH} - sudo lxc start $BOX 2>/dev/null || true - sudo lxc exec $BOX --cwd /ynh-dev -- /bin/bash + sudo lxc start "$BOX" 2>/dev/null || true + sudo lxc exec "$BOX" --cwd /ynh-dev -- /bin/bash } function destroy_ynhdev() @@ -211,8 +212,8 @@ function destroy_ynhdev() local DIST=${1:-bookworm} local YNH_BRANCH=${3:-unstable} local BOX=${2:-ynh-dev}-${DIST}-${YNH_BRANCH} - sudo lxc stop $BOX - sudo lxc delete $BOX + sudo lxc stop "$BOX" + sudo lxc delete "$BOX" } function rebuild_ynhdev() @@ -224,14 +225,14 @@ function rebuild_ynhdev() local BOX=${2:-ynh-dev}-${DIST}-${YNH_BRANCH} set -x - sudo lxc info $BOX-rebuild >/dev/null && sudo lxc delete $BOX-rebuild --force - sudo lxc launch images:debian/$DIST/amd64 $BOX-rebuild -c security.nesting=true -c security.privileged=true + sudo lxc info "$BOX-rebuild" >/dev/null && sudo lxc delete "$BOX-rebuild" --force + sudo lxc launch "images:debian/$DIST/amd64" "$BOX-rebuild" -c security.nesting=true -c security.privileged=true sleep 5 - sudo lxc exec $BOX-rebuild -- apt install curl -y + sudo lxc exec "$BOX-rebuild" -- apt install curl -y INSTALL_SCRIPT="https://install.yunohost.org/$DIST" - sudo lxc exec $BOX-rebuild -- /bin/bash -c "curl $INSTALL_SCRIPT | bash -s -- -a -d $YNH_BRANCH" - sudo lxc stop $BOX-rebuild - sudo lxc publish $BOX-rebuild --alias $BOX-base + sudo lxc exec "$BOX-rebuild" -- /bin/bash -c "curl $INSTALL_SCRIPT | bash -s -- -a -d $YNH_BRANCH" + sudo lxc stop "$BOX-rebuild" + sudo lxc publish "$BOX-rebuild" --alias "$BOX-base" set +x } @@ -246,8 +247,7 @@ function use_git() assert_inside_vm local PACKAGES=("$@") - if [ "$PACKAGES" = "" ] - then + if [[ "${#PACKAGES[@]}" == 0 ]]; then PACKAGES=('moulinette' 'ssowat' 'yunohost' 'yunohost-admin') fi @@ -281,17 +281,13 @@ function use_git() ;; yunohost) - for FILE in $(ls /ynh-dev/yunohost/bin/) - do + for FILE in /ynh-dev/yunohost/bin/*; do create_sym_link "/ynh-dev/yunohost/bin/$FILE" "/usr/bin/$FILE" done - - for FILE in $(ls /ynh-dev/yunohost/conf/metronome/modules/) - do + for FILE in /ynh-dev/yunohost/conf/metronome/modules/*; do create_sym_link "/ynh-dev/yunohost/conf/metronome/modules/$FILE" "/usr/lib/metronome/modules/$FILE" done - for FILE in $(ls /ynh-dev/yunohost/share/) - do + for FILE in /ynh-dev/yunohost/share/*; do create_sym_link "/ynh-dev/yunohost/share/$FILE" "/usr/share/yunohost/$FILE" done create_sym_link "/ynh-dev/yunohost/hooks" "/usr/share/yunohost/hooks" @@ -436,6 +432,7 @@ function dev() journalctl --no-pager --no-hostname -u yunohost-api -u yunohost-portal-api -n 0 -f & JOURNALCTL_PID=$! + # shellcheck disable=SC2064 trap "kill $JOURNALCTL_PID; exit" SIGINT while ! inotifywait -q -e modify /usr/lib/python3/dist-packages/{moulinette,yunohost}/{*.py,*/*.py} @@ -449,9 +446,8 @@ function dev() function run_tests() { assert_inside_vm - local PACKAGES="$@" - for PACKAGE in $PACKAGES; - do + local PACKAGES=("$@") + for PACKAGE in "${PACKAGES[@]}"; do TEST_FUNCTION=$(echo "$PACKAGE" | tr '/:' ' ' | awk '{print $3}') TEST_MODULE=$(echo "$PACKAGE" | tr '/:' ' ' | awk '{print $2}') PACKAGE=$(echo "$PACKAGE" | tr '/:' ' ' | awk '{print $1}') @@ -464,11 +460,10 @@ function run_tests() apt-get install python3-pip -y pip3 install pytest pytest-sugar --break-system-packages fi - for DEP in "pytest-mock requests-mock mock" - do - if [ -z "$(pip3 show $DEP)" ]; then + for DEP in pytest-mock requests-mock mock; do + if [ -z "$(pip3 show "$DEP")" ]; then info "Installing $DEP with pip3" - pip3 install $DEP --break-system-packages + pip3 install "$DEP" --break-system-packages fi done @@ -560,4 +555,4 @@ function rebuild_api_doc() -main $@ +main "$@"