Code files
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
'use strict'
|
||||
|
||||
const fs = require('fs')
|
||||
const {execSync} = require('child_process')
|
||||
|
||||
const file = process.argv[2]
|
||||
if (!file) {
|
||||
console.error('specify a file')
|
||||
process.exit(1)
|
||||
}
|
||||
try {
|
||||
fs.accessSync(file)
|
||||
console.error('file already exists')
|
||||
process.exit(1)
|
||||
} catch (e) {
|
||||
makeIt()
|
||||
}
|
||||
|
||||
function makeIt() {
|
||||
const nobody = Number(execSync('id -u nobody').toString().trim())
|
||||
const fd = fs.openSync(file, 'w')
|
||||
fs.fchmodSync(fd, 0)
|
||||
fs.fchownSync(fd, nobody, nobody)
|
||||
console.log(file + ' created')
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
'use strict'
|
||||
|
||||
const fs = require('fs')
|
||||
const {execSync} = require('child_process')
|
||||
|
||||
const file = process.argv[2]
|
||||
if (!file) {
|
||||
console.error('specify a file')
|
||||
process.exit(1)
|
||||
}
|
||||
try {
|
||||
fs.accessSync(file)
|
||||
console.error('file already exists')
|
||||
process.exit(1)
|
||||
} catch (e) {
|
||||
makeIt()
|
||||
}
|
||||
|
||||
function makeIt() {
|
||||
const nobody = Number(execSync('id -u nobody').toString().trim())
|
||||
fs.writeFileSync(file, '')
|
||||
fs.chownSync(file, nobody, nobody)
|
||||
fs.chmodSync(file, 0)
|
||||
console.log(file + ' created')
|
||||
}
|
||||
Reference in New Issue
Block a user