mirror of
https://github.com/System-End/spaces.git
synced 2026-04-19 16:38:24 +00:00
hackatime autosetup
This commit is contained in:
parent
0dd0d32f31
commit
cd9e4a1d20
2 changed files with 31 additions and 1 deletions
|
|
@ -1,9 +1,12 @@
|
|||
#!/bin/bash
|
||||
|
||||
# runs inside of created code-server containers, installs essential dev tools by default
|
||||
# Usage: ./code-server-setup.sh [HACKATIME_API_KEY]
|
||||
|
||||
set -e
|
||||
|
||||
HACKATIME_API_KEY="${1:-}"
|
||||
|
||||
echo "Starting development environment setup..."
|
||||
|
||||
echo "Updating package manager..."
|
||||
|
|
@ -98,6 +101,15 @@ gem install rails
|
|||
sudo npm install pnpm
|
||||
|
||||
|
||||
# Set up Hackatime if API key is provided
|
||||
if [ -n "$HACKATIME_API_KEY" ]; then
|
||||
echo "⏱️ Setting up Hackatime..."
|
||||
export HACKATIME_API_KEY="$HACKATIME_API_KEY"
|
||||
export HACKATIME_API_URL="https://hackatime.hackclub.com/api/hackatime/v1"
|
||||
export SUCCESS_URL="https://hackatime.hackclub.com//success.txt"
|
||||
curl -sSL https://hackatime.hackclub.com/hackatime/setup.sh | bash
|
||||
fi
|
||||
|
||||
# Final cleanup
|
||||
echo "🧹 Cleaning up..."
|
||||
sudo apt autoremove -y
|
||||
|
|
|
|||
|
|
@ -101,8 +101,9 @@ export const createContainer = async (password, type, authorization) => {
|
|||
const setupScriptPath = path.join(__dirname, "../../code-server-setup.sh");
|
||||
const setupScript = fs.readFileSync(setupScriptPath, "utf8");
|
||||
|
||||
const hackatimeApiKey = user.hackatime_api_key || "";
|
||||
const exec = await container.exec({
|
||||
Cmd: ["bash", "-c", `cat > /tmp/setup.sh << 'EOF'\n${setupScript}\nEOF\nchmod +x /tmp/setup.sh && /tmp/setup.sh > /app/postinstall.log 2>&1`],
|
||||
Cmd: ["bash", "-c", `cat > /tmp/setup.sh << 'EOF'\n${setupScript}\nEOF\nchmod +x /tmp/setup.sh && /tmp/setup.sh '${hackatimeApiKey}' > /app/postinstall.log 2>&1`],
|
||||
AttachStdout: true,
|
||||
AttachStderr: true,
|
||||
});
|
||||
|
|
@ -221,6 +222,23 @@ export const startContainer = async (spaceId, authorization) => {
|
|||
|
||||
await container.inspect();
|
||||
await container.start();
|
||||
|
||||
if (space.type === "code-server" && user.hackatime_api_key) {
|
||||
try {
|
||||
console.log("Setting up Hackatime for code-server container...");
|
||||
const hackatimeApiKey = user.hackatime_api_key;
|
||||
const exec = await container.exec({
|
||||
Cmd: ["bash", "-c", `export HACKATIME_API_KEY='${hackatimeApiKey}' && export HACKATIME_API_URL="https://hackatime.hackclub.com/api/hackatime/v1" && export SUCCESS_URL="https://hackatime.hackclub.com//success.txt" && curl -sSL https://hackatime.hackclub.com/hackatime/setup.sh | bash`],
|
||||
AttachStdout: true,
|
||||
AttachStderr: true,
|
||||
});
|
||||
const stream = await exec.start();
|
||||
stream.pipe(process.stdout);
|
||||
console.log("Hackatime setup executed successfully");
|
||||
} catch (hackatimeErr) {
|
||||
console.error("Failed to set up Hackatime (container will still start):", hackatimeErr);
|
||||
}
|
||||
}
|
||||
|
||||
// Update running status and started_at timestamp in database
|
||||
await pg('spaces')
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue