diff --git a/commands/create-snoot.js b/commands/create-snoot.js index fd01e22..af0c8c2 100755 --- a/commands/create-snoot.js +++ b/commands/create-snoot.js @@ -127,11 +127,11 @@ module.exports = async function createSnoot () { }) } - log("creating a bare git repo for them to live at /repo") - await snoots.createBareRepo(snoot) + log("generating their base files! 📠 🎰") + await snoots.createBase(snoot, {authorizedKeys}) - log("generating their base application files! 📠 🎰") - await snoots.createBaseApplication(snoot, {authorizedKeys}) + log("creating a git folder for them") + await snoots.createRepository(snoot) log("fixing ssh permssions") await snoots.fixSshPermissions(snoot) diff --git a/library/skeletons.js b/library/skeletons.js index 22a6e7b..1ae4c9d 100644 --- a/library/skeletons.js +++ b/library/skeletons.js @@ -1,5 +1,4 @@ let fs = require("fs-extra") -let os = require("os") let inquirer = require("inquirer") exports.files = { @@ -13,14 +12,6 @@ exports.files = { name = ${snoot} email ${snoot}@snoot.club` }, - repo: { - hooks: { - "post-receive" () { - return `#!/bin/sh -npx @snootclub/post-receive` - } - } - }, application: { boops: { ".gitkeep": () => "a polite request to git to keep this empty directory" @@ -112,15 +103,24 @@ module.exports = (request, response) => Welcome to ${snoot}'s homepage +

getting started:

+

if you are ${snoot}, you can now ssh or ftp into your account!

+

+ if you want to host a webpage, put files in the directory + application/website +

+

the page you are reading right now is the file located at ./application/website/index.html

+

advanced users:

+

the start script in your package.json will be run automatically. you can replace it with anything, and as long as it creates and listens on a @@ -130,10 +130,6 @@ module.exports = (request, response) => ./application/boops using boops.

- -

- i promise that's cool and fun -

` } } @@ -156,8 +152,7 @@ exports.write = async function write (options) { render, files = exports.files, uid, - gid, - getPermissions = () => ({uid, gid, mode}) + gid } = options for (let [key, value] of Object.entries(files)) { @@ -167,7 +162,6 @@ exports.write = async function write (options) { : fileTypes.directory let filePath = fileResolver.path - let permissions = getPermissions({filePath, fileType}) || {} out: if (fileType == fileTypes.file) { // if this is a file node @@ -185,12 +179,14 @@ exports.write = async function write (options) { } } await fs.outputFile(filePath, render(fileCreator)) - await fs.chmod(filePath, permissions.mode || 0o644) + let rw_r__r__ = 0o644 + await fs.chmod(filePath, rw_r__r__) } else { // this is a directory node let files = value + let rwxrwxr_x = 0o775 await fs.mkdirp(filePath) - await fs.chmod(filePath, permissions.mode || 0o775) + await fs.chmod(filePath, rwxrwxr_x) await write(merge(options, { resolver: fileResolver, files @@ -199,8 +195,8 @@ exports.write = async function write (options) { await fs.chown( filePath, - permissions.uid || uid, - permissions.gid || gid + uid, + gid ) } } diff --git a/library/snoots.js b/library/snoots.js index c4ad2ed..8769915 100644 --- a/library/snoots.js +++ b/library/snoots.js @@ -5,31 +5,30 @@ let shell = require("./shell.js") let skeletons = require("./skeletons.js") let {shout} = require("./loggo.js") +let gitRootResolver = createResolver("/mnt/extra-goose/git") let rootResolver = createResolver("/www/snoot.club") let resolver = rootResolver("snoots") let validNameRegex = /^[a-z][a-z0-9]{0,30}$/ -let validateName = snoot => - validNameRegex.test(snoot) +let validateName = snoot => validNameRegex.test(snoot) let applicationResolver = (snoot, ...paths) => resolver(snoot, "application", ...paths) -let repoResolver = (snoot, ...paths) => - resolver(snoot, "repo", ...paths) +let repoResolver = snoot => resolver(snoot, "git") let websiteResolver = (snoot, ...paths) => resolver(snoot, "application", "website", ...paths) -async function getAuthorizedKeys (snoot) { +async function getAuthorizedKeys(snoot) { let snootResolver = resolver(snoot) let sshDirectoryResolver = snootResolver(".ssh") let authorizedKeysPath = sshDirectoryResolver("authorized_keys").path return fs.readFile(authorizedKeysPath, "utf-8") } -async function fixSshPermissions (snoot) { +async function fixSshPermissions(snoot) { let snootResolver = resolver(snoot) let sshDirectoryResolver = snootResolver(".ssh") let authorizedKeysPath = sshDirectoryResolver("authorized_keys").path @@ -37,7 +36,7 @@ async function fixSshPermissions (snoot) { let snootOwnedPaths = [ sshDirectoryResolver.path, authorizedKeysPath, - snootResolver.path + snootResolver.path, ] let snootId = await unix.getUserId(snoot) @@ -54,58 +53,50 @@ async function fixSshPermissions (snoot) { } } -async function createUnixAccount (snoot) { +async function createUnixAccount(snoot) { return unix.createUser({ user: snoot, groups: [unix.commonGroupName, unix.lowerGroupName], - homeDirectory: createResolver("/")("snoots", snoot).path + homeDirectory: createResolver("/")("snoots", snoot).path, }) } -async function createBareRepo (snoot) { - let snootRepoResolver = repoResolver(snoot) - await shell.run(`git init --bare ${snootRepoResolver.path}`) +async function createRepository(snoot) { + let snootGitPath = resolver(snoot)("git").path + let gitSnootPath = gitRootResolver(snoot).path + await fs.mkdir(gitSnootPath) await unix.chown({ user: await unix.getUserId(snoot), group: await unix.getCommonGid(), - path: snootRepoResolver.path, - recurse: true + path: gitSnootPath, + recurse: true, + }) + await unix.ln({ + to: gitSnootPath, + from: snootGitPath, }) } -async function createBaseApplication (snoot, data) { +async function createBase(snoot, data) { await skeletons.write({ resolver: resolver(snoot), uid: await unix.getUserId(snoot), gid: await unix.getCommonGid(), render: compile => compile(snoot, data), - getPermissions ({filePath, fileType}) { - if (fileType == skeletons.fileTypes.file) { - let rwxr_xr_x = 0o755 - let postReceive = repoResolver(snoot, "hooks", "post-receive").path - if (filePath == postReceive) { - return { - mode: rwxr_xr_x - } - } - } - } }) } -async function getNames () { +async function getNames() { let files = await fs.readdir(resolver.path) - return files.filter(name => - validateName(name) - ) + return files.filter(name => validateName(name)) } -async function checkExists (snoot) { +async function checkExists(snoot) { let names = await getNames() return names.includes(snoot) } -async function demandExistence (snoot) { +async function demandExistence(snoot) { let names = await getNames() if (!names.includes(snoot)) { @@ -120,12 +111,12 @@ module.exports = { applicationResolver, websiteResolver, createUnixAccount, - createBaseApplication, + createBase, fixSshPermissions, checkExists, validateName, getNames, demandExistence, - createBareRepo, - getAuthorizedKeys + createRepository, + getAuthorizedKeys, }