diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml new file mode 100644 index 00000000..89c1ca04 --- /dev/null +++ b/.github/workflows/shellcheck.yml @@ -0,0 +1,10 @@ +name: Linting +on: [pull_request] +jobs: + shellcheck: + name: Shellcheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Run ShellCheck + uses: ludeeus/action-shellcheck@master diff --git a/scripts/all_in_one.sh b/scripts/all_in_one.sh index 767f3b30..3dd8bb0b 100644 --- a/scripts/all_in_one.sh +++ b/scripts/all_in_one.sh @@ -8,7 +8,7 @@ sudo apt-get update && sudo apt-get -y upgrade # Steps for git echo "~ Check if git is installed ~" -git --version 2>&1 >/dev/null +git --version >/dev/null 2>&1 GIT_IS_AVAILABLE=$? if [ $GIT_IS_AVAILABLE -ne 0 ]; then echo "Git was not found, installing it ..." @@ -24,7 +24,7 @@ sudo apt install python-is-python3 # steps for python >= 3.9 echo "~ Check that Python version is at least 3.9 ~" version=$(python -V 2>&1 | grep -Po '(?<=Python )(.+)') -parsedVersion=$(echo "${version//./}") +parsedVersion="${version//./}" echo "Detected version: $version" if [[ "$parsedVersion" -lt "390" ]]; then echo "Python must be at least 3.9. Please upgrade your Python or the system to use CocktailBerry." @@ -39,22 +39,22 @@ fi # might also need to install python-venv echo "~ Check if python3-venv and ensurepip are available ~" -python3 -m venv --help 2>&1 >/dev/null +python3 -m venv --help >/dev/null 2>&1 VENV_IS_AVAILABLE=$? -python3 -c "import ensurepip" 2>&1 >/dev/null +python3 -c "import ensurepip" >/dev/null 2>&1 ENSUREPIP_IS_AVAILABLE=$? if [ $VENV_IS_AVAILABLE -ne 0 ] || [ $ENSUREPIP_IS_AVAILABLE -ne 0 ]; then echo "Python3 venv or ensurepip was not found, installing python3-venv ..." PYTHON_VERSION=$(python3 -V | cut -d' ' -f2 | cut -d'.' -f1,2) # Extracts version in format X.Y - sudo apt install python${PYTHON_VERSION}-venv + sudo apt install python"${PYTHON_VERSION}"-venv else echo "Python3 venv and ensurepip are already installed!" fi # also install pip if not already done echo "~ Check if pip is installed ~" -pip --version 2>&1 >/dev/null +pip --version >/dev/null 2>&1 PIP_IS_AVAILABLE=$? if [ $PIP_IS_AVAILABLE -ne 0 ]; then echo "Pip was not found, installing it ..." @@ -77,7 +77,7 @@ fi # ensure lxterminal is installed echo "~ Check if lxterminal is installed ~" -lxterminal --version 2>&1 >/dev/null +lxterminal --version >/dev/null 2>&1 LXTERMINAL_IS_AVAILABLE=$? if [ $LXTERMINAL_IS_AVAILABLE -ne 0 ]; then echo "Lxterminal was not found, installing it ..." @@ -89,17 +89,21 @@ fi # Now gets CocktailBerry source echo "~ Getting the CocktailBerry project from GitHub ... ~" echo "It will be located at ~/CocktailBerry" +# shellcheck disable=SC2164 cd ~ git clone https://github.com/AndreWohnsland/CocktailBerry.git +# shellcheck disable=SC2164 cd ~/CocktailBerry # Do Docker related steps echo "~ Setting things up for Docker and Compose ~" bash scripts/install_docker.sh -n +# shellcheck disable=SC2164 cd ~/CocktailBerry bash scripts/install_compose.sh # Now we can finally set the program up ^-^ +# shellcheck disable=SC2164 cd ~/CocktailBerry echo "~ Setting up and installing CocktailBerry ~" bash scripts/setup.sh diff --git a/scripts/install_compose.sh b/scripts/install_compose.sh index 282fc80b..a83f24da 100644 --- a/scripts/install_compose.sh +++ b/scripts/install_compose.sh @@ -2,7 +2,7 @@ echo "Installing Compose" DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker} -mkdir -p $DOCKER_CONFIG/cli-plugins +mkdir -p "$DOCKER_CONFIG/cli-plugins" # in the future, sudo apt install docker-compose-plugin should work # sadly, this still does not work :( @@ -11,6 +11,7 @@ mkdir -p $DOCKER_CONFIG/cli-plugins # This is used to have always the latest version and not a fixed one echo "Creating temporary virtual environment for lastversion" python -m venv --system-site-packages ~/.env-compose +# shellcheck disable=SC1090 source ~/.env-compose/bin/activate echo "Installing lastversion" pip install -q lastversion @@ -19,15 +20,15 @@ pip install -q lastversion # COMPOSE_VERSION=$(lastversion docker/compose) # but its more robust to get the whole asset URL -if [ $(getconf LONG_BIT) = "64" ]; then +if [ "$(getconf LONG_BIT)" = "64" ]; then echo "Detected 64 bit system, using aarch64 compose image" DOWNLOAD_URL=$(lastversion --assets --filter '\-linux-aarch64(?!.sha256)' docker/compose) else echo "Detected 32 bit system, using armv7l compose image" DOWNLOAD_URL=$(lastversion --assets --filter '\-linux-armv7(?!.sha256)' docker/compose) fi -curl -SL $DOWNLOAD_URL -o $DOCKER_CONFIG/cli-plugins/docker-compose -chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose +curl -SL "$DOWNLOAD_URL" -o "$DOCKER_CONFIG/cli-plugins/docker-compose" +chmod +x "$DOCKER_CONFIG/cli-plugins/docker-compose" docker compose version || echo "Compose installation failed :(" # remove venv at the end diff --git a/scripts/install_docker.sh b/scripts/install_docker.sh index cc3b7b07..1a3be421 100644 --- a/scripts/install_docker.sh +++ b/scripts/install_docker.sh @@ -28,7 +28,7 @@ sudo apt-get update && sudo apt-get -y upgrade sudo apt install docker.io -y docker --version || echo "Docker installation failed :(" echo "Adds current user to docker permissions" -sudo usermod -aG docker $USER +sudo usermod -aG docker "$USER" if ${RELOAD_GRP}; then newgrp docker diff --git a/scripts/launcher.sh b/scripts/launcher.sh index 6140415c..c07e3633 100644 --- a/scripts/launcher.sh +++ b/scripts/launcher.sh @@ -12,5 +12,5 @@ # launcher.sh for CocktailBerry export QT_SCALE_FACTOR=1 -cd ~/CocktailBerry/ +cd ~/CocktailBerry/ || echo "Did not find ~/CocktailBerry/" && exit python runme.py diff --git a/scripts/setup.sh b/scripts/setup.sh index 2c4000ca..2aba9a75 100644 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -47,18 +47,19 @@ echo "(Re-)Creating virtual environment for CocktailBerry, located at ~/.venv-co rm -rf ~/.env-cocktailberry python -m venv --system-site-packages ~/.env-cocktailberry echo "Activating virtual environment, this is needed since Raspbery Pi OS Bookworm" +# shellcheck disable=SC1090 source ~/.env-cocktailberry/bin/activate -cd ~/CocktailBerry/ +cd ~/CocktailBerry/ || exit # Making neccecary steps for the according program if [ "$1" = "dashboard" ]; then echo "Setting up Dashboard" - cd dashboard/ + cd dashboard/ || exit # Letting user choose the frontend type (WebApp or Qt) echo -n "Use new dashboard? This is strongly recommended! Oterwise will use old Qt App, but this will only work on a standalone device and has no remote access option (y/n) " - read answer + read -r answer echo -n "Enter your display language (en, de): " - read language + read -r language # new dashboard if echo "$answer" | grep -iq "^y"; then export UI_LANGUAGE=$language @@ -67,19 +68,23 @@ if [ "$1" = "dashboard" ]; then # qt app else docker compose up --build -d || echo "ERROR: Could not install backend over docker-compose, is docker installed?" - echo "export UI_LANGUAGE=$language" >>~/launcher.sh - echo "source ~/.env-cocktailberry/bin/activate" >>~/launcher.sh - echo "cd ~/CocktailBerry/dashboard/qt-app/" >>~/launcher.sh - echo "python main.py" >>~/launcher.sh - cd qt-app/ + { + echo "export UI_LANGUAGE=$language" + echo "source ~/.env-cocktailberry/bin/activate" + echo "cd ~/CocktailBerry/dashboard/qt-app/" + echo "python main.py" + } >>~/launcher.sh + cd qt-app/ || exit pip install -r requirements.txt fi else echo "Setting up CocktailBerry" - echo "source ~/.env-cocktailberry/bin/activate" >>~/launcher.sh - echo "export QT_SCALE_FACTOR=1" >>~/launcher.sh - echo "cd ~/CocktailBerry/" >>~/launcher.sh - echo "python runme.py" >>~/launcher.sh + { + echo "source ~/.env-cocktailberry/bin/activate" + echo "export QT_SCALE_FACTOR=1" + echo "cd ~/CocktailBerry/" + echo "python runme.py" + } >>~/launcher.sh echo "Installing PyQt" sudo apt-get -y install qt5-default pyqt5-dev pyqt5-dev-tools || sudo apt-get -y install python3-pyqt5 || echo "ERROR: Could not install PyQt5" echo "Installing needed Python libraries"