feat(scripts): add process check and interactive prompts (#230)
install.sh: - Add check_running_processes() function to detect running Vocalinux - Prompt user to kill processes before proceeding with installation - Auto-kill in non-interactive mode uninstall.sh: - Add confirmation prompt before killing processes - Add interactive prompt for keeping data (models, config) - Simplified --keep-data flag behavior (also keeps config) This prevents issues during install/upgrade when Vocalinux is still running, and gives users more control over data preservation.
This commit is contained in:
+48
-1
@@ -21,6 +21,52 @@ print_warning() {
|
||||
echo -e "\e[1;33m[WARNING]\e[0m $1"
|
||||
}
|
||||
|
||||
command_exists() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
check_running_processes() {
|
||||
local PIDS=$(pgrep -f "vocalinux" 2>/dev/null || true)
|
||||
|
||||
if [ -n "$PIDS" ]; then
|
||||
print_warning "Found running Vocalinux process(es): $PIDS"
|
||||
echo ""
|
||||
|
||||
if [[ "$NON_INTERACTIVE" == "yes" ]]; then
|
||||
print_info "Non-interactive mode: stopping Vocalinux automatically..."
|
||||
else
|
||||
read -p "Vocalinux must be stopped before installation. Kill running process(es)? (Y/n) " -n 1 -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Nn]$ ]]; then
|
||||
print_error "Cannot proceed with installation while Vocalinux is running."
|
||||
print_info "Please stop Vocalinux manually and run the installer again."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
print_info "Stopping Vocalinux..."
|
||||
echo "$PIDS" | xargs -r kill -TERM 2>/dev/null || true
|
||||
sleep 2
|
||||
|
||||
local REMAINING_PIDS=$(pgrep -f "vocalinux" 2>/dev/null || true)
|
||||
|
||||
if [ -n "$REMAINING_PIDS" ]; then
|
||||
print_warning "Some processes still running, forcing termination..."
|
||||
echo "$REMAINING_PIDS" | xargs -r kill -KILL 2>/dev/null || true
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
local FINAL_PIDS=$(pgrep -f "vocalinux" 2>/dev/null || true)
|
||||
if [ -n "$FINAL_PIDS" ]; then
|
||||
print_error "Could not terminate all Vocalinux processes: $FINAL_PIDS"
|
||||
print_error "Please manually kill these processes and run the installer again."
|
||||
exit 1
|
||||
else
|
||||
print_success "All Vocalinux processes stopped"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Parse command line arguments
|
||||
INSTALL_MODE="user"
|
||||
RUN_TESTS="no"
|
||||
@@ -140,7 +186,8 @@ print_info "Vocalinux Installer"
|
||||
print_info "=============================="
|
||||
echo ""
|
||||
|
||||
# Default to installing from latest stable release instead of main branch
|
||||
check_running_processes
|
||||
|
||||
INSTALL_TAG="${INSTALL_TAG:-v0.6.1-beta}"
|
||||
|
||||
# Check if running from within the vocalinux repo or remotely (via curl)
|
||||
|
||||
+20
-11
@@ -51,20 +51,24 @@ safe_remove() {
|
||||
kill_vocalinux_processes() {
|
||||
print_info "Checking for running Vocalinux processes..."
|
||||
|
||||
# Find and kill vocalinux processes
|
||||
local PIDS=$(pgrep -f "vocalinux" 2>/dev/null || true)
|
||||
|
||||
if [ -n "$PIDS" ]; then
|
||||
print_warning "Found running Vocalinux process(es): $PIDS"
|
||||
|
||||
if [[ "$NON_INTERACTIVE" != "yes" ]]; then
|
||||
read -p "Kill running Vocalinux process(es)? (Y/n) " -n 1 -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Nn]$ ]]; then
|
||||
print_warning "Processes not killed. Uninstallation may be incomplete."
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
print_info "Stopping Vocalinux..."
|
||||
|
||||
# Try graceful termination first
|
||||
echo "$PIDS" | xargs -r kill -TERM 2>/dev/null || true
|
||||
|
||||
# Wait a moment for processes to terminate
|
||||
sleep 2
|
||||
|
||||
# Check if any processes are still running
|
||||
local REMAINING_PIDS=$(pgrep -f "vocalinux" 2>/dev/null || true)
|
||||
|
||||
if [ -n "$REMAINING_PIDS" ]; then
|
||||
@@ -73,7 +77,6 @@ kill_vocalinux_processes() {
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
# Final check
|
||||
local FINAL_PIDS=$(pgrep -f "vocalinux" 2>/dev/null || true)
|
||||
if [ -n "$FINAL_PIDS" ]; then
|
||||
print_error "Warning: Could not terminate all Vocalinux processes: $FINAL_PIDS"
|
||||
@@ -149,16 +152,12 @@ CURL_INSTALL_DIR="$HOME/.local/share/vocalinux-install"
|
||||
CURL_VENV_DIR="$HOME/.local/share/vocalinux/venv"
|
||||
CURL_BIN_DIR="$HOME/.local/bin"
|
||||
|
||||
# Print uninstallation options
|
||||
echo "Uninstallation options:"
|
||||
echo "- Local virtual environment: $VENV_DIR"
|
||||
echo "- Curl-installed venv: $CURL_VENV_DIR"
|
||||
echo "- Curl-installed repo: $CURL_INSTALL_DIR"
|
||||
[[ "$KEEP_CONFIG" == "yes" ]] && echo "- Keeping configuration files"
|
||||
[[ "$KEEP_DATA" == "yes" ]] && echo "- Keeping application data"
|
||||
echo
|
||||
|
||||
# Ask for confirmation
|
||||
if [[ "$NON_INTERACTIVE" == "yes" ]]; then
|
||||
print_info "Non-interactive mode: proceeding with uninstallation..."
|
||||
else
|
||||
@@ -168,6 +167,16 @@ else
|
||||
print_info "Uninstallation cancelled."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "$KEEP_DATA" != "yes" ]]; then
|
||||
read -p "Do you want to keep your data (models, config)? (y/N) " -n 1 -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
KEEP_DATA="yes"
|
||||
KEEP_CONFIG="yes"
|
||||
print_info "Data and configuration will be preserved."
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Function to handle virtual environment removal
|
||||
|
||||
Reference in New Issue
Block a user