update
This commit is contained in:
@@ -99,13 +99,48 @@ fi
|
||||
|
||||
# Add sudo authorization (prevent duplicate entries)
|
||||
info "Setting up sudo authorization..."
|
||||
if ! sudo grep -q "/usr/bin/nmcli" /etc/sudoers; then
|
||||
echo -e "ALL ALL=(ALL) NOPASSWD: /usr/bin/nmcli, /usr/sbin/reboot\nwww-data ALL=(ALL) NOPASSWD: /usr/bin/git pull\nwww-data ALL=(ALL) NOPASSWD: /usr/bin/ssh\nwww-data ALL=(ALL) NOPASSWD: /usr/bin/python3 * www-data ALL=(ALL) NOPASSWD: /bin/systemctl * www-data ALL=(ALL) NOPASSWD: /var/www/nebuleair_pro_4g/*" | sudo tee -a /etc/sudoers > /dev/null
|
||||
success "Sudo authorization added."
|
||||
SUDOERS_FILE="/etc/sudoers"
|
||||
|
||||
# First, fix any existing syntax errors
|
||||
if sudo visudo -c 2>&1 | grep -q "syntax error"; then
|
||||
warning "Syntax error detected in sudoers file. Attempting to fix..."
|
||||
# Remove the problematic line if it exists
|
||||
sudo sed -i '/www-data ALL=(ALL) NOPASSWD: \/usr\/bin\/python3 \* www-data/d' "$SUDOERS_FILE"
|
||||
fi
|
||||
|
||||
# Add proper sudo rules (each on a separate line)
|
||||
if ! sudo grep -q "/usr/bin/nmcli" "$SUDOERS_FILE"; then
|
||||
# Create a temporary file with the new rules
|
||||
cat <<EOF | sudo tee /tmp/sudoers_additions > /dev/null
|
||||
# NebuleAir Pro 4G sudo rules
|
||||
ALL ALL=(ALL) NOPASSWD: /usr/bin/nmcli, /usr/sbin/reboot
|
||||
www-data ALL=(ALL) NOPASSWD: /usr/bin/git pull
|
||||
www-data ALL=(ALL) NOPASSWD: /usr/bin/ssh
|
||||
www-data ALL=(ALL) NOPASSWD: /usr/bin/python3 *
|
||||
www-data ALL=(ALL) NOPASSWD: /bin/systemctl *
|
||||
www-data ALL=(ALL) NOPASSWD: /var/www/nebuleair_pro_4g/*
|
||||
EOF
|
||||
|
||||
# Validate the temporary file
|
||||
if sudo visudo -c -f /tmp/sudoers_additions; then
|
||||
# Append to sudoers if valid
|
||||
sudo cat /tmp/sudoers_additions >> "$SUDOERS_FILE"
|
||||
success "Sudo authorization added."
|
||||
else
|
||||
error "Failed to add sudo rules - syntax validation failed."
|
||||
fi
|
||||
|
||||
# Clean up
|
||||
sudo rm -f /tmp/sudoers_additions
|
||||
else
|
||||
warning "Sudo authorization already set. Skipping."
|
||||
fi
|
||||
|
||||
# Validate sudoers file after changes
|
||||
if ! sudo visudo -c; then
|
||||
error "Sudoers file has syntax errors! Please fix manually with 'sudo visudo'"
|
||||
fi
|
||||
|
||||
# Open all UART serial ports (avoid duplication)
|
||||
info "Configuring UART serial ports..."
|
||||
if ! grep -q "enable_uart=1" /boot/firmware/config.txt; then
|
||||
@@ -128,6 +163,13 @@ success "I2C ports enabled."
|
||||
info "Creates sqlites databases..."
|
||||
/usr/bin/python3 /var/www/nebuleair_pro_4g/sqlite/create_db.py
|
||||
|
||||
# Final sudoers check
|
||||
if sudo visudo -c; then
|
||||
success "Sudoers file is valid."
|
||||
else
|
||||
error "Sudoers file has errors! System may not function correctly."
|
||||
fi
|
||||
|
||||
# Completion message
|
||||
success "Setup completed successfully!"
|
||||
info "System will reboot in 5 seconds..."
|
||||
|
||||
Reference in New Issue
Block a user