117 lines
3.4 KiB
Bash
Executable File
117 lines
3.4 KiB
Bash
Executable File
#!/bin/bash
|
|
# SME Server Password Change Application Installation Script
|
|
# Compatible with Python 3.6.8 and Flask 2.0.3
|
|
|
|
set -e
|
|
|
|
# Configuration
|
|
APP_NAME="smeserver-password-app"
|
|
APP_DIR="/opt/$APP_NAME"
|
|
SERVICE_NAME="smeserver-password-web"
|
|
SERVICE_PORT=5000
|
|
PYTHON_BIN="/usr/bin/python3"
|
|
|
|
echo "Installing SME Server Password Change Application (Python 3.6.8 Compatible)..."
|
|
|
|
# Check if running as root
|
|
if [ "$EUID" -ne 0 ]; then
|
|
echo "Please run this script as root"
|
|
exit 1
|
|
fi
|
|
|
|
# Check if we're on an SME Server
|
|
if [ ! -f "/etc/e-smith-release" ] && [ ! -f "/etc/sme-release" ]; then
|
|
echo "Warning: This doesn't appear to be an SME Server system"
|
|
echo "The application may not work correctly without SME Server tools"
|
|
fi
|
|
|
|
# Check Python version
|
|
PYTHON_VERSION=$(python3 -c "import sys; print('{}.{}'.format(sys.version_info.major, sys.version_info.minor))")
|
|
echo "Detected Python version: $PYTHON_VERSION"
|
|
|
|
if [ "$PYTHON_VERSION" != "3.6" ]; then
|
|
echo "Warning: This application is optimized for Python 3.6.8"
|
|
echo "Current version: $PYTHON_VERSION"
|
|
echo "Continuing with installation..."
|
|
fi
|
|
|
|
# Create application directory
|
|
echo "Creating application directory..."
|
|
mkdir -p "$APP_DIR"
|
|
|
|
# Copy application files
|
|
echo "Copying application files..."
|
|
cp -r ./* "$APP_DIR/"
|
|
|
|
# Set permissions
|
|
echo "Setting permissions..."
|
|
chown -R root:root "$APP_DIR"
|
|
chmod +x "$APP_DIR/app.py"
|
|
chmod +x "$APP_DIR/install.sh"
|
|
|
|
# Install Python dependencies compatible with Python 3.6.8
|
|
echo "Installing Python dependencies (Python 3.6.8 compatible)..."
|
|
if command -v pip3 &> /dev/null; then
|
|
pip3 install Flask==2.0.3 Flask-CORS==3.0.10 Werkzeug==2.0.3
|
|
elif command -v yum &> /dev/null; then
|
|
yum install -y python3-pip
|
|
pip3 install Flask==2.0.3 Flask-CORS==3.0.10 Werkzeug==2.0.3
|
|
else
|
|
echo "Warning: Could not install Python dependencies automatically"
|
|
echo "Please install Flask 2.0.3 and Flask-CORS 3.0.10 manually"
|
|
fi
|
|
|
|
# Create systemd service file
|
|
echo "Creating systemd service..."
|
|
cat > "/etc/systemd/system/$SERVICE_NAME.service" << EOF
|
|
[Unit]
|
|
Description=SME Server Password Change Web Application
|
|
After=network.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
User=root
|
|
WorkingDirectory=$APP_DIR
|
|
Environment=FLASK_APP=app.py
|
|
Environment=FLASK_ENV=production
|
|
ExecStart=$PYTHON_BIN $APP_DIR/app.py
|
|
Restart=always
|
|
RestartSec=10
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
# Reload systemd and enable service
|
|
echo "Enabling service..."
|
|
systemctl daemon-reload
|
|
systemctl enable "$SERVICE_NAME"
|
|
|
|
# Start the service
|
|
echo "Starting service..."
|
|
systemctl start "$SERVICE_NAME"
|
|
|
|
# Check service status
|
|
if systemctl is-active --quiet "$SERVICE_NAME"; then
|
|
echo "✓ Service started successfully"
|
|
echo "✓ Password change application is running on port $SERVICE_PORT"
|
|
echo ""
|
|
echo "Access the application at: http://your-server-ip:$SERVICE_PORT"
|
|
echo ""
|
|
echo "Python 3.6.8 and Flask 2.0.3 compatibility confirmed"
|
|
echo ""
|
|
echo "To check service status: systemctl status $SERVICE_NAME"
|
|
echo "To view logs: journalctl -u $SERVICE_NAME -f"
|
|
echo "To stop service: systemctl stop $SERVICE_NAME"
|
|
echo "To restart service: systemctl restart $SERVICE_NAME"
|
|
else
|
|
echo "✗ Failed to start service"
|
|
echo "Check logs with: journalctl -u $SERVICE_NAME"
|
|
exit 1
|
|
fi
|
|
|
|
echo ""
|
|
echo "Installation completed successfully!"
|
|
echo "Application is compatible with Python 3.6.8 and Flask 2.0.3"
|
|
|