Skip to content

Commit

Permalink
Merge pull request #3 from octonawish-akcodes/scr
Browse files Browse the repository at this point in the history
added uninstall script for kcl linux installation
  • Loading branch information
Peefy authored Feb 3, 2024
2 parents 4247c29 + b86f3ec commit b2f6264
Showing 1 changed file with 109 additions and 0 deletions.
109 changes: 109 additions & 0 deletions script/uninstall-cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#!/bin/bash

# KCL location
: ${KCL_INSTALL_DIR:="/usr/local"}

# KCL filename
KCL_CLI_FILENAME="kcl"
# KCL file path
KCL_CLI_FILE="${KCL_INSTALL_DIR}/bin/${KCL_CLI_FILENAME}"

# --- helper functions ---
info() {
printf '\033[1;32m%12s\033[0m %s\n' "$1" "$2"
}

warn() {
printf '\033[1;33mWarn\033[0m: %s\n' "$1"
}

error() {
printf '\033[1;31mError\033[0m: %s\n' "$1"
}

# Uninstall KCL
uninstall_kcl() {
if [ -f "$KCL_CLI_FILE" ]; then
# Remove the binary file
sudo rm -f "$KCL_CLI_FILE"
if [ $? -eq 0 ]; then
info "Success" "KCL uninstalled from $KCL_CLI_FILE"
else
error "Failed" "Failed to uninstall KCL from $KCL_CLI_FILE"
fi
else
warn "Warning" "KCL is not installed in $KCL_CLI_FILE"
fi
}

# Remove modifications from user's profile
remove_profile_modifications() {
detected_profile=$(detectProfile "$(basename $SHELL)" "$(uname -s)")
if [ -n "$detected_profile" ]; then
info "Profile" "Removing modifications from $detected_profile"
sed -i.bak '/kcl-lang.io/d' "$detected_profile"
if [ $? -eq 0 ]; then
info "Success" "Profile modifications removed"
else
error "Failed" "Failed to remove profile modifications"
fi
rm -f "${detected_profile}.bak"
else
warn "Warning" "No user profile found."
fi
}

# Detect user's profile
detectProfile() {
local shell_name="$1"
local uname="$2"

case "$shell_name" in
bash)
case $uname in
Darwin)
echo_fexists "$HOME/.bash_profile" || echo_fexists "$HOME/.bashrc"
;;
*)
echo_fexists "$HOME/.bashrc" || echo_fexists "$HOME/.bash_profile"
;;
esac
;;
zsh)
echo "$HOME/.zshrc"
;;
fish)
echo "$HOME/.config/fish/config.fish"
;;
*)
# Fall back to checking for profile file existence
local profiles
case $uname in
Darwin)
profiles=("$HOME/.bash_profile" "$HOME/.bashrc")
;;
*)
profiles=("$HOME/.bashrc" "$HOME/.bash_profile")
;;
esac

for profile in "${profiles[@]}"; do
echo_fexists "$profile" && break
done
;;
esac
}

# Check if file exists and echo it
echo_fexists() {
[ -f "$1" ] && echo "$1"
}

# Main uninstallation process
uninstall() {
uninstall_kcl
remove_profile_modifications
}

# Execute uninstallation
uninstall

0 comments on commit b2f6264

Please sign in to comment.