Skip to content

Commit

Permalink
Merge pull request #179 from AndreWohnsland/dev
Browse files Browse the repository at this point in the history
Introduce shellcheck to CICD
  • Loading branch information
AndreWohnsland authored Jul 20, 2024
2 parents 8f8d40e + 50440ff commit 80cba9a
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 29 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: ShellCheck
on: [pull_request]
jobs:
shellcheck:
name: Shellcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
18 changes: 11 additions & 7 deletions scripts/all_in_one.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ..."
Expand All @@ -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."
Expand All @@ -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 ..."
Expand All @@ -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 ..."
Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions scripts/install_compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 :(

Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/install_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/launcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
31 changes: 18 additions & 13 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions scripts/setup_non_rpi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

# Check if the script is running on a non-Raspberry Pi device
if ! is_raspberry_pi; then
echo "$(whoami) ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/99_$(whoami)_nopasswd >/dev/null
sudo chmod 0440 /etc/sudoers.d/99_$(whoami)_nopasswd
echo "$(whoami) ALL=(ALL) NOPASSWD: ALL" | sudo tee "/etc/sudoers.d/99_$(whoami)_nopasswd" >/dev/null
sudo chmod 0440 "/etc/sudoers.d/99_$(whoami)_nopasswd"
if ! getent group gpio >/dev/null; then
echo "Creating gpio group"
sudo groupadd gpio
fi
echo "Setting up GPIOs for non Raspberry Pi devices"
sudo usermod -aG gpio $USER
sudo usermod -aG gpio "$USER"

# Create the setup_gpio_permissions.sh script
sudo cp .scripts/setup_gpio_permissions.sh /usr/local/bin/setup_gpio_permissions.sh
Expand Down

0 comments on commit 80cba9a

Please sign in to comment.