Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
add scoop task, build secman scoop generator, update packages
Browse files Browse the repository at this point in the history
  • Loading branch information
abdfnx committed Mar 13, 2022
1 parent 19e4dbc commit dbe4566
Show file tree
Hide file tree
Showing 7 changed files with 437 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ vendor
# Optional npm cache directory
.npm

# Output of 'npm pack'
# Archive files
*.tgz
*.zip

# Yarn Integrity file
.yarn-integrity
Expand Down
4 changes: 4 additions & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,7 @@ tasks:
- task: build-core
- task: link-core
- ./scripts/bfs.ps1

scoop:
cmds:
- node ./scripts/scoop/scoop-sm.js
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"url": "https://secman.dev"
},
"workspaces": [
"core"
"core",
"scripts/scoop"
]
}
18 changes: 18 additions & 0 deletions scripts/scoop/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "scoop-sm",
"version": "0.0.0",
"description": "secman scoop generator.",
"author": "@abdfnx",
"main": "scoop-sm.js",
"scripts": {
"start": "node scoop-sm.js"
},
"dependencies": {
"crypto": "1.0.1",
"mkdirp": "^1.0.4",
"rimraf": "^3.0.2",
"shelljs": "^0.8.5",
"stream": "0.0.2",
"util": "0.12.4"
}
}
76 changes: 76 additions & 0 deletions scripts/scoop/scoop-sm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const fs = require("fs");
const path = require("path");
const rm = require("rimraf");
const mkdirp = require("mkdirp");
const sh = require("shelljs");
const _crypto = require("crypto");
const { promisify } = require("util");
const { pipeline } = require("stream");

const VERSION_CMD = sh.exec("git describe --abbrev=0 --tags");
const VERSION = VERSION_CMD.replace("\n", "")
.replace("\r", "")
.replace("v", "");

const SECMAN_32BIT_URL = `https://github.com/scmn-dev/secman/releases/download/v${VERSION}/secman_windows_v${VERSION}_386.zip`;
const SECMAN_64BIT_URL = `https://github.com/scmn-dev/secman/releases/download/v${VERSION}/secman_windows_v${VERSION}_amd64.zip`;

const ROOT = __dirname;
const DIST_DIR = path.join(ROOT, "..", "..", "dist");
const TEMPLATES = path.join(ROOT, "templates");

async function calculateSHA256(fileName) {
const hash = _crypto.createHash("sha256");

hash.setEncoding("hex");
await promisify(pipeline)(fs.createReadStream(fileName), hash);

return hash.read();
}

async function updateSecmanScoop(secmanDir) {
const templatePath = path.join(TEMPLATES, "secman.json");
const template = fs.readFileSync(templatePath).toString("utf-8");

const SM_32BIT_FILE = path.join(
DIST_DIR,
`secman_windows_v${VERSION}_386.zip`
);
const SM_64BIT_FILE = path.join(
DIST_DIR,
`secman_windows_v${VERSION}_amd64.zip`
);

const SM_32BIT_HASH = await calculateSHA256(SM_32BIT_FILE);
const SM_64BIT_HASH = await calculateSHA256(SM_64BIT_FILE);

const templateReplaced = template
.replace("CLI_VERSION", VERSION)
.replace("SECMAN_32BIT_URL", SECMAN_32BIT_URL)
.replace("SECMAN_64BIT_URL", SECMAN_64BIT_URL)
.replace("32BIT_HASH", SM_32BIT_HASH)
.replace("64BIT_HASH", SM_64BIT_HASH);

fs.writeFileSync(path.join(secmanDir, "secman.json"), templateReplaced);
}

async function updateScoop() {
const tmp = path.join(__dirname, "tmp");
const scoopDir = path.join(tmp, "scoop");

mkdirp.sync(tmp);
rm.sync(scoopDir);

console.log(`cloning https://github.com/scmn-dev/scoop to ${scoopDir}`);

sh.exec(`git clone https://github.com/scmn-dev/scoop.git ${scoopDir}`);

console.log(`done cloning scmn-dev/scoop to ${scoopDir}`);

await updateSecmanScoop(scoopDir);
}

updateScoop().catch((err) => {
console.error(`error running scripts/scoop/scoop-sm.js`, err);
process.exit(1);
});
18 changes: 18 additions & 0 deletions scripts/scoop/templates/secman.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": "CLI_VERSION",
"architecture": {
"32bit": {
"url": "SECMAN_32BIT_URL",
"bin": ["bin/secman.exe"],
"hash": "32BIT_HASH"
},
"64bit": {
"url": "SECMAN_64BIT_URL",
"bin": ["bin/secman.exe"],
"hash": "64BIT_HASH"
}
},
"homepage": "https://secman.dev",
"license": "MIT",
"description": "👊 Human-friendly and amazing TUI secrets manager"
}
Loading

0 comments on commit dbe4566

Please sign in to comment.