Browse Source

add secrets

master
Chris Mahoney 2 months ago
parent
commit
ec2f9fa374
  1. 5
      .gitignore
  2. 25
      src/index.ts
  3. 7
      src/mirrors.json
  4. 23
      src/mirrors.schema.json
  5. 23
      src/secrets.schema.json

5
.gitignore

@ -1,2 +1,5 @@
dist/
node_modules/
node_modules/
scripts
src/secrets.json

25
src/index.ts

@ -1,8 +1,25 @@
import data from './mirrors.json';
import _ from './secrets.json';
let secrets = require('./secrets.json')["secrets"]
import fs from 'fs/promises'
for (let mirror of data.mirrors) {
if (mirror.rsync) {
let {host, src, dest, options} = mirror.rsync;
console.log(`rsync ${options} ${host}:/${src} ${dest}`);
async function createScripts() {
await fs.mkdir("scripts/passwords", {recursive: true});
for (let mirror of data.mirrors) {
if (mirror.rsync) {
let {host, src, dest, options} = mirror.rsync;
if (secrets[mirror.short]) {
let {username, password} = secrets[mirror.short];
await fs.writeFile("scripts/passwords/" + mirror.short, password, {mode: "600"});
let command = `#/bin/bash\nrsync ${options} --password-file=scripts/passwords/${mirror.short} ${username}@${host}::${src} ${dest}`;
await fs.writeFile("scripts/" + mirror.short + ".sh", command, {mode: "755"});
} else {
let command = `#/bin/bash\nrsync ${options} ${host}::${src} ${dest}`;
await fs.writeFile("scripts/" + mirror.short + ".sh", command, {mode: "755"});
}
}
}
}
createScripts();

7
src/mirrors.json

@ -3,12 +3,13 @@
"mirrors": [
{
"name": "Alpine Linux",
"short": "alpine",
"isDistro": true,
"rsync": {
"host": "rsync.alpinelinux.org",
"src": "alpine",
"dest": "/storage/alpine",
"options": "-avzrH --exclude \".~tmp~\" --bwlimit=50000",
"options": "-avzrH --exclude \".~tmp~\"",
"sync_file": "last-updated",
"syncs_per_day": 2
},
@ -17,12 +18,13 @@
},
{
"name": "Blender",
"short": "blender",
"isDistro": false,
"rsync": {
"host": "downloads.blender.org",
"src": "blender",
"dest": "/storage/blender",
"options": "-avzrH --exclude \".~tmp~\" --bwlimit=50000",
"options": "-avzrH --exclude \".~tmp~\"",
"syncs_per_day": 6
},
"official": true,
@ -30,6 +32,7 @@
},
{
"name": "MS-DOS",
"short": "msdos",
"isDistro": false,
"static": {
"location": "/storage/msdos"

23
src/mirrors.schema.json

@ -14,6 +14,20 @@
"description": "Human name of the repo",
"type": "string"
},
"short": {
"description": "short name of the repo, folders will be named this",
"type": "string"
},
"script": {
"description": "Host a project by periodically calling a script",
"type": "object",
"syncs_per_day": {
"description": "How many times a day to sync",
"type": "number",
"minimum": 1,
"maximum": 24
}
},
"rsync": {
"description": "Instructions for how to run rsync",
"type": "object",
@ -21,13 +35,7 @@
"options": {
"description": "Command line options passed with rsync call",
"type": "string",
"default": "-avzrH --numeric-ids --delete --delete-delay --delay-updates --ignore-errors --exclude \".~tmp~\" --bwlimit=50000"
},
"password": {
"description": "Adds a password file for sync"
},
"user": {
"type": "string"
"default": "-avzrH --numeric-ids --delete --delete-delay --delay-updates --ignore-errors --exclude \".~tmp~\""
},
"host": {
"description": "Host address of the upstream mirror",
@ -86,6 +94,7 @@
},
"required": [
"name",
"short",
"official",
"isDistro",
"homepage"

23
src/secrets.schema.json

@ -0,0 +1,23 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"secrets": {
"description": "usernames and passwords",
"type": "object",
"additionalProperties": {
"type": "object",
"properties": {
"username": {
"type": "string"
},
"password": {
"type:": "string"
}
}
},
"minProperties": 1
}
},
"required": ["secrets"]
}
Loading…
Cancel
Save