Skip to content

Commit

Permalink
create git file, authorized keys, no nginx
Browse files Browse the repository at this point in the history
  • Loading branch information
chee committed Aug 12, 2019
1 parent f7c7079 commit ee6107d
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 164 deletions.
17 changes: 4 additions & 13 deletions commands/create-snoot.js
Expand Up @@ -124,29 +124,20 @@ module.exports = async function createSnoot () {
.catch(error => {
shout("couldnt create user!")
shout(error)
warn("creating them a directory 📂 📁 in /snoots as a backup 🦴")
})
}

log("adding their authorized_keys ➕🔑 file so they can log in (:")
await snoots.createHomeSshConfiguration(snoot, {authorizedKeys})

log("creating a bare git repo for them to live at /repo")
await snoots.createBareRepo(snoot)

log("giving them a gitconfig")
await snoots.createHomeGitConfiguration(snoot)
log("fixing ssh permssions")
await snoots.fixSshPermissions(snoot)

log("generating their base application files! 📠 🎰")
await snoots.createBaseApplication(snoot)

await fs.move(
snoots.applicationResolver("nginx.conf").path,
snoots.rootResolver("snoots-nginx")(`${snoot}.conf`).path
)
await snoots.createBaseApplication(snoot, {authorizedKeys})

log("restarting nginx 🔂")
await shell.run("nginx -s reload")
await shell.run("/www/snoot.club/scripts/refresh.zsh /www/snoot.club/")
}

let beingRunDirectly = process.argv[1].match(/create-snoot($|\.js$)/)
Expand Down
16 changes: 0 additions & 16 deletions commands/each.js

This file was deleted.

10 changes: 0 additions & 10 deletions commands/enter-snoot.js

This file was deleted.

10 changes: 0 additions & 10 deletions commands/exec.js

This file was deleted.

15 changes: 0 additions & 15 deletions commands/get.js

This file was deleted.

10 changes: 0 additions & 10 deletions commands/start-snoot.js

This file was deleted.

10 changes: 0 additions & 10 deletions commands/stop-snoot.js

This file was deleted.

56 changes: 20 additions & 36 deletions library/skeletons.js
Expand Up @@ -3,38 +3,15 @@ let os = require("os")
let inquirer = require("inquirer")

exports.files = {
logs: {},
"nginx.conf" (snoot) {
return `server {
include /www/snoot.club/blocks/error_page.nginx;
include /www/snoot.club/blocks/ssl.nginx;
default_type text/plain;
server_name ${snoot}.snoot.club;
access_log /www/snoot.club/snoots/logs/${snoot}.access.ssl.log;
error_log /www/snoot.club/snoots/logs/${snoot}.error.ssl.log;
location / {
include /www/snoot.club/blocks/cors.nginx;
proxy_pass http://unix:/www/snoot.club/snoots/${snoot}/application/sock:/;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
include /www/snoot.club/blocks/proxy-cache.nginx;
expires $expires;
client_max_body_size 222m;
}
}
server {
listen 80;
listen [::]:80;
server_name ${snoot}.snoot.club;
return 301 https://${snoot}.snoot.club$request_uri;
}
`
".ssh": {
authorizedKeys (_snoot, {authorizedKeys}) {
return authorizedKeys
}
},
".gitconfig" (snoot) {
return `[user]
name = ${snoot}
email ${snoot}@snoot.club`
},
repo: {
hooks: {
Expand Down Expand Up @@ -146,8 +123,16 @@ module.exports = (request, response) =>
<p>
the start script in your <code>package.json</code> will be run automatically.
it needs to create a unix domain socket called <code>sock</code> in
the application directory.
you can replace it with anything, and as long as it creates and listens on a
unix domain socket at <code>./application/sock</code>, it'll be served. the
initial setup already does this, and serves files in
<code>./application/website</code> and apps in
<code>./application/boops</code> using <a
href="https://github.com/snootclub/boops">boops</a>.
</p>
<p>
i promise that's cool and fun and not scary
</p>
`
}
Expand Down Expand Up @@ -185,8 +170,7 @@ exports.write = async function write (options) {
let permissions = getPermissions({filePath, fileType}) || {}

out:
if (fileType == fileTypes.file) {
// this is a file node
if (fileType == fileTypes.file) { // if this is a file node
let fileCreator = value
if (await fs.pathExists(filePath)) {
let {shouldContinue} = await inquirer.prompt({
Expand Down
57 changes: 13 additions & 44 deletions library/snoots.js
Expand Up @@ -30,19 +30,14 @@ async function getAuthorizedKeys (snoot) {
return fs.readFile(authorizedKeysPath, "utf-8")
}

async function createHomeSshConfiguration (snoot, {authorizedKeys}) {
async function fixSshPermissions (snoot) {
let snootHomeResolver = homeResolver(snoot)
let snootResolver = resolver(snoot)
let sshDirectoryResolver = snootResolver(".ssh")
let authorizedKeysPath = sshDirectoryResolver("authorized_keys").path

await fs.outputFile(
authorizedKeysPath,
authorizedKeys
)

let rootOwnedPaths = [
homeResolver
homeResolver.path
]

let snootOwnedPaths = [
Expand All @@ -51,11 +46,6 @@ async function createHomeSshConfiguration (snoot, {authorizedKeys}) {
snootHomeResolver.path
]

await unix.ln({
from: snootHomeResolver.path,
to: snootResolver.path
})

let snootId = await unix.getUserId(snoot)
let commonId = await unix.getCommonGid()

Expand All @@ -74,30 +64,17 @@ async function createHomeSshConfiguration (snoot, {authorizedKeys}) {
}
}

async function createHomeGitConfiguration (snoot) {
let snootResolver = resolver(snoot)
let gitconfigPath = snootResolver(".gitconfig").path

let gitconfig = `[user]
name = ${snoot}
email ${snoot}@snoot.club
`

await fs.outputFile(
gitconfig,
gitconfigPath
)

let snootId = await unix.getUserId(snoot)
let commonId = await unix.getCommonGid()
await fs.chown(gitconfigPath, snootId, commonId)
}

async function createUnixAccount (snoot) {
return await unix.createUser({
let homeDirectory = homeResolver(snoot).path
await unix.createUser({
user: snoot,
groups: [unix.commonGroupName, unix.lowerGroupName],
homeDirectory: homeResolver(snoot).path
homeDirectory
})

await unix.ln({
from: homeDirectory,
to: resolver("snoot").path
})
}

Expand All @@ -112,12 +89,12 @@ async function createBareRepo (snoot) {
})
}

async function createBaseApplication (snoot) {
async function createBaseApplication (snoot, data) {
await skeletons.write({
resolver: resolver(snoot),
uid: await unix.getUserId(snoot),
gid: await unix.getCommonGid(),
render: compile => compile(snoot),
render: compile => compile(snoot, data),
getPermissions ({filePath, fileType}) {
if (fileType == skeletons.fileTypes.file) {
let rwxr_xr_x = 0o755
Expand All @@ -139,12 +116,6 @@ async function getNames () {
)
}

async function each (fn) {
for (let snoot of await getNames()) {
await fn(snoot)
}
}

async function checkExists (snoot) {
let names = await getNames()
return names.includes(snoot)
Expand All @@ -165,11 +136,9 @@ module.exports = {
homeResolver,
applicationResolver,
websiteResolver,
createHomeSshConfiguration,
createHomeGitConfiguration,
createUnixAccount,
createBaseApplication,
each,
fixSshPermissions,
checkExists,
validateName,
getNames,
Expand Down

0 comments on commit ee6107d

Please sign in to comment.