295 lines
7.9 KiB
Bash
Executable File
295 lines
7.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Raspberry Pi Video Player Auto-Start Uninstallation Script
|
|
# This script removes the video player system
|
|
|
|
set -e # Exit on any error
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Configuration
|
|
INSTALL_DIR="/opt/video_player"
|
|
CONFIG_DIR="/etc/video_player"
|
|
SERVICE_NAME="video-player"
|
|
USER="pi"
|
|
|
|
# Function to print colored output
|
|
print_status() {
|
|
echo -e "${BLUE}[INFO]${NC} $1"
|
|
}
|
|
|
|
print_success() {
|
|
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
|
}
|
|
|
|
print_warning() {
|
|
echo -e "${YELLOW}[WARNING]${NC} $1"
|
|
}
|
|
|
|
print_error() {
|
|
echo -e "${RED}[ERROR]${NC} $1"
|
|
}
|
|
|
|
# Function to check if running as root
|
|
check_root() {
|
|
if [[ $EUID -ne 0 ]]; then
|
|
print_error "This script must be run as root (use sudo)"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Function to confirm uninstallation
|
|
confirm_uninstall() {
|
|
print_warning "This will completely remove the Video Player system."
|
|
print_warning "All configuration files and data will be deleted."
|
|
echo
|
|
read -p "Are you sure you want to continue? (y/N): " -r response
|
|
if [[ ! "$response" =~ ^[Yy]$ ]]; then
|
|
print_status "Uninstallation cancelled"
|
|
exit 0
|
|
fi
|
|
}
|
|
|
|
# Function to stop and disable service
|
|
stop_service() {
|
|
print_status "Stopping and disabling service..."
|
|
|
|
# Stop service if running
|
|
if systemctl is-active --quiet "$SERVICE_NAME"; then
|
|
systemctl stop "$SERVICE_NAME"
|
|
print_status "Service stopped"
|
|
fi
|
|
|
|
# Disable service
|
|
if systemctl is-enabled --quiet "$SERVICE_NAME"; then
|
|
systemctl disable "$SERVICE_NAME"
|
|
print_status "Service disabled"
|
|
fi
|
|
|
|
print_success "Service stopped and disabled"
|
|
}
|
|
|
|
# Function to remove service file
|
|
remove_service_file() {
|
|
print_status "Removing service file..."
|
|
|
|
if [[ -f "/etc/systemd/system/$SERVICE_NAME.service" ]]; then
|
|
rm -f "/etc/systemd/system/$SERVICE_NAME.service"
|
|
systemctl daemon-reload
|
|
print_success "Service file removed"
|
|
else
|
|
print_warning "Service file not found"
|
|
fi
|
|
}
|
|
|
|
# Function to remove application files
|
|
remove_application_files() {
|
|
print_status "Removing application files..."
|
|
|
|
if [[ -d "$INSTALL_DIR" ]]; then
|
|
rm -rf "$INSTALL_DIR"
|
|
print_success "Application files removed"
|
|
else
|
|
print_warning "Installation directory not found"
|
|
fi
|
|
}
|
|
|
|
# Function to remove configuration files
|
|
remove_config_files() {
|
|
print_status "Removing configuration files..."
|
|
|
|
if [[ -d "$CONFIG_DIR" ]]; then
|
|
rm -rf "$CONFIG_DIR"
|
|
print_success "Configuration files removed"
|
|
else
|
|
print_warning "Configuration directory not found"
|
|
fi
|
|
}
|
|
|
|
# Function to remove management scripts
|
|
remove_management_scripts() {
|
|
print_status "Removing management scripts..."
|
|
|
|
local scripts=(
|
|
"video-player-start"
|
|
"video-player-stop"
|
|
"video-player-restart"
|
|
"video-player-status"
|
|
"video-player-logs"
|
|
)
|
|
|
|
for script in "${scripts[@]}"; do
|
|
if [[ -f "/usr/local/bin/$script" ]]; then
|
|
rm -f "/usr/local/bin/$script"
|
|
fi
|
|
done
|
|
|
|
print_success "Management scripts removed"
|
|
}
|
|
|
|
# Function to remove desktop shortcut
|
|
remove_desktop_shortcut() {
|
|
print_status "Removing desktop shortcut..."
|
|
|
|
local desktop_file="/home/$USER/Desktop/Video Player.desktop"
|
|
if [[ -f "$desktop_file" ]]; then
|
|
rm -f "$desktop_file"
|
|
print_success "Desktop shortcut removed"
|
|
else
|
|
print_warning "Desktop shortcut not found"
|
|
fi
|
|
}
|
|
|
|
# Function to remove log files
|
|
remove_log_files() {
|
|
print_status "Removing log files..."
|
|
|
|
if [[ -f "/var/log/video_player.log" ]]; then
|
|
rm -f "/var/log/video_player.log"
|
|
print_success "Log files removed"
|
|
else
|
|
print_warning "Log files not found"
|
|
fi
|
|
}
|
|
|
|
# Function to remove GPIO udev rules
|
|
remove_gpio_rules() {
|
|
print_status "Removing GPIO udev rules..."
|
|
|
|
if [[ -f "/etc/udev/rules.d/99-gpio.rules" ]]; then
|
|
rm -f "/etc/udev/rules.d/99-gpio.rules"
|
|
udevadm control --reload-rules
|
|
udevadm trigger
|
|
print_success "GPIO udev rules removed"
|
|
else
|
|
print_warning "GPIO udev rules not found"
|
|
fi
|
|
}
|
|
|
|
# Function to remove user from gpio group
|
|
remove_gpio_group() {
|
|
print_status "Removing user from gpio group..."
|
|
|
|
if groups "$USER" | grep -q "gpio"; then
|
|
gpasswd -d "$USER" gpio
|
|
print_success "User removed from gpio group"
|
|
else
|
|
print_warning "User not in gpio group"
|
|
fi
|
|
}
|
|
|
|
# Function to ask about video files
|
|
ask_about_video_files() {
|
|
local video_folder="/home/pi/Videos"
|
|
|
|
if [[ -d "$video_folder" ]]; then
|
|
local video_count=$(find "$video_folder" -name "*.mp4" -o -name "*.avi" -o -name "*.mkv" -o -name "*.mov" | wc -l)
|
|
|
|
if [[ $video_count -gt 0 ]]; then
|
|
print_warning "Found $video_count video files in $video_folder"
|
|
read -p "Do you want to remove all video files? (y/N): " -r response
|
|
if [[ "$response" =~ ^[Yy]$ ]]; then
|
|
rm -f "$video_folder"/*.mp4 "$video_folder"/*.avi "$video_folder"/*.mkv "$video_folder"/*.mov
|
|
print_success "Video files removed"
|
|
else
|
|
print_status "Video files preserved"
|
|
fi
|
|
fi
|
|
fi
|
|
}
|
|
|
|
# Function to ask about Python packages
|
|
ask_about_python_packages() {
|
|
print_warning "The following Python packages were installed for this application:"
|
|
echo " - python-vlc"
|
|
echo " - python-dotenv"
|
|
echo " - psutil"
|
|
echo " - PyYAML"
|
|
echo " - RPi.GPIO"
|
|
echo " - pigpio"
|
|
echo " - lirc"
|
|
echo
|
|
read -p "Do you want to remove these Python packages? (y/N): " -r response
|
|
if [[ "$response" =~ ^[Yy]$ ]]; then
|
|
print_status "Removing Python packages..."
|
|
pip3 uninstall -y python-vlc python-dotenv psutil PyYAML RPi.GPIO pigpio lirc 2>/dev/null || true
|
|
print_success "Python packages removed"
|
|
else
|
|
print_status "Python packages preserved"
|
|
fi
|
|
}
|
|
|
|
# Function to ask about system packages
|
|
ask_about_system_packages() {
|
|
print_warning "The following system packages were installed for this application:"
|
|
echo " - vlc"
|
|
echo " - python3-rpi.gpio"
|
|
echo " - i2c-tools"
|
|
echo " - spi-tools"
|
|
echo
|
|
read -p "Do you want to remove these system packages? (y/N): " -r response
|
|
if [[ "$response" =~ ^[Yy]$ ]]; then
|
|
print_status "Removing system packages..."
|
|
apt-get remove -y vlc python3-rpi.gpio i2c-tools spi-tools 2>/dev/null || true
|
|
apt-get autoremove -y 2>/dev/null || true
|
|
print_success "System packages removed"
|
|
else
|
|
print_status "System packages preserved"
|
|
fi
|
|
}
|
|
|
|
# Function to display uninstallation summary
|
|
display_summary() {
|
|
print_success "Uninstallation completed successfully!"
|
|
echo
|
|
echo "Removed Components:"
|
|
echo "==================="
|
|
echo "✓ Service and systemd configuration"
|
|
echo "✓ Application files"
|
|
echo "✓ Configuration files"
|
|
echo "✓ Management scripts"
|
|
echo "✓ Desktop shortcut"
|
|
echo "✓ Log files"
|
|
echo "✓ GPIO udev rules"
|
|
echo "✓ User group membership"
|
|
echo
|
|
echo "The Video Player system has been completely removed."
|
|
echo "You may need to reboot for all changes to take effect."
|
|
}
|
|
|
|
# Main uninstallation function
|
|
main() {
|
|
echo "Raspberry Pi Video Player Auto-Start Uninstallation"
|
|
echo "==================================================="
|
|
echo
|
|
|
|
check_root
|
|
confirm_uninstall
|
|
|
|
print_status "Starting uninstallation..."
|
|
|
|
stop_service
|
|
remove_service_file
|
|
remove_application_files
|
|
remove_config_files
|
|
remove_management_scripts
|
|
remove_desktop_shortcut
|
|
remove_log_files
|
|
remove_gpio_rules
|
|
remove_gpio_group
|
|
|
|
ask_about_video_files
|
|
ask_about_python_packages
|
|
ask_about_system_packages
|
|
|
|
display_summary
|
|
}
|
|
|
|
# Run main function
|
|
main "$@"
|