feat: enhance installation and uninstallation scripts with logging and error handling
This commit is contained in:
parent
a52fa31901
commit
2e77ee2333
@ -78,6 +78,12 @@ printfe() {
|
||||
printf "$color$format$normal" "$message"
|
||||
}
|
||||
|
||||
# Print and run a command in yellow
|
||||
log_and_run() {
|
||||
printfe "%s\n" "yellow" "$*"
|
||||
eval "$@"
|
||||
}
|
||||
|
||||
run_docker_command() {
|
||||
cmd=$1
|
||||
log_level="$2"
|
||||
|
@ -8,24 +8,42 @@ if [ "$EUID" -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Remove any existing kcm installation
|
||||
if [ -f "/usr/local/bin/kcm" ]; then
|
||||
printfe "%s\n" "yellow" "Removing existing kcm installation..."
|
||||
rm /usr/local/bin/kcm
|
||||
# Firstly compile the kcm binary
|
||||
printfe "%s\n" "cyan" "Compiling kcm..."
|
||||
MAKE_OUTPUT=$(make 2>&1)
|
||||
MAKE_EXIT_CODE=$?
|
||||
if [ $MAKE_EXIT_CODE -ne 0 ]; then
|
||||
printfe "%s\n" "red" "Compilation failed. Please check the output below."
|
||||
echo "$MAKE_OUTPUT"
|
||||
exit 1
|
||||
fi
|
||||
printfe "%s\n" "green" "Compilation successful."
|
||||
|
||||
# Remove any existing kcm installation
|
||||
printfe "%s\n" "cyan" "Removing existing kcm installation..."
|
||||
if [ -f "/usr/local/bin/kcm" ]; then
|
||||
log_and_run rm /usr/local/bin/kcm
|
||||
fi
|
||||
if [ -f "/usr/share/bash-completion/completions/kcm" ]; then
|
||||
printfe "%s\n" "yellow" "Removing existing kcm bash completion..."
|
||||
rm /usr/share/bash-completion/completions/kcm
|
||||
log_and_run rm /usr/share/bash-completion/completions/kcm
|
||||
fi
|
||||
if [ -f "/usr/local/share/kcm/kcm.version" ]; then
|
||||
log_and_run rm /usr/local/share/kcm/kcm.version
|
||||
fi
|
||||
|
||||
# Copy binary files to /usr/local/bin
|
||||
printfe "%s\n" "cyan" "Installing kcm..."
|
||||
cp $(pwd)/bin/kcm /usr/local/bin/kcm
|
||||
cp $(pwd)/bin/kcm-completion.bash /usr/share/bash-completion/completions/kcm
|
||||
log_and_run cp $(pwd)/bin/kcm /usr/local/bin/kcm
|
||||
log_and_run cp $(pwd)/bin/kcm-completion.bash /usr/share/bash-completion/completions/kcm
|
||||
|
||||
# Copy version file to /usr/local/share/kcm/kcm.version
|
||||
mkdir -p /usr/local/share/kcm
|
||||
cp $(pwd)/bin/kcm.version /usr/local/share/kcm/kcm.version
|
||||
log_and_run cp $(pwd)/bin/kcm.version /usr/local/share/kcm/kcm.version
|
||||
|
||||
# Clean up any compiled files
|
||||
printfe "%s\n" "cyan" "Cleaning up..."
|
||||
log_and_run rm $(pwd)/bin/kcm
|
||||
log_and_run rm $(pwd)/bin/kcm-completion.bash
|
||||
log_and_run rm $(pwd)/bin/kcm.version
|
||||
|
||||
printfe "%s\n" "green" "Installation complete."
|
||||
|
@ -2,52 +2,35 @@
|
||||
|
||||
source bin/helpers/func.sh
|
||||
|
||||
# Test for root privileges if uninstalling system-wide files
|
||||
NEED_ROOT=0
|
||||
if [ -f /usr/local/bin/kcm ] || [ -f /usr/share/bash-completion/completions/kcm ] || [ -f /usr/local/share/kcm/kcm.version ]; then
|
||||
NEED_ROOT=1
|
||||
fi
|
||||
if [ $NEED_ROOT -eq 1 ] && [ "$EUID" -ne 0 ]; then
|
||||
printfe "%s\n" "red" "Please run as root"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Remove user-local files
|
||||
printfe "%s\n" "cyan" "Removing kcm from user-local locations..."
|
||||
if [ -f $HOME/.local/bin/kcm ]; then
|
||||
printfe "%s\n" "cyan" "Removing kcm from $HOME/.local/bin"
|
||||
rm $HOME/.local/bin/kcm
|
||||
rm $HOME/.local/bin/T
|
||||
log_and_run rm $HOME/.local/bin/kcm
|
||||
fi
|
||||
|
||||
if [ -f $HOME/.local/bin/kcm-completion.bash ]; then
|
||||
printfe "%s\n" "cyan" "Removing kcm-completion.bash from $HOME/.local/bin"
|
||||
rm $HOME/.local/bin/kcm-completion.bash
|
||||
fi
|
||||
|
||||
if [ -f $HOME/.local/bin/php ]; then
|
||||
printfe "%s\n" "cyan" "Removing php from $HOME/.local/bin"
|
||||
rm $HOME/.local/bin/php
|
||||
fi
|
||||
|
||||
if [ -f $HOME/.local/bin/composer ]; then
|
||||
printfe "%s\n" "cyan" "Removing composer from $HOME/.local/bin"
|
||||
rm $HOME/.local/bin/composer
|
||||
fi
|
||||
|
||||
if [ -f $HOME/.local/bin/phpstan ]; then
|
||||
printfe "%s\n" "cyan" "Removing phpstan from $HOME/.local/bin"
|
||||
rm $HOME/.local/bin/phpstan
|
||||
log_and_run rm $HOME/.local/bin/kcm-completion.bash
|
||||
fi
|
||||
|
||||
# Remove system-wide files using log_and_run
|
||||
printfe "%s\n" "cyan" "Removing kcm from system-wide locations..."
|
||||
if [ -f /usr/share/bash-completion/completions/kcm ]; then
|
||||
# Check root privileges
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
printfe "%s\n" "red" "Please run as root"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printfe "%s\n" "cyan" "Removing kcm bash completion from /usr/share/bash-completion/completions"
|
||||
rm /usr/share/bash-completion/completions/kcm
|
||||
log_and_run rm /usr/share/bash-completion/completions/kcm
|
||||
fi
|
||||
|
||||
if [ -f /usr/local/bin/kcm ]; then
|
||||
# Check root privileges
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
printfe "%s\n" "red" "Please run as root"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printfe "%s\n" "cyan" "Removing kcm from /usr/local/bin"
|
||||
rm /usr/local/bin/kcm
|
||||
log_and_run rm /usr/local/bin/kcm
|
||||
fi
|
||||
if [ -f /usr/local/share/kcm/kcm.version ]; then
|
||||
log_and_run rm /usr/local/share/kcm/kcm.version
|
||||
fi
|
||||
|
||||
printfe "%s\n" "green" "Uninstall complete."
|
||||
|
Loading…
x
Reference in New Issue
Block a user