update to add sudo in env

This commit is contained in:
Ryahn 2025-02-23 16:58:00 -06:00
parent ed24fcc5ba
commit b1e22b7590

View File

@ -43,6 +43,16 @@ if [ -z "$MYSQL_ADMIN_USER" ]; then
exit 1 exit 1
fi fi
sudo_cmd() {
echo "$SUDO_PASSWORD" | sudo -S "$@" 2>/dev/null
}
# Test sudo access
if ! sudo_cmd true; then
echo "Error: Invalid sudo password"
exit 1
fi
# Database configuration # Database configuration
DB_NAME="tempmail" DB_NAME="tempmail"
DB_USER="tempmail" DB_USER="tempmail"
@ -51,8 +61,8 @@ DB_PASS=$(openssl rand -base64 12) # Generate random password
# Check if mysql-server is installed # Check if mysql-server is installed
if ! command -v mysql &> /dev/null; then if ! command -v mysql &> /dev/null; then
log_warn "MySQL Server not found. Installing..." log_warn "MySQL Server not found. Installing..."
sudo apt-get update >> /dev/null 2>&1 sudo_cmd apt-get update >> /dev/null 2>&1
sudo apt-get install -y mysql-server >> /dev/null 2>&1 sudo_cmd apt-get install -y mysql-server >> /dev/null 2>&1
else else
log_info "MySQL Server is already installed" log_info "MySQL Server is already installed"
fi fi
@ -90,18 +100,18 @@ fi
# Create group and user # Create group and user
log_info "Creating group and user..." log_info "Creating group and user..."
sudo groupadd smtp 2>/dev/null || true sudo_cmd groupadd smtp 2>/dev/null || true
sudo useradd -r -g smtp smtp 2>/dev/null || true sudo_cmd useradd -r -g smtp smtp 2>/dev/null || true
# Create required directories # Create required directories
log_info "Creating required directories..." log_info "Creating required directories..."
sudo mkdir -p /var/spool/haraka /var/log/haraka sudo_cmd mkdir -p /var/spool/haraka /var/log/haraka
sudo chown -R smtp:smtp /var/spool/haraka /var/log/haraka sudo_cmd chown -R smtp:smtp /var/spool/haraka /var/log/haraka
# Set permissions # Set permissions
log_info "Setting permissions..." log_info "Setting permissions..."
sudo chmod 755 /var/spool/haraka sudo_cmd chmod 755 /var/spool/haraka
sudo chmod 644 /var/log/haraka sudo_cmd chmod 644 /var/log/haraka
# Install Haraka # Install Haraka
log_info "Installing Haraka..." log_info "Installing Haraka..."
@ -120,19 +130,19 @@ if [ -f "$SERVICE_PATH" ]; then
if [ "$REMOTE_CHECKSUM" != "$LOCAL_CHECKSUM" ]; then if [ "$REMOTE_CHECKSUM" != "$LOCAL_CHECKSUM" ]; then
log_warn "Service file differs from local version. Updating..." log_warn "Service file differs from local version. Updating..."
sudo cp "$LOCAL_SERVICE_PATH" "$SERVICE_PATH" sudo_cmd cp "$LOCAL_SERVICE_PATH" "$SERVICE_PATH"
sudo systemctl daemon-reload sudo_cmd systemctl daemon-reload
sudo systemctl enable haraka sudo_cmd systemctl enable haraka
sudo systemctl restart haraka sudo_cmd systemctl restart haraka
else else
log_info "Service file is up to date" log_info "Service file is up to date"
fi fi
else else
log_info "Service file not found. Installing..." log_info "Service file not found. Installing..."
sudo cp "$LOCAL_SERVICE_PATH" "$SERVICE_PATH" sudo_cmd cp "$LOCAL_SERVICE_PATH" "$SERVICE_PATH"
sudo systemctl daemon-reload sudo_cmd systemctl daemon-reload
log_info "Enabling and starting Haraka..." log_info "Enabling and starting Haraka..."
sudo systemctl enable haraka sudo_cmd systemctl enable haraka
fi fi
# Install Haraka plugins # Install Haraka plugins