/ opencodehub / scripts / init-git-server.cjs
swadhinbiswas Initial commit of OpenCodeHub source · 12/11/2025
1110042
43 lines · 1.4 KB
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

const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');

const DATA_DIR = path.join(__dirname, '../data');
const REPOS_DIR = path.join(DATA_DIR, 'repos');
const AVATARS_DIR = path.join(DATA_DIR, 'avatars');
const ARTIFACTS_DIR = path.join(DATA_DIR, 'artifacts');
const SSH_DIR = path.join(DATA_DIR, 'ssh');

const dirs = [DATA_DIR, REPOS_DIR, AVATARS_DIR, ARTIFACTS_DIR, SSH_DIR];

console.log('Initializing OpenCodeHub Git Server Environment...');

// Create directories
dirs.forEach(dir => {
  if (!fs.existsSync(dir)) {
    console.log(`Creating directory: ${dir}`);
    fs.mkdirSync(dir, { recursive: true });
  } else {
    console.log(`Directory exists: ${dir}`);
  }
});

// Generate SSH Host Keys if they don't exist
const hostKeyPath = path.join(SSH_DIR, 'ssh_host_rsa_key');
if (!fs.existsSync(hostKeyPath)) {
  console.log('Generating SSH Host Key...');
  try {
    // Try to use ssh-keygen if available
    execSync(`ssh-keygen -t rsa -b 4096 -f "${hostKeyPath}" -N "" -q`);
    console.log('SSH Host Key generated successfully.');
  } catch (error) {
    console.warn('Warning: Could not generate SSH key using ssh-keygen. Please ensure ssh-keygen is installed or generate keys manually.');
    console.warn('Error:', error.message);
  }
} else {
  console.log('SSH Host Key already exists.');
}

console.log('Initialization complete.');