script
This commit is contained in:
		
							parent
							
								
									73ace5965f
								
							
						
					
					
						commit
						95ce48192b
					
				
							
								
								
									
										107
									
								
								deploy.sh
									
									
									
									
									
								
							
							
						
						
									
										107
									
								
								deploy.sh
									
									
									
									
									
								
							@ -34,26 +34,83 @@ if [ ! -f "package.json" ] || [ ! -f "astro.config.mjs" ]; then
 | 
			
		||||
    exit 1
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# Build application
 | 
			
		||||
echo "📦 Building application..."
 | 
			
		||||
if [ ! -d "node_modules" ]; then
 | 
			
		||||
    echo "📦 Installing dependencies..."
 | 
			
		||||
    sudo -u "$ORIGINAL_USER" npm install
 | 
			
		||||
fi
 | 
			
		||||
# Function to find and use npm
 | 
			
		||||
find_and_use_npm() {
 | 
			
		||||
    echo "🔍 Searching for npm installation..."
 | 
			
		||||
    
 | 
			
		||||
    # Try system npm first
 | 
			
		||||
    if command -v npm &> /dev/null; then
 | 
			
		||||
        echo "✅ Found system npm: $(which npm)"
 | 
			
		||||
        echo "📦 Installing dependencies..."
 | 
			
		||||
        sudo -u "$ORIGINAL_USER" npm install
 | 
			
		||||
        echo "📦 Building application..."
 | 
			
		||||
        sudo -u "$ORIGINAL_USER" npm run build
 | 
			
		||||
        return 0
 | 
			
		||||
    fi
 | 
			
		||||
    
 | 
			
		||||
    # Try nvm-installed npm
 | 
			
		||||
    echo "🔍 Checking for nvm installation..."
 | 
			
		||||
    if sudo -u "$ORIGINAL_USER" bash -c "
 | 
			
		||||
        export NVM_DIR='$ORIGINAL_HOME/.nvm'
 | 
			
		||||
        [ -s '\$NVM_DIR/nvm.sh' ] && source '\$NVM_DIR/nvm.sh'
 | 
			
		||||
        [ -s '$ORIGINAL_HOME/.bashrc' ] && source '$ORIGINAL_HOME/.bashrc'
 | 
			
		||||
        command -v npm &> /dev/null
 | 
			
		||||
    "; then
 | 
			
		||||
        echo "✅ Found nvm-managed npm"
 | 
			
		||||
        echo "📦 Installing dependencies with nvm..."
 | 
			
		||||
        sudo -u "$ORIGINAL_USER" bash -c "
 | 
			
		||||
            export NVM_DIR='$ORIGINAL_HOME/.nvm'
 | 
			
		||||
            [ -s '\$NVM_DIR/nvm.sh' ] && source '\$NVM_DIR/nvm.sh'
 | 
			
		||||
            [ -s '$ORIGINAL_HOME/.bashrc' ] && source '$ORIGINAL_HOME/.bashrc'
 | 
			
		||||
            npm install
 | 
			
		||||
        "
 | 
			
		||||
        echo "📦 Building application with nvm..."
 | 
			
		||||
        sudo -u "$ORIGINAL_USER" bash -c "
 | 
			
		||||
            export NVM_DIR='$ORIGINAL_HOME/.nvm'
 | 
			
		||||
            [ -s '\$NVM_DIR/nvm.sh' ] && source '\$NVM_DIR/nvm.sh'
 | 
			
		||||
            [ -s '$ORIGINAL_HOME/.bashrc' ] && source '$ORIGINAL_HOME/.bashrc'
 | 
			
		||||
            npm run build
 | 
			
		||||
        "
 | 
			
		||||
        return 0
 | 
			
		||||
    fi
 | 
			
		||||
    
 | 
			
		||||
    echo "❌ npm not found in system or user environment"
 | 
			
		||||
    echo ""
 | 
			
		||||
    echo "💡 Please install Node.js and npm first:"
 | 
			
		||||
    echo "   # Option 1: System package manager"
 | 
			
		||||
    echo "   sudo apt update && sudo apt install nodejs npm"
 | 
			
		||||
    echo ""
 | 
			
		||||
    echo "   # Option 2: NodeSource repository (recommended)"
 | 
			
		||||
    echo "   curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -"
 | 
			
		||||
    echo "   sudo apt-get install -y nodejs"
 | 
			
		||||
    echo ""
 | 
			
		||||
    echo "   # Option 3: nvm (as user $ORIGINAL_USER)"
 | 
			
		||||
    echo "   curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash"
 | 
			
		||||
    echo "   source ~/.bashrc"
 | 
			
		||||
    echo "   nvm install 20"
 | 
			
		||||
    echo ""
 | 
			
		||||
    return 1
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Build with proper user context
 | 
			
		||||
sudo -u "$ORIGINAL_USER" bash -c "
 | 
			
		||||
    # Load user environment
 | 
			
		||||
    [ -s '$ORIGINAL_HOME/.bashrc' ] && source '$ORIGINAL_HOME/.bashrc'
 | 
			
		||||
    [ -s '$ORIGINAL_HOME/.profile' ] && source '$ORIGINAL_HOME/.profile'
 | 
			
		||||
    
 | 
			
		||||
    # Load nvm if available
 | 
			
		||||
    export NVM_DIR='$ORIGINAL_HOME/.nvm'
 | 
			
		||||
    [ -s '\$NVM_DIR/nvm.sh' ] && source '\$NVM_DIR/nvm.sh'
 | 
			
		||||
    
 | 
			
		||||
    # Build
 | 
			
		||||
    npm run build
 | 
			
		||||
"
 | 
			
		||||
# Check for existing build or build if needed
 | 
			
		||||
if [ ! -d "dist" ] || [ ! "$(ls -A dist 2>/dev/null)" ]; then
 | 
			
		||||
    echo "📦 No dist/ directory found, building..."
 | 
			
		||||
    if ! find_and_use_npm; then
 | 
			
		||||
        exit 1
 | 
			
		||||
    fi
 | 
			
		||||
else
 | 
			
		||||
    echo "📦 Found existing dist/ directory"
 | 
			
		||||
    read -p "🤔 Rebuild application? (y/N): " -n 1 -r
 | 
			
		||||
    echo
 | 
			
		||||
    if [[ $REPLY =~ ^[Yy]$ ]]; then
 | 
			
		||||
        if ! find_and_use_npm; then
 | 
			
		||||
            echo ""
 | 
			
		||||
            echo "💡 Using existing dist/ due to build failure"
 | 
			
		||||
        fi
 | 
			
		||||
    else
 | 
			
		||||
        echo "📦 Using existing build"
 | 
			
		||||
    fi
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# Verify build succeeded
 | 
			
		||||
if [ ! -d "dist" ] || [ ! "$(ls -A dist 2>/dev/null)" ]; then
 | 
			
		||||
@ -96,15 +153,11 @@ if [ -d "src/content/knowledgebase" ]; then
 | 
			
		||||
    echo "✅ Knowledgebase content copied ($KB_COUNT articles)"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# Setup environment configuration
 | 
			
		||||
# Setup environment configuration  
 | 
			
		||||
echo "🔧 Setting up environment configuration..."
 | 
			
		||||
if [ -f "$WEBROOT/.env" ]; then
 | 
			
		||||
    echo "📝 Existing .env found, keeping current configuration"
 | 
			
		||||
else
 | 
			
		||||
    echo "📝 Creating new .env from template..."
 | 
			
		||||
    cp .env.example "$WEBROOT/.env"
 | 
			
		||||
    echo "⚠️  IMPORTANT: Edit $WEBROOT/.env with your configuration"
 | 
			
		||||
fi
 | 
			
		||||
cp .env.example "$WEBROOT/.env"
 | 
			
		||||
echo "✅ Created .env from .env.example template"
 | 
			
		||||
echo "⚠️  IMPORTANT: Edit $WEBROOT/.env with your configuration"
 | 
			
		||||
 | 
			
		||||
# Create log files
 | 
			
		||||
echo "📝 Creating log files..."
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user