Skip to content

Commit

Permalink
Remove complexity around homes
Browse files Browse the repository at this point in the history
  • Loading branch information
chee committed Aug 12, 2019
1 parent 0e20265 commit 44882bf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 28 deletions.
2 changes: 0 additions & 2 deletions commands/create-snoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ module.exports = async function createSnoot () {
})
}

await snoots.linkHome(snoot)

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

Expand Down
30 changes: 4 additions & 26 deletions library/snoots.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ let {shout} = require("./loggo.js")

let rootResolver = createResolver("/www/snoot.club")
let resolver = rootResolver("snoots")
let homeResolver = createResolver("/snoots")

let validNameRegex = /^[a-z][a-z0-9]{0,30}$/

Expand All @@ -30,36 +29,21 @@ async function getAuthorizedKeys (snoot) {
return fs.readFile(authorizedKeysPath, "utf-8")
}

async function linkHome (snoot) {
let home = homeResolver(snoot).path
if (!fs.pathExists(home)) {
await unix.ln({
from: home,
to: resolver("snoot").path
})
}
}

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

let rootOwnedPaths = [
homeResolver.path
]

let snootOwnedPaths = [
sshDirectoryResolver.path,
authorizedKeysPath,
snootHomeResolver.path
snootResolver.path
]

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

for (let path of [...rootOwnedPaths, ...snootOwnedPaths]) {
for (let path of snootOwnedPaths) {
await fs.chmod(path, 0o755)
}

Expand All @@ -68,17 +52,13 @@ async function fixSshPermissions (snoot) {
for (let path of snootOwnedPaths) {
await fs.chown(path, snootId, commonId)
}

for (let path of rootOwnedPaths) {
await fs.chown(path, 0, 0)
}
}

async function createUnixAccount (snoot) {
return unix.createUser({
user: snoot,
groups: [unix.commonGroupName, unix.lowerGroupName],
homeDirectory: homeResolver(snoot).path
homeDirectory: createResolver("/")("snoots", snoot).path
})
}

Expand Down Expand Up @@ -137,7 +117,6 @@ async function demandExistence (snoot) {
module.exports = {
rootResolver,
resolver,
homeResolver,
applicationResolver,
websiteResolver,
createUnixAccount,
Expand All @@ -148,6 +127,5 @@ module.exports = {
getNames,
demandExistence,
createBareRepo,
getAuthorizedKeys,
linkHome
getAuthorizedKeys
}

0 comments on commit 44882bf

Please sign in to comment.