implement Git Repo Sync

This commit is contained in:
2016-07-04 04:56:49 +02:00
parent d06c7059bb
commit ee844fd348
15 changed files with 79 additions and 31 deletions

View File

@ -1,7 +1,6 @@
#!/usr/bin/env node
// the shebang line above makes sure this script will get interpreted by node
import "typings-global";
import * as plugins from "./cert.plugins";
import * as paths from "./cert.paths";

View File

@ -1,4 +1,3 @@
import "typings-global";
import * as plugins from "./cert.plugins";
export let certHook = plugins.path.join(__dirname,"cert.hook.js");

View File

@ -4,7 +4,7 @@ export import cflare = require("cflare");
export let fs = require("fs-extra");
export import path = require("path");
export import q = require("q");
export import shelljs = require("shelljs");
export let shelljs = require("shelljs");
export import smartcli = require("smartcli");
export import smartfile = require("smartfile");
export import smartgit = require("smartgit");

View File

@ -7,7 +7,7 @@ export class Cert {
private _sslDir: string;
certificatesPresent:Certificate[];
certificatesValid:Certificate[];
gitOriginRepo;
private _gitOriginRepo;
constructor(optionsArg: {
cfEmail: string,
cfKey: string,
@ -17,15 +17,33 @@ export class Cert {
this._cfEmail = optionsArg.cfEmail;
this._cfKey = optionsArg.cfKey;
this._sslDir = optionsArg.sslDir;
this.gitOriginRepo = optionsArg.gitOriginRepo;
this._gitOriginRepo = optionsArg.gitOriginRepo;
let config = {
cfEmail: this._cfEmail,
cfKey: this._cfKey
}
plugins.smartfile.memory.toFsSync(JSON.stringify(config),plugins.path.join(__dirname, "assets/config.json"));
if(this._gitOriginRepo){
plugins.smartgit.init(this._sslDir);
plugins.smartgit.remote.add(this._sslDir,"origin",this._gitOriginRepo);
this.sslGitOriginPull();
}
};
sslGitOriginPull = () => {
if(this._gitOriginRepo){
plugins.smartgit.pull(this._sslDir,"origin","master");
}
};
sslGitOriginAddCommitPush = () => {
if(this._gitOriginRepo){
plugins.smartgit.add.addAll(this._sslDir);
plugins.smartgit.commit(this._sslDir,"added new SSL certificates and deleted obsolete ones.");
plugins.smartgit.push(this._sslDir,"origin","master");
}
};
getDomainCert(domainNameArg: string,optionsArg?:{force:boolean}) {
let done = plugins.q.defer();
this.sslGitOriginPull();
if (!checkDomainsStillValid(domainNameArg) || optionsArg.force) {
plugins.shelljs.exec("chmod 700 " + paths.letsencryptSh);
plugins.shelljs.exec("chmod 700 " + paths.certHook);
@ -34,11 +52,12 @@ export class Cert {
if(fetchedCertsArray.indexOf(domainNameArg) != -1){
updateSslDirSync(this._sslDir,domainNameArg);
}
this.sslGitOriginAddCommitPush();
done.resolve();
} else {
plugins.beautylog.info("certificate for " + domainNameArg + " is still valid! Not fetching new one!");
done.resolve();
}
};
return done.promise;
};
}
@ -90,6 +109,13 @@ let updateSslDirSync = (sslDirArg:string,domainNameArg:string) => {
};
}
let updateGitOrigin = () => {
const enum gitSyncDirection {
toOrigin,
fromOrigin
}
}
let updateGitOrigin = (syncDirectionArg:gitSyncDirection) => {
};
updateGitOrigin(gitSyncDirection.toOrigin);