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"
|
printf "$color$format$normal" "$message"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Print and run a command in yellow
|
||||||
|
log_and_run() {
|
||||||
|
printfe "%s\n" "yellow" "$*"
|
||||||
|
eval "$@"
|
||||||
|
}
|
||||||
|
|
||||||
run_docker_command() {
|
run_docker_command() {
|
||||||
cmd=$1
|
cmd=$1
|
||||||
log_level="$2"
|
log_level="$2"
|
||||||
|
@ -8,24 +8,42 @@ if [ "$EUID" -ne 0 ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Remove any existing kcm installation
|
# Firstly compile the kcm binary
|
||||||
if [ -f "/usr/local/bin/kcm" ]; then
|
printfe "%s\n" "cyan" "Compiling kcm..."
|
||||||
printfe "%s\n" "yellow" "Removing existing kcm installation..."
|
MAKE_OUTPUT=$(make 2>&1)
|
||||||
rm /usr/local/bin/kcm
|
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
|
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
|
if [ -f "/usr/share/bash-completion/completions/kcm" ]; then
|
||||||
printfe "%s\n" "yellow" "Removing existing kcm bash completion..."
|
log_and_run rm /usr/share/bash-completion/completions/kcm
|
||||||
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
|
fi
|
||||||
|
|
||||||
# Copy binary files to /usr/local/bin
|
# Copy binary files to /usr/local/bin
|
||||||
printfe "%s\n" "cyan" "Installing kcm..."
|
printfe "%s\n" "cyan" "Installing kcm..."
|
||||||
cp $(pwd)/bin/kcm /usr/local/bin/kcm
|
log_and_run 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-completion.bash /usr/share/bash-completion/completions/kcm
|
||||||
|
|
||||||
# Copy version file to /usr/local/share/kcm/kcm.version
|
# Copy version file to /usr/local/share/kcm/kcm.version
|
||||||
mkdir -p /usr/local/share/kcm
|
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."
|
printfe "%s\n" "green" "Installation complete."
|
||||||
|
@ -2,52 +2,35 @@
|
|||||||
|
|
||||||
source bin/helpers/func.sh
|
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
|
if [ -f $HOME/.local/bin/kcm ]; then
|
||||||
printfe "%s\n" "cyan" "Removing kcm from $HOME/.local/bin"
|
log_and_run rm $HOME/.local/bin/kcm
|
||||||
rm $HOME/.local/bin/kcm
|
|
||||||
rm $HOME/.local/bin/T
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f $HOME/.local/bin/kcm-completion.bash ]; then
|
if [ -f $HOME/.local/bin/kcm-completion.bash ]; then
|
||||||
printfe "%s\n" "cyan" "Removing kcm-completion.bash from $HOME/.local/bin"
|
log_and_run rm $HOME/.local/bin/kcm-completion.bash
|
||||||
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
|
|
||||||
fi
|
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
|
if [ -f /usr/share/bash-completion/completions/kcm ]; then
|
||||||
# Check root privileges
|
log_and_run rm /usr/share/bash-completion/completions/kcm
|
||||||
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
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f /usr/local/bin/kcm ]; then
|
if [ -f /usr/local/bin/kcm ]; then
|
||||||
# Check root privileges
|
log_and_run rm /usr/local/bin/kcm
|
||||||
if [ "$EUID" -ne 0 ]; then
|
fi
|
||||||
printfe "%s\n" "red" "Please run as root"
|
if [ -f /usr/local/share/kcm/kcm.version ]; then
|
||||||
exit 1
|
log_and_run rm /usr/local/share/kcm/kcm.version
|
||||||
fi
|
|
||||||
|
|
||||||
printfe "%s\n" "cyan" "Removing kcm from /usr/local/bin"
|
|
||||||
rm /usr/local/bin/kcm
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printfe "%s\n" "green" "Uninstall complete."
|
printfe "%s\n" "green" "Uninstall complete."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user