mirror of
https://github.com/amir1376/ab-download-manager.git
synced 2025-02-20 11:43:24 +08:00
Update: changes for rm and pkill the app pid (#285)
* Update: changes for rm and pkill the app pid
This commit is contained in:
parent
df722c3079
commit
4367495931
@ -43,7 +43,7 @@ in order to download and install the app
|
|||||||
### installation script (Linux)
|
### installation script (Linux)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -fsSL https://raw.githubusercontent.com/amir1376/ab-download-manager/master/scripts/install.sh | bash
|
bash <(curl -fsSL https://raw.githubusercontent.com/amir1376/ab-download-manager/master/scripts/install.sh)
|
||||||
```
|
```
|
||||||
|
|
||||||
### winget or scoop (for Windows)
|
### winget or scoop (for Windows)
|
||||||
@ -60,14 +60,12 @@ winget install amir1376.ABDownloadManager
|
|||||||
scoop install extras/abdownloadmanager
|
scoop install extras/abdownloadmanager
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Uninstall
|
## Uninstall
|
||||||
|
|
||||||
perform below command to uninstall
|
perform below command to uninstall
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -fsSL https://raw.githubusercontent.com/amir1376/ab-download-manager/master/scripts/uninstall.sh | bash
|
bash <(curl -fsSL https://raw.githubusercontent.com/amir1376/ab-download-manager/master/scripts/uninstall.sh)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Screenshots
|
## Screenshots
|
||||||
|
@ -14,13 +14,29 @@ logger() {
|
|||||||
|
|
||||||
if [[ "$1" == "error" ]]; then
|
if [[ "$1" == "error" ]]; then
|
||||||
# Red color for errors
|
# Red color for errors
|
||||||
echo -e "${timestamp} -- "$0" [Error]: \033[0;31m$@\033[0m" | tee -a ${LOG_FILE}
|
echo -e "${timestamp} -- ABDM-Installer [Error]: \033[0;31m$@\033[0m" | tee -a ${LOG_FILE}
|
||||||
else
|
else
|
||||||
# Default color for non-error messages
|
# Default color for non-error messages
|
||||||
echo -e "${timestamp} -- "$0" [Info]: $@" | tee -a ${LOG_FILE}
|
echo -e "${timestamp} -- ABDM-Installer [Info]: $@" | tee -a ${LOG_FILE}
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
remove_if_exists() {
|
||||||
|
local target="$1"
|
||||||
|
|
||||||
|
if [ -z "$target" ]; then
|
||||||
|
logger "No target specified in remove_if_exists function"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -e "$target" ]; then
|
||||||
|
logger "File \"$target\" Removed"
|
||||||
|
rm -rf "$target"
|
||||||
|
else
|
||||||
|
logger "File \"$target\" does not exist"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# --- Detect OS and The Package Manager to use
|
# --- Detect OS and The Package Manager to use
|
||||||
detect_package_manager() {
|
detect_package_manager() {
|
||||||
if [ -f /etc/os-release ]; then
|
if [ -f /etc/os-release ]; then
|
||||||
@ -101,11 +117,39 @@ BINARY_PATH="$HOME/.local/$APP_NAME/bin/$APP_NAME"
|
|||||||
|
|
||||||
# --- Delete the old version Application if exists
|
# --- Delete the old version Application if exists
|
||||||
delete_old_version() {
|
delete_old_version() {
|
||||||
# --- Killing Any Application Process
|
# Find the PID(s) of the application
|
||||||
pkill -f "$APP_NAME"
|
PIDS=$(pidof "$APP_NAME") || true
|
||||||
rm -rf "$HOME/.local/$APP_NAME"
|
|
||||||
rm -rf "$HOME/.local/bin/$APP_NAME"
|
if [ -n "$PIDS" ]; then
|
||||||
logger "removed old version AB Download Manager"
|
echo "Found $APP_NAME with PID(s): $PIDS. Attempting to kill..."
|
||||||
|
|
||||||
|
# Attempt to terminate the process gracefully
|
||||||
|
kill $PIDS 2>/dev/null || echo "Graceful kill failed..."
|
||||||
|
|
||||||
|
# Wait for a short period to allow graceful shutdown
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
# Check if the process is still running
|
||||||
|
PIDS=$(pidof "$APP_NAME") || true
|
||||||
|
if [ -n "$PIDS" ]; then
|
||||||
|
echo "Process still running. Force killing..."
|
||||||
|
kill -9 $PIDS 2>/dev/null || echo "Force kill failed..."
|
||||||
|
else
|
||||||
|
echo "$APP_NAME terminated successfully."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "$APP_NAME is not running."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove old version directories
|
||||||
|
# First Remove link to "$HOME/.local/$APP_NAME"
|
||||||
|
remove_if_exists "$HOME/.local/bin/$APP_NAME"
|
||||||
|
# then Remove the main binary files directory
|
||||||
|
remove_if_exists "$HOME/.local/$APP_NAME"
|
||||||
|
|
||||||
|
|
||||||
|
# Log the removal action
|
||||||
|
logger "Removed old version of $APP_NAME"
|
||||||
}
|
}
|
||||||
|
|
||||||
# --- Generate a .desktop file for the app
|
# --- Generate a .desktop file for the app
|
||||||
@ -127,7 +171,7 @@ EOF
|
|||||||
# --- Download the latest version of the app
|
# --- Download the latest version of the app
|
||||||
download_zip() {
|
download_zip() {
|
||||||
# Remove the app tarball if it exists in /tmp
|
# Remove the app tarball if it exists in /tmp
|
||||||
rm -f "/tmp/$ASSET_NAME"
|
remove_if_exists "/tmp/$ASSET_NAME"
|
||||||
|
|
||||||
logger "downloading AB Download Manager ..."
|
logger "downloading AB Download Manager ..."
|
||||||
# Perform the download with curl
|
# Perform the download with curl
|
||||||
@ -135,9 +179,9 @@ download_zip() {
|
|||||||
logger "download finished successfully"
|
logger "download finished successfully"
|
||||||
else
|
else
|
||||||
logger error "Download failed! Something Went Wrong"
|
logger error "Download failed! Something Went Wrong"
|
||||||
logger error "Hint: Check Your Internet Connectivity"
|
logger error "Check Your Internet Connectivity"
|
||||||
# Optionally remove the partially downloaded file
|
# Optionally remove the partially downloaded file
|
||||||
rm -f "/tmp/$ASSET_NAME"
|
remove_if_exists "/tmp/$ASSET_NAME"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,10 +195,10 @@ install_app() {
|
|||||||
tar -xzf "/tmp/$ASSET_NAME" -C "$HOME/.local"
|
tar -xzf "/tmp/$ASSET_NAME" -C "$HOME/.local"
|
||||||
|
|
||||||
# --- remove tarball after installation
|
# --- remove tarball after installation
|
||||||
rm "/tmp/$ASSET_NAME"
|
remove_if_exists "/tmp/$ASSET_NAME"
|
||||||
|
|
||||||
# Link the binary to ~/.local/bin
|
# Link the binary to ~/.local/bin
|
||||||
ln -s "$BINARY_PATH" "$HOME/.local/bin/$APP_NAME"
|
ln -sf "$BINARY_PATH" "$HOME/.local/bin/$APP_NAME"
|
||||||
|
|
||||||
# Create a .desktop file in ~/.local/share/applications
|
# Create a .desktop file in ~/.local/share/applications
|
||||||
generate_desktop_file
|
generate_desktop_file
|
||||||
|
@ -14,13 +14,29 @@ logger() {
|
|||||||
|
|
||||||
if [[ "$1" == "error" ]]; then
|
if [[ "$1" == "error" ]]; then
|
||||||
# Red color for errors
|
# Red color for errors
|
||||||
echo -e "${timestamp} -- "$0" [Error]: \033[0;31m$@\033[0m" | tee -a ${LOG_FILE}
|
echo -e "${timestamp} -- ABDM-Uninstaller [Error]: \033[0;31m$@\033[0m" | tee -a ${LOG_FILE}
|
||||||
else
|
else
|
||||||
# Default color for non-error messages
|
# Default color for non-error messages
|
||||||
echo -e "${timestamp} -- "$0" [Info]: $@" | tee -a ${LOG_FILE}
|
echo -e "${timestamp} -- ABDM-Uninstaller [Info]: $@" | tee -a ${LOG_FILE}
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
remove_if_exists() {
|
||||||
|
local target="$1"
|
||||||
|
|
||||||
|
if [ -z "$target" ]; then
|
||||||
|
logger "No target specified in remove_if_exists function"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -e "$target" ]; then
|
||||||
|
logger "File \"$target\" Removed"
|
||||||
|
rm -rf "$target"
|
||||||
|
else
|
||||||
|
logger "File \"$target\" does not exist"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
delete_app_config_dir() {
|
delete_app_config_dir() {
|
||||||
|
|
||||||
local answer
|
local answer
|
||||||
@ -29,8 +45,7 @@ delete_app_config_dir() {
|
|||||||
|
|
||||||
case $answer in
|
case $answer in
|
||||||
[Yy]* )
|
[Yy]* )
|
||||||
rm -rf "$HOME/.abdm"
|
remove_if_exists "$HOME/.abdm"
|
||||||
logger "$APP_NAME settings and download lists directory: $HOME/.abdm removed."
|
|
||||||
;;
|
;;
|
||||||
[Nn]* )
|
[Nn]* )
|
||||||
logger "Remove The $HOME/.abdm directory manually."
|
logger "Remove The $HOME/.abdm directory manually."
|
||||||
@ -44,25 +59,47 @@ delete_app_config_dir() {
|
|||||||
|
|
||||||
delete_app() {
|
delete_app() {
|
||||||
|
|
||||||
logger "Killing Any $APP_NAME Processes ..."
|
# Find the PID(s) of the application
|
||||||
pkill -f "$APP_NAME"
|
PIDS=$(pidof "$APP_NAME") || true
|
||||||
|
|
||||||
|
if [ -n "$PIDS" ]; then
|
||||||
|
echo "Found $APP_NAME with PID(s): $PIDS. Attempting to kill..."
|
||||||
|
|
||||||
|
# Attempt to terminate the process gracefully
|
||||||
|
kill $PIDS 2>/dev/null || echo "Graceful kill failed..."
|
||||||
|
|
||||||
|
# Wait for a short period to allow graceful shutdown
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
# Check if the process is still running
|
||||||
|
PIDS=$(pidof "$APP_NAME") || true
|
||||||
|
if [ -n "$PIDS" ]; then
|
||||||
|
echo "Process still running. Force killing..."
|
||||||
|
kill -9 $PIDS 2>/dev/null || echo "Force kill failed..."
|
||||||
|
else
|
||||||
|
echo "$APP_NAME terminated successfully."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "$APP_NAME is not running."
|
||||||
|
fi
|
||||||
|
|
||||||
logger "removing $APP_NAME desktop file ..."
|
logger "removing $APP_NAME desktop file ..."
|
||||||
# --- Remove the .desktop file in ~/.local/share/applications
|
# --- Remove the .desktop file in ~/.local/share/applications
|
||||||
rm "$HOME/.local/share/applications/abdownloadmanager.desktop"
|
remove_if_exists "$HOME/.local/share/applications/abdownloadmanager.desktop"
|
||||||
|
|
||||||
logger "unlinking $APP_NAME link ..."
|
logger "removing $APP_NAME link ..."
|
||||||
unlink "$HOME/.local/bin/$APP_NAME"
|
remove_if_exists "$HOME/.local/bin/$APP_NAME"
|
||||||
|
|
||||||
logger "removing $APP_NAME binary ..."
|
logger "removing $APP_NAME binary ..."
|
||||||
rm -rf "$HOME/.local/$APP_NAME"
|
remove_if_exists "$HOME/.local/$APP_NAME"
|
||||||
rm -rf "$HOME/.local/bin/$APP_NAME"
|
|
||||||
|
|
||||||
logger "removing $APP_NAME autostart at boot file ..."
|
logger "removing $APP_NAME autostart at boot file ..."
|
||||||
rm -f "$HOME/.config/autostart/AB Download Manager.desktop"
|
remove_if_exists "$HOME/.config/autostart/AB Download Manager.desktop"
|
||||||
|
|
||||||
logger "removing $APP_NAME settings and download lists"
|
if [ -e "$HOME/.abdm" ]; then
|
||||||
delete_app_config_dir
|
logger "removing $APP_NAME settings and download lists $HOME/.abdm"
|
||||||
|
delete_app_config_dir
|
||||||
|
fi
|
||||||
|
|
||||||
logger "AB Download Manager completely removed"
|
logger "AB Download Manager completely removed"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user