Small fixes

This commit is contained in:
Sefinek 2025-01-18 02:50:12 +01:00
parent f01c296750
commit 4f16dfda77

View file

@ -1,5 +1,18 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Function to prompt for a Yes/no answer
yes_no_prompt() {
local prompt="$1"
while true; do
read -r -p "$prompt [Yes/no]: " answer
case $answer in
[Yy]*|[Yy]es ) return 0 ;; # Return 0 for Yes
[Nn]*|[Nn]o ) return 1 ;; # Return 1 for No
* ) echo "❌ Invalid input. Please answer Yes/no or Y/n." ;;
esac
done
}
# Function to check and install missing dependencies # Function to check and install missing dependencies
check_dependencies() { check_dependencies() {
local dependencies=(curl node git) local dependencies=(curl node git)
@ -8,30 +21,29 @@ check_dependencies() {
for dependency in "${dependencies[@]}"; do for dependency in "${dependencies[@]}"; do
if ! command -v "$dependency" &> /dev/null; then if ! command -v "$dependency" &> /dev/null; then
missing+=("$dependency") missing+=("$dependency")
else
echo "$dependency is installed ($(command -v "$dependency"))"
if $dependency --version &> /dev/null; then
$dependency --version
else
echo " Version information for $dependency is unavailable"
fi
fi fi
done done
if [[ ${#missing[@]} -gt 0 ]]; then if [[ ${#missing[@]} -gt 0 ]]; then
echo "🚨 Missing dependencies: ${missing[*]}" echo "🚨 Missing dependencies: ${missing[*]}"
for dep in "${missing[@]}"; do for dep in "${missing[@]}"; do
read -r -p "📦 Do you want to install $dep? [Yes/No]: " answer if yes_no_prompt "📦 Do you want to install $dep?"; then
case $answer in case $dep in
[Yy]*|[Yy]es ) curl ) apt-get install -y curl ;;
case $dep in node ) curl -fsSL https://deb.nodesource.com/setup_22.x -o nodesource_setup.sh && bash nodesource_setup.sh && apt-get install -y nodejs && rm -f nodesource_setup.sh ;;
curl ) apt-get install -y curl ;; git ) add-apt-repository ppa:git-core/ppa && apt-get update && apt-get -y install git ;;
node ) curl -fsSL https://deb.nodesource.com/setup_22.x -o nodesource_setup.sh && bash nodesource_setup.sh && apt-get install -y nodejs && rm -f nodesource_setup.sh ;; esac
git ) add-apt-repository ppa:git-core/ppa && apt-get update && apt-get -y install git ;; else
esac echo "❌ Cannot proceed without $dep. Exiting..."
;; exit 1
[Nn]*|[Nn]o ) fi
echo "❌ Cannot proceed without $dep. Exiting..."
exit 1
;;
* )
echo "❌ Invalid input. Exiting..."
exit 1
;;
esac
done done
else else
echo "✅ All dependencies are installed" echo "✅ All dependencies are installed"
@ -93,20 +105,12 @@ while true; do
done done
# Prompt for system update and upgrade # Prompt for system update and upgrade
read -r -p "🛠️ Do you want the script to run apt update and apt upgrade for you? [Yes/No]: " answer if yes_no_prompt "🛠️ Do you want the script to run apt update and apt upgrade for you?"; then
case $answer in echo "🔧 Updating and upgrading the system..."
[Yy]*|[Yy]es ) apt-get update > /dev/null 2>&1 && apt-get upgrade
echo "🔧 Updating and upgrading the system..." else
apt-get update > /dev/null 2>&1 && apt-get upgrade echo "⏩ Skipping system update and upgrade..."
;; fi
[Nn]*|[Nn]o )
echo "⏩ Skipping system update and upgrade..."
;;
* )
echo "❌ Confused. Invalid input. Expected Yes/no or Y/n."
exit 1
;;
esac
# Clone repository # Clone repository
if [ -d "/home" ]; then if [ -d "/home" ]; then