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
 | 
					    exit 1
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Build application
 | 
					# Function to find and use npm
 | 
				
			||||||
echo "📦 Building application..."
 | 
					find_and_use_npm() {
 | 
				
			||||||
if [ ! -d "node_modules" ]; then
 | 
					    echo "🔍 Searching for npm installation..."
 | 
				
			||||||
    echo "📦 Installing dependencies..."
 | 
					    
 | 
				
			||||||
    sudo -u "$ORIGINAL_USER" npm install
 | 
					    # Try system npm first
 | 
				
			||||||
fi
 | 
					    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
 | 
					# Check for existing build or build if needed
 | 
				
			||||||
sudo -u "$ORIGINAL_USER" bash -c "
 | 
					if [ ! -d "dist" ] || [ ! "$(ls -A dist 2>/dev/null)" ]; then
 | 
				
			||||||
    # Load user environment
 | 
					    echo "📦 No dist/ directory found, building..."
 | 
				
			||||||
    [ -s '$ORIGINAL_HOME/.bashrc' ] && source '$ORIGINAL_HOME/.bashrc'
 | 
					    if ! find_and_use_npm; then
 | 
				
			||||||
    [ -s '$ORIGINAL_HOME/.profile' ] && source '$ORIGINAL_HOME/.profile'
 | 
					        exit 1
 | 
				
			||||||
    
 | 
					    fi
 | 
				
			||||||
    # Load nvm if available
 | 
					else
 | 
				
			||||||
    export NVM_DIR='$ORIGINAL_HOME/.nvm'
 | 
					    echo "📦 Found existing dist/ directory"
 | 
				
			||||||
    [ -s '\$NVM_DIR/nvm.sh' ] && source '\$NVM_DIR/nvm.sh'
 | 
					    read -p "🤔 Rebuild application? (y/N): " -n 1 -r
 | 
				
			||||||
    
 | 
					    echo
 | 
				
			||||||
    # Build
 | 
					    if [[ $REPLY =~ ^[Yy]$ ]]; then
 | 
				
			||||||
    npm run build
 | 
					        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
 | 
					# Verify build succeeded
 | 
				
			||||||
if [ ! -d "dist" ] || [ ! "$(ls -A dist 2>/dev/null)" ]; then
 | 
					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)"
 | 
					    echo "✅ Knowledgebase content copied ($KB_COUNT articles)"
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Setup environment configuration
 | 
					# Setup environment configuration  
 | 
				
			||||||
echo "🔧 Setting up environment configuration..."
 | 
					echo "🔧 Setting up environment configuration..."
 | 
				
			||||||
if [ -f "$WEBROOT/.env" ]; then
 | 
					cp .env.example "$WEBROOT/.env"
 | 
				
			||||||
    echo "📝 Existing .env found, keeping current configuration"
 | 
					echo "✅ Created .env from .env.example template"
 | 
				
			||||||
else
 | 
					echo "⚠️  IMPORTANT: Edit $WEBROOT/.env with your configuration"
 | 
				
			||||||
    echo "📝 Creating new .env from template..."
 | 
					 | 
				
			||||||
    cp .env.example "$WEBROOT/.env"
 | 
					 | 
				
			||||||
    echo "⚠️  IMPORTANT: Edit $WEBROOT/.env with your configuration"
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Create log files
 | 
					# Create log files
 | 
				
			||||||
echo "📝 Creating log files..."
 | 
					echo "📝 Creating log files..."
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user