more install things
This commit is contained in:
37
install.sh
37
install.sh
@@ -16,8 +16,6 @@ NC='\033[0m' # No Color
|
||||
INSTALL_DIR="/opt/video_player"
|
||||
CONFIG_DIR="/etc/video_player"
|
||||
SERVICE_NAME="video-player"
|
||||
USER="pi"
|
||||
VIDEO_FOLDER="${VIDEO_FOLDER:-/home/pi/Videos}"
|
||||
|
||||
# Function to print colored output
|
||||
print_status() {
|
||||
@@ -36,6 +34,25 @@ print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# Load environment variables from .env file if it exists
|
||||
if [[ -f ".env" ]]; then
|
||||
print_status "Loading configuration from .env file..."
|
||||
source .env
|
||||
else
|
||||
print_warning "No .env file found, using default values"
|
||||
# Create .env file from template if it doesn't exist
|
||||
if [[ -f "templates/env.template" ]]; then
|
||||
cp templates/env.template .env
|
||||
print_status "Created .env file from template. Please review and modify as needed."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Set defaults if not defined in .env
|
||||
USER="${USER:-pi}"
|
||||
GROUP="${GROUP:-pi}"
|
||||
VIDEO_FOLDER="${VIDEO_FOLDER:-/home/pi/Videos}"
|
||||
GPIO_GROUP="${GPIO_GROUP:-gpio}"
|
||||
|
||||
# Function to check if running as root
|
||||
check_root() {
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
@@ -182,10 +199,18 @@ copy_files() {
|
||||
cp usb_automount.sh "$INSTALL_DIR/"
|
||||
chmod +x "$INSTALL_DIR/usb_automount.sh"
|
||||
|
||||
# Copy service files
|
||||
# Copy service files and customize them
|
||||
cp video-player.service /etc/systemd/system/
|
||||
cp usb-automount.service /etc/systemd/system/
|
||||
|
||||
# Update service files with correct user/group and environment variables
|
||||
sed -i "s/User=root/User=$USER/g" /etc/systemd/system/video-player.service
|
||||
sed -i "s/Group=root/Group=$GROUP/g" /etc/systemd/system/video-player.service
|
||||
sed -i "s/SupplementaryGroups=gpio/SupplementaryGroups=$GPIO_GROUP/g" /etc/systemd/system/video-player.service
|
||||
sed -i "s|Environment=XAUTHORITY=/home/pi/.Xauthority|Environment=XAUTHORITY=/home/$USER/.Xauthority|g" /etc/systemd/system/video-player.service
|
||||
sed -i "s/User=root/User=$USER/g" /etc/systemd/system/usb-automount.service
|
||||
sed -i "s/Group=root/Group=$GROUP/g" /etc/systemd/system/usb-automount.service
|
||||
|
||||
# Copy configuration templates
|
||||
mkdir -p "$CONFIG_DIR/templates"
|
||||
cp templates/* "$CONFIG_DIR/templates/" 2>/dev/null || true
|
||||
@@ -368,12 +393,12 @@ setup_gpio_permissions() {
|
||||
print_status "Setting up GPIO permissions..."
|
||||
|
||||
# Add user to gpio group
|
||||
usermod -a -G gpio "$USER"
|
||||
usermod -a -G "$GPIO_GROUP" "$USER"
|
||||
|
||||
# Create udev rule for GPIO access
|
||||
cat > /etc/udev/rules.d/99-gpio.rules << EOF
|
||||
SUBSYSTEM=="gpio", GROUP="gpio", MODE="0664"
|
||||
SUBSYSTEM=="gpio*", PROGRAM="/bin/sh -c 'chown -R root:gpio /sys/class/gpio && chmod -R 775 /sys/class/gpio; chown -R root:gpio /sys/devices/virtual/gpio && chmod -R 775 /sys/devices/virtual/gpio'"
|
||||
SUBSYSTEM=="gpio", GROUP="$GPIO_GROUP", MODE="0664"
|
||||
SUBSYSTEM=="gpio*", PROGRAM="/bin/sh -c 'chown -R root:$GPIO_GROUP /sys/class/gpio && chmod -R 775 /sys/class/gpio; chown -R root:$GPIO_GROUP /sys/devices/virtual/gpio && chmod -R 775 /sys/devices/virtual/gpio'"
|
||||
EOF
|
||||
|
||||
# Reload udev rules
|
||||
|
||||
Reference in New Issue
Block a user