Skip to content

Instantly share code, notes, and snippets.

@Zxce3
Created October 30, 2024 05:04
Show Gist options
  • Save Zxce3/2c23e168a5c42ea45c40d3da20c5a5ce to your computer and use it in GitHub Desktop.
Save Zxce3/2c23e168a5c42ea45c40d3da20c5a5ce to your computer and use it in GitHub Desktop.
#!/bin/bash
INSTALL_DIR="$HOME/.config/herd-lite/bin"
PHP_BIN="$INSTALL_DIR/php"
COMPOSER_BIN="$INSTALL_DIR/composer"
LARAVEL_BIN="$INSTALL_DIR/laravel"
# Function to remove the selected binaries
remove_component() {
local component="$1"
local path="$2"
if [ -f "$path" ]; then
rm -f "$path"
echo "$component has been uninstalled."
else
echo "$component was not found. Nothing to uninstall."
fi
}
# Function to clean the shell profile
remove_path_from_profile() {
local profile_file="$1"
if [ -f "$profile_file" ]; then
sed -i '/herd-lite\/bin/d' "$profile_file"
echo "Removed herd-lite PATH entry from $profile_file."
fi
}
# Display the uninstall options menu
echo "Select components to uninstall:"
echo "1) Uninstall PHP"
echo "2) Uninstall Composer"
echo "3) Uninstall Laravel"
echo "4) Uninstall all"
echo "5) Cancel"
read -p "Enter your choice [1-5]: " choice
case $choice in
1)
remove_component "PHP" "$PHP_BIN"
;;
2)
remove_component "Composer" "$COMPOSER_BIN"
;;
3)
remove_component "Laravel" "$LARAVEL_BIN"
;;
4)
remove_component "PHP" "$PHP_BIN"
remove_component "Composer" "$COMPOSER_BIN"
remove_component "Laravel" "$LARAVEL_BIN"
;;
5)
echo "Uninstallation cancelled."
exit 0
;;
*)
echo "Invalid choice. Exiting."
exit 1
;;
esac
# Ask if the user wants to remove the PATH entry
read -p "Do you want to remove the herd-lite PATH entry from your shell profile? (y/n): " remove_path
if [[ "$remove_path" == "y" || "$remove_path" == "Y" ]]; then
# Detect the current shell and clean the correct profile file
CURRENT_SHELL=$(basename "$SHELL")
case "$CURRENT_SHELL" in
bash)
PROFILE_FILES=("$HOME/.bashrc" "$HOME/.bash_profile" "$HOME/.profile")
;;
zsh)
PROFILE_FILES=("$HOME/.zshrc" "$HOME/.zprofile" "$HOME/.profile")
;;
*)
PROFILE_FILES=("$HOME/.profile")
echo "Unknown shell. Defaulting to clean ~/.profile."
;;
esac
# Remove PATH entry from all relevant profile files
for PROFILE_FILE in "${PROFILE_FILES[@]}"; do
remove_path_from_profile "$PROFILE_FILE"
done
echo "herd-lite PATH entry removed from your shell profile."
else
echo "PATH entry was not removed."
fi
echo "Uninstallation complete."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment