File size: 6,078 Bytes
8679b23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f06466c
8679b23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/bin/bash

# Ubuntu Sandbox Initialization Script
echo "🐧 Initializing Ubuntu Sandbox..."

# Set up environment
export DEBIAN_FRONTEND=noninteractive
export PYTHONDONTWRITEBYTECODE=1
export PYTHONUNBUFFERED=1

# Create necessary directories
mkdir -p /home/sandbox/projects
mkdir -p /home/sandbox/tools
mkdir -p /home/sandbox/.jupyter

# Set up Git configuration (if not exists)
if [ ! -f /home/sandbox/.gitconfig ]; then
    git config --global user.name "Sandbox User"
    git config --global user.email "sandbox@example.com"
    git config --global init.defaultBranch main
    git config --global --add safe.directory '*'
fi

# Create useful aliases
cat > /home/sandbox/.bash_aliases << 'EOF'
# Custom aliases for sandbox
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
alias ..='cd ..'
alias ...='cd ../..'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'

# Development shortcuts
alias py='python3'
alias pip='pip3'
alias serve='python3 -m http.server 8000'
alias jlab='jupyter lab --ip=0.0.0.0 --port=8888 --no-browser --allow-root'

# System monitoring
alias ports='netstat -tuln'
alias processes='ps aux'
alias memory='free -h'
alias disk='df -h'
EOF

# Create Jupyter configuration
cat > /home/sandbox/.jupyter/jupyter_lab_config.py << 'EOF'
c.ServerApp.ip = '0.0.0.0'
c.ServerApp.port = 8888
c.ServerApp.open_browser = False
c.ServerApp.allow_root = True
c.ServerApp.token = ''
c.ServerApp.password = ''
c.ServerApp.allow_origin = '*'
c.ServerApp.disable_check_xsrf = True
EOF

# Create a sample project structure
if [ ! -d "/home/sandbox/projects/sample-project" ]; then
    mkdir -p /home/sandbox/projects/sample-project
    cd /home/sandbox/projects/sample-project
    
    # Create a simple Python web app
    cat > app.py << 'EOF'
from fastapi import FastAPI
from fastapi.responses import HTMLResponse

app = FastAPI(title="Sandbox Web App", version="1.0.0")

@app.get("/", response_class=HTMLResponse)
def read_root():
    return """
    <html>
        <head>
            <title>Ubuntu Sandbox</title>
            <style>
                body { font-family: Arial, sans-serif; margin: 40px; }
                .container { max-width: 600px; margin: 0 auto; }
                .header { color: #2c3e50; }
                .info { background: #ecf0f1; padding: 20px; border-radius: 8px; }
            </style>
        </head>
        <body>
            <div class="container">
                <h1 class="header">🐧 Ubuntu Sandbox</h1>
                <div class="info">
                    <p><strong>Welcome to your Ubuntu development sandbox!</strong></p>
                    <p>This is a containerized Ubuntu environment with:</p>
                    <ul>
                        <li>Python 3.10+ with FastAPI</li>
                        <li>Node.js 18+ with npm</li>
                        <li>Development tools (git, vim, etc.)</li>
                        <li>Jupyter Lab available on port 8888</li>
                    </ul>
                    <p>Start building your projects in <code>/home/sandbox/projects</code>!</p>
                </div>
                <p><a href="/docs">πŸ“š API Documentation</a></p>
            </div>
        </body>
    </html>
    """

@app.get("/health")
def health_check():
    return {"status": "healthy", "message": "Ubuntu Sandbox is running!"}

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)
EOF

    # Create requirements.txt
    cat > requirements.txt << 'EOF'
fastapi==0.104.1
uvicorn==0.24.0
requests==2.31.0
pandas==2.1.3
numpy==1.25.2
matplotlib==3.8.2
seaborn==0.13.0
jupyterlab==4.0.8
EOF

    # Create package.json for Node.js projects
    cat > package.json << 'EOF'
{
  "name": "sandbox-project",
  "version": "1.0.0",
  "description": "Sample project in Ubuntu sandbox",
  "main": "server.js",
  "scripts": {
    "start": "node server.js",
    "dev": "nodemon server.js"
  },
  "dependencies": {
    "express": "^4.18.2",
    "axios": "^1.6.0"
  },
  "devDependencies": {
    "nodemon": "^3.0.1"
  }
}
EOF

    # Create a simple Express server
    cat > server.js << 'EOF'
const express = require('express');
const app = express();
const port = 3000;

app.use(express.json());
app.use(express.static('public'));

app.get('/', (req, res) => {
    res.send(`
        <html>
            <head><title>Node.js Sandbox</title></head>
            <body style="font-family: Arial, sans-serif; margin: 40px;">
                <h1>πŸš€ Node.js Server Running</h1>
                <p>This is your Node.js server in the Ubuntu sandbox!</p>
                <p>Server running on port ${port}</p>
            </body>
        </html>
    `);
});

app.get('/api/status', (req, res) => {
    res.json({ 
        status: 'running', 
        port: port,
        message: 'Node.js server is healthy!' 
    });
});

app.listen(port, '0.0.0.0', () => {
    console.log(`πŸš€ Server running at http://0.0.0.0:${port}`);
});
EOF
fi

# Install Python packages if requirements.txt exists
if [ -f "/home/sandbox/projects/sample-project/requirements.txt" ]; then
    echo "πŸ“¦ Installing Python dependencies..."
    cd /home/sandbox/projects/sample-project
    pip3 install -r requirements.txt --user
fi

# Set proper permissions
chown -R sandbox:sandbox /home/sandbox/

# Display welcome message
echo ""
echo "βœ… Ubuntu Sandbox initialized successfully!"
echo ""
echo "πŸ“ Available directories:"
echo "   - /home/sandbox/projects (your code goes here)"
echo "   - /home/sandbox/tools (custom tools and utilities)"
echo ""
echo "πŸš€ Quick start commands:"
echo "   - cd /home/sandbox/projects/sample-project"
echo "   - python3 app.py  (start FastAPI server on port 8000)"
echo "   - npm start       (start Node.js server on port 3000)"
echo "   - jupyter lab --ip=0.0.0.0 --port=8888 --no-browser --allow-root"
echo ""
echo "πŸ”§ System info:"
echo "   - Python: $(python3 --version)"
echo "   - Node.js: $(node --version 2>/dev/null || echo 'Not available')"
echo "   - Git: $(git --version)"
echo ""
echo "Happy coding! πŸŽ‰"