-
-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automated the project setup with a single command for both Windows and Unix-based systems using Batch and Shell scripts with pacman support and comments #162
base: main
Are you sure you want to change the base?
Conversation
Automated setup for verso in unix based operating systems. Signed-off-by: Arpit Pathak <[email protected]>
Automated setup for verso on Windows. Signed-off-by: Arpit Pathak <[email protected]>
Added comments for letting users know what they are installing. Signed-off-by: Arpit Pathak <[email protected]>
Added support for pacman and Added comments for letting users know what they are installing. Signed-off-by: Arpit Pathak <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewrite of the script that is meant to be used on Linux and Darwin
#!/bin/bash | ||
|
||
# Ensure script is run as root | ||
if [ "$(id -u)" != "0" ]; then | ||
echo "This script must be run as root (use sudo)." | ||
exit 1 | ||
fi | ||
|
||
# Install necessary packages based on the package manager available | ||
if [ -x "$(command -v apt-get)" ]; then | ||
echo "Detected Debian-based system. Installing dependencies using apt-get." | ||
sudo apt-get update | ||
sudo apt-get install -y git python3-pip llvm cmake curl | ||
|
||
elif [ -x "$(command -v yum)" ]; then | ||
echo "Detected Red Hat-based system. Installing dependencies using yum." | ||
sudo yum install -y git python3-pip llvm cmake curl | ||
|
||
elif [ -x "$(command -v pacman)" ]; then | ||
echo "Detected Arch-based system. Installing dependencies using pacman." | ||
sudo pacman -Sy --needed git python-pip llvm cmake curl | ||
|
||
elif [ -x "$(command -v brew)" ]; then | ||
echo "Detected macOS. Installing dependencies using Homebrew." | ||
brew install git python3 llvm cmake curl | ||
|
||
else | ||
echo "Unsupported OS or package manager. Please install dependencies manually." | ||
exit 1 | ||
fi | ||
|
||
# Install Python dependencies | ||
echo "Installing Python dependencies..." | ||
pip3 install mako | ||
|
||
# Build and run the project using Cargo | ||
echo "Building the project..." | ||
cargo run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#!/bin/bash | |
# Ensure script is run as root | |
if [ "$(id -u)" != "0" ]; then | |
echo "This script must be run as root (use sudo)." | |
exit 1 | |
fi | |
# Install necessary packages based on the package manager available | |
if [ -x "$(command -v apt-get)" ]; then | |
echo "Detected Debian-based system. Installing dependencies using apt-get." | |
sudo apt-get update | |
sudo apt-get install -y git python3-pip llvm cmake curl | |
elif [ -x "$(command -v yum)" ]; then | |
echo "Detected Red Hat-based system. Installing dependencies using yum." | |
sudo yum install -y git python3-pip llvm cmake curl | |
elif [ -x "$(command -v pacman)" ]; then | |
echo "Detected Arch-based system. Installing dependencies using pacman." | |
sudo pacman -Sy --needed git python-pip llvm cmake curl | |
elif [ -x "$(command -v brew)" ]; then | |
echo "Detected macOS. Installing dependencies using Homebrew." | |
brew install git python3 llvm cmake curl | |
else | |
echo "Unsupported OS or package manager. Please install dependencies manually." | |
exit 1 | |
fi | |
# Install Python dependencies | |
echo "Installing Python dependencies..." | |
pip3 install mako | |
# Build and run the project using Cargo | |
echo "Building the project..." | |
cargo run | |
#!/usr/bin/env sh | |
# shellcheck shell=sh # POSIX | |
set -e # Exit on false return | |
die() { printf "FATAL: %s/n" "$2"; exit "${1:-1}"; } | |
[ "$(id -u)" = 0 ] || die 13 "This script '$0' must be run as root" # Root Check | |
kernelId="$(uname --kernel-name)" | |
kernelRel="$(uname --kernel-release)" | |
kernel="$kernelId:$kernelRel" | |
case "$kernel" in | |
Linux:*) | |
command -v lsb_release 1>/dev/null || die 127 "Required command 'lsb_release', needed to identify the host's distribution was not found in the current environment. Please install it" | |
distroId="$(lsb_release -s -i | sed 's/"//g')" | |
distroRel="$(lsb_release -s -r | sed 's/"//g')" | |
distro="$distroId:$distroRel" | |
case "$distro" in | |
arch:*) | |
echo "Detected Red Hat-based system. Installing dependencies using yum." | |
sudo yum install -y git python3-pip llvm cmake curl | |
;; | |
debian:*) | |
echo "Detected Debian-based system. Installing dependencies using apt-get." | |
sudo apt-get update | |
sudo apt-get install -y git python3-pip llvm cmake curl | |
;; | |
fedora:*) | |
echo "Detected Red Hat-based system. Installing dependencies using yum." | |
sudo yum install -y git python3-pip llvm cmake curl | |
;; | |
NixOS:*) | |
die 1 "This script does not support NixOS as a method for installing dependencies, use the provided shell environment instead" | |
;; | |
*) | |
die 1 "Distribution '$distro' is not implemented, please contribute a support for it in script: $0" | |
esac | |
;; | |
Darwin:*) | |
echo "Detected macOS. Installing dependencies using Homebrew." | |
brew install git python3 llvm cmake curl | |
;; | |
*) die 1 "Kernel '$kernel' is not implemented, please contribute a support for it in script: $0" | |
esac | |
# Install Python dependencies | |
echo "Installing Python dependencies..." | |
pip3 install mako | |
# Build and run the project using Cargo | |
echo "Building the project..." | |
cargo run |
@@ -0,0 +1,38 @@ | |||
#!/bin/bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works only on systems that follow the FHS 3.0 standard and e.g. on NixOS it's broken with:
$ /bin/bash
bash: /bin/bash: No such file or directory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#!/usr/bin/env bash
would be "universally POSIX way" :-) Should work also in NixOS.
# Install necessary packages based on the package manager available | ||
if [ -x "$(command -v apt-get)" ]; then | ||
echo "Detected Debian-based system. Installing dependencies using apt-get." | ||
sudo apt-get update | ||
sudo apt-get install -y git python3-pip llvm cmake curl | ||
|
||
elif [ -x "$(command -v yum)" ]; then | ||
echo "Detected Red Hat-based system. Installing dependencies using yum." | ||
sudo yum install -y git python3-pip llvm cmake curl | ||
|
||
elif [ -x "$(command -v pacman)" ]; then | ||
echo "Detected Arch-based system. Installing dependencies using pacman." | ||
sudo pacman -Sy --needed git python-pip llvm cmake curl | ||
|
||
elif [ -x "$(command -v brew)" ]; then | ||
echo "Detected macOS. Installing dependencies using Homebrew." | ||
brew install git python3 llvm cmake curl | ||
|
||
else | ||
echo "Unsupported OS or package manager. Please install dependencies manually." | ||
exit 1 | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stacking if-elif-elif-...-else unnecesarily increases the maintanance burden and it's common bad programming practice to the point that it's a popular programming meme named after YandereDev who popularized it as it makes the code look bad and with complexity very difficult to maintain. In general if you have to do more than 3 stacked conditions then you probably want to use a switch
statement or it's implementation in shell case
.
On Linux it's standard to use Linux Standard Base (latest LSB 5.0) to identify the linux distribution and it's release as e.g. there are scenarios where pacman is used on multiple distributions that might not have the same packages or their naming e.g. Parabola GNU/Linux
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both bash and zsh have OSTYPE
environment variable, which can be used along the lines of:
# Grep for 'darwin':
if [[ $OSTYPE =~ "darwin" ]]; then
echo "macOS"
else
echo "not macOS"
fi
That said, upstream projects never should modify system state as part of any script. At most it could suggest packages but not perform any action. It's a security border IMHO that should not be crossed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comments in the original code for review reference, please consider using shellcheck next time you write shell scripts as it's able to capture common mistakes:
and has a good documentation to explain why is the highlighted code an issue: https://www.shellcheck.net/wiki/SC2312
Referencing https://github.com/NiXium-org/NiXium/tree/35dc1a258134234f1601c6124bd4881ef1ba7567/tasks for how this abstract could be implemented in Nix-based environment, but it seems that the project developers do not use Nix for development to justify it's implementation. |
[In this PR I've added support for pacman and added comments to let users know what they are installing.]
Added batch and shell files (setup.bat for Windows and setup.sh for Unix-based systems) to streamline the setup process for the Verso project. These scripts handle the installation of all necessary dependencies, tools, and build processes, enabling users to set up and run the project with a single command on their respective systems.
Steps: