more install things
This commit is contained in:
135
ENV_SETUP.md
Normal file
135
ENV_SETUP.md
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
# Environment Configuration Setup
|
||||||
|
|
||||||
|
This document explains how to configure the Video Player system using environment variables.
|
||||||
|
|
||||||
|
## Environment File Setup
|
||||||
|
|
||||||
|
The system now supports reading configuration from a `.env` file. This allows you to customize the user, group, and other settings without modifying the installation scripts.
|
||||||
|
|
||||||
|
### Creating the Environment File
|
||||||
|
|
||||||
|
1. Copy the template file:
|
||||||
|
```bash
|
||||||
|
cp templates/env.template .env
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Edit the `.env` file with your preferred settings:
|
||||||
|
```bash
|
||||||
|
nano .env
|
||||||
|
```
|
||||||
|
|
||||||
|
### Available Configuration Variables
|
||||||
|
|
||||||
|
| Variable | Default | Description |
|
||||||
|
|----------|---------|-------------|
|
||||||
|
| `USER` | `pi` | System user to run the video player service |
|
||||||
|
| `GROUP` | `pi` | System group for the user |
|
||||||
|
| `VIDEO_FOLDER` | `/home/pi/Videos` | Directory containing video files |
|
||||||
|
| `SERVICE_NAME` | `video-player` | Name of the systemd service |
|
||||||
|
| `INSTALL_DIR` | `/opt/video_player` | Installation directory |
|
||||||
|
| `CONFIG_DIR` | `/etc/video_player` | Configuration directory |
|
||||||
|
| `GPIO_GROUP` | `gpio` | Group for GPIO access |
|
||||||
|
| `LOG_FILE` | `/var/log/video_player.log` | Log file path |
|
||||||
|
| `LOG_LEVEL` | `INFO` | Logging level |
|
||||||
|
| `DISPLAY` | `:0` | X11 display |
|
||||||
|
| `XAUTHORITY` | `/home/pi/.Xauthority` | X11 authority file |
|
||||||
|
|
||||||
|
### Example .env File
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# System User Configuration
|
||||||
|
USER=myuser
|
||||||
|
GROUP=myuser
|
||||||
|
|
||||||
|
# Video Configuration
|
||||||
|
VIDEO_FOLDER=/home/myuser/Videos
|
||||||
|
|
||||||
|
# Service Configuration
|
||||||
|
SERVICE_NAME=video-player
|
||||||
|
INSTALL_DIR=/opt/video_player
|
||||||
|
CONFIG_DIR=/etc/video_player
|
||||||
|
|
||||||
|
# GPIO Configuration
|
||||||
|
GPIO_GROUP=gpio
|
||||||
|
|
||||||
|
# Logging Configuration
|
||||||
|
LOG_FILE=/var/log/video_player.log
|
||||||
|
LOG_LEVEL=INFO
|
||||||
|
|
||||||
|
# Display Configuration
|
||||||
|
DISPLAY=:0
|
||||||
|
XAUTHORITY=/home/myuser/.Xauthority
|
||||||
|
```
|
||||||
|
|
||||||
|
## Installation Process
|
||||||
|
|
||||||
|
1. **Create your .env file** (as described above)
|
||||||
|
|
||||||
|
2. **Run the installation script**:
|
||||||
|
```bash
|
||||||
|
sudo ./install.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
The script will:
|
||||||
|
- Load configuration from your `.env` file
|
||||||
|
- Create the specified user and group if they don't exist
|
||||||
|
- Set up the service with the correct user/group
|
||||||
|
- Configure file permissions appropriately
|
||||||
|
|
||||||
|
3. **Verify the installation**:
|
||||||
|
```bash
|
||||||
|
video-player-test
|
||||||
|
```
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
### User/Group Issues
|
||||||
|
|
||||||
|
If you encounter permission errors:
|
||||||
|
|
||||||
|
1. Check that the user exists:
|
||||||
|
```bash
|
||||||
|
id $USER
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Check that the user is in the GPIO group:
|
||||||
|
```bash
|
||||||
|
groups $USER
|
||||||
|
```
|
||||||
|
|
||||||
|
3. If needed, manually add the user to the GPIO group:
|
||||||
|
```bash
|
||||||
|
sudo usermod -a -G gpio $USER
|
||||||
|
```
|
||||||
|
|
||||||
|
### Service Issues
|
||||||
|
|
||||||
|
If the service fails to start:
|
||||||
|
|
||||||
|
1. Check the service status:
|
||||||
|
```bash
|
||||||
|
sudo systemctl status video-player
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Check the logs:
|
||||||
|
```bash
|
||||||
|
sudo journalctl -u video-player -f
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Verify the service file has the correct user/group:
|
||||||
|
```bash
|
||||||
|
sudo systemctl cat video-player
|
||||||
|
```
|
||||||
|
|
||||||
|
## Uninstallation
|
||||||
|
|
||||||
|
To uninstall the system:
|
||||||
|
|
||||||
|
1. **Create your .env file** (if not already done)
|
||||||
|
|
||||||
|
2. **Run the uninstall script**:
|
||||||
|
```bash
|
||||||
|
sudo ./uninstall.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
The uninstall script will use the same configuration from your `.env` file to properly clean up the installation.
|
||||||
37
install.sh
37
install.sh
@@ -16,8 +16,6 @@ NC='\033[0m' # No Color
|
|||||||
INSTALL_DIR="/opt/video_player"
|
INSTALL_DIR="/opt/video_player"
|
||||||
CONFIG_DIR="/etc/video_player"
|
CONFIG_DIR="/etc/video_player"
|
||||||
SERVICE_NAME="video-player"
|
SERVICE_NAME="video-player"
|
||||||
USER="pi"
|
|
||||||
VIDEO_FOLDER="${VIDEO_FOLDER:-/home/pi/Videos}"
|
|
||||||
|
|
||||||
# Function to print colored output
|
# Function to print colored output
|
||||||
print_status() {
|
print_status() {
|
||||||
@@ -36,6 +34,25 @@ print_error() {
|
|||||||
echo -e "${RED}[ERROR]${NC} $1"
|
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
|
# Function to check if running as root
|
||||||
check_root() {
|
check_root() {
|
||||||
if [[ $EUID -ne 0 ]]; then
|
if [[ $EUID -ne 0 ]]; then
|
||||||
@@ -182,10 +199,18 @@ copy_files() {
|
|||||||
cp usb_automount.sh "$INSTALL_DIR/"
|
cp usb_automount.sh "$INSTALL_DIR/"
|
||||||
chmod +x "$INSTALL_DIR/usb_automount.sh"
|
chmod +x "$INSTALL_DIR/usb_automount.sh"
|
||||||
|
|
||||||
# Copy service files
|
# Copy service files and customize them
|
||||||
cp video-player.service /etc/systemd/system/
|
cp video-player.service /etc/systemd/system/
|
||||||
cp usb-automount.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
|
# Copy configuration templates
|
||||||
mkdir -p "$CONFIG_DIR/templates"
|
mkdir -p "$CONFIG_DIR/templates"
|
||||||
cp templates/* "$CONFIG_DIR/templates/" 2>/dev/null || true
|
cp templates/* "$CONFIG_DIR/templates/" 2>/dev/null || true
|
||||||
@@ -368,12 +393,12 @@ setup_gpio_permissions() {
|
|||||||
print_status "Setting up GPIO permissions..."
|
print_status "Setting up GPIO permissions..."
|
||||||
|
|
||||||
# Add user to gpio group
|
# Add user to gpio group
|
||||||
usermod -a -G gpio "$USER"
|
usermod -a -G "$GPIO_GROUP" "$USER"
|
||||||
|
|
||||||
# Create udev rule for GPIO access
|
# Create udev rule for GPIO access
|
||||||
cat > /etc/udev/rules.d/99-gpio.rules << EOF
|
cat > /etc/udev/rules.d/99-gpio.rules << EOF
|
||||||
SUBSYSTEM=="gpio", GROUP="gpio", MODE="0664"
|
SUBSYSTEM=="gpio", GROUP="$GPIO_GROUP", 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*", 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
|
EOF
|
||||||
|
|
||||||
# Reload udev rules
|
# Reload udev rules
|
||||||
|
|||||||
25
templates/env.template
Normal file
25
templates/env.template
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# Environment Configuration for Video Player System
|
||||||
|
# Copy this file to .env and modify the values as needed
|
||||||
|
|
||||||
|
# System User Configuration
|
||||||
|
USER=pi
|
||||||
|
GROUP=pi
|
||||||
|
|
||||||
|
# Video Configuration
|
||||||
|
VIDEO_FOLDER=/home/pi/Videos
|
||||||
|
|
||||||
|
# Service Configuration
|
||||||
|
SERVICE_NAME=video-player
|
||||||
|
INSTALL_DIR=/opt/video_player
|
||||||
|
CONFIG_DIR=/etc/video_player
|
||||||
|
|
||||||
|
# GPIO Configuration
|
||||||
|
GPIO_GROUP=gpio
|
||||||
|
|
||||||
|
# Logging Configuration
|
||||||
|
LOG_FILE=/var/log/video_player.log
|
||||||
|
LOG_LEVEL=INFO
|
||||||
|
|
||||||
|
# Display Configuration
|
||||||
|
DISPLAY=:0
|
||||||
|
XAUTHORITY=/home/pi/.Xauthority
|
||||||
18
uninstall.sh
18
uninstall.sh
@@ -16,7 +16,6 @@ NC='\033[0m' # No Color
|
|||||||
INSTALL_DIR="/opt/video_player"
|
INSTALL_DIR="/opt/video_player"
|
||||||
CONFIG_DIR="/etc/video_player"
|
CONFIG_DIR="/etc/video_player"
|
||||||
SERVICE_NAME="video-player"
|
SERVICE_NAME="video-player"
|
||||||
USER="pi"
|
|
||||||
|
|
||||||
# Function to print colored output
|
# Function to print colored output
|
||||||
print_status() {
|
print_status() {
|
||||||
@@ -35,6 +34,19 @@ print_error() {
|
|||||||
echo -e "${RED}[ERROR]${NC} $1"
|
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"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set defaults if not defined in .env
|
||||||
|
USER="${USER:-pi}"
|
||||||
|
GROUP="${GROUP:-pi}"
|
||||||
|
GPIO_GROUP="${GPIO_GROUP:-gpio}"
|
||||||
|
|
||||||
# Function to check if running as root
|
# Function to check if running as root
|
||||||
check_root() {
|
check_root() {
|
||||||
if [[ $EUID -ne 0 ]]; then
|
if [[ $EUID -ne 0 ]]; then
|
||||||
@@ -175,8 +187,8 @@ remove_gpio_rules() {
|
|||||||
remove_gpio_group() {
|
remove_gpio_group() {
|
||||||
print_status "Removing user from gpio group..."
|
print_status "Removing user from gpio group..."
|
||||||
|
|
||||||
if groups "$USER" | grep -q "gpio"; then
|
if groups "$USER" | grep -q "$GPIO_GROUP"; then
|
||||||
gpasswd -d "$USER" gpio
|
gpasswd -d "$USER" "$GPIO_GROUP"
|
||||||
print_success "User removed from gpio group"
|
print_success "User removed from gpio group"
|
||||||
else
|
else
|
||||||
print_warning "User not in gpio group"
|
print_warning "User not in gpio group"
|
||||||
|
|||||||
@@ -6,7 +6,14 @@
|
|||||||
# Configuration
|
# Configuration
|
||||||
MOUNT_BASE="/media/usb"
|
MOUNT_BASE="/media/usb"
|
||||||
LOG_FILE="/var/log/usb_automount.log"
|
LOG_FILE="/var/log/usb_automount.log"
|
||||||
USER="pi"
|
|
||||||
|
# Load environment variables from .env file if it exists
|
||||||
|
if [[ -f ".env" ]]; then
|
||||||
|
source .env
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set defaults if not defined in .env
|
||||||
|
USER="${USER:-pi}"
|
||||||
|
|
||||||
# Function to log messages
|
# Function to log messages
|
||||||
log_message() {
|
log_message() {
|
||||||
|
|||||||
Reference in New Issue
Block a user