From 085dd02148b13294c0b556de5d2fd2ea30ebe04a Mon Sep 17 00:00:00 2001 From: knotteye Date: Thu, 26 Sep 2019 14:43:24 -0500 Subject: [PATCH] Changed init functions to be more consistent. Added setup script and templates for config and database setup. Fixed typo in tsconfig. --- .gitignore | 2 ++ config/default.toml | 3 ++- db_setup.sql | 11 ---------- install/db_template.sql | 11 ++++++++++ install/setup.sh | 43 +++++++++++++++++++++++++++++++++++++ install/template.local.toml | 15 +++++++++++++ package.json | 3 ++- src/cli.ts | 2 +- src/controller.ts | 12 +++++------ src/database.ts | 4 ++-- src/ircd.ts | 4 ++-- src/server.ts | 4 ++-- tsconfig.json | 4 ++-- 13 files changed, 90 insertions(+), 28 deletions(-) delete mode 100644 db_setup.sql create mode 100644 install/db_template.sql create mode 100644 install/setup.sh create mode 100644 install/template.local.toml diff --git a/.gitignore b/.gitignore index 66bd688..c7134f8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ node_modules site config/local.toml +config/generated.toml +install/db_setup.sql build/** lib/inspircd-* diff --git a/config/default.toml b/config/default.toml index 4b8079c..9af96b5 100644 --- a/config/default.toml +++ b/config/default.toml @@ -4,9 +4,10 @@ saltRounds = 12 [satyr] +name = '' +domain = '' registration = false webFormat = 'hls' -record = false restrictedNames = ['live','stream'] [ircd] diff --git a/db_setup.sql b/db_setup.sql deleted file mode 100644 index 922287f..0000000 --- a/db_setup.sql +++ /dev/null @@ -1,11 +0,0 @@ -CREATE USER 'satyr'@'localhost' IDENTIFIED BY 'password'; -CREATE DATABASE satyr_db; -GRANT ALL PRIVILEGES ON satyr_db.* TO 'satyr'@'localhost'; -USE satyr_db; -CREATE TABLE users( - username VARCHAR(25), - password_hash BINARY(60), - stream_key CHAR(20), - record_flag TINYINT, - is_mod TINYINT -); \ No newline at end of file diff --git a/install/db_template.sql b/install/db_template.sql new file mode 100644 index 0000000..4393693 --- /dev/null +++ b/install/db_template.sql @@ -0,0 +1,11 @@ +CREATE USER ''@'' IDENTIFIED BY ''; +CREATE DATABASE ; +GRANT ALL PRIVILEGES ON .* TO ''@''; +USE ; +CREATE TABLE users( + username VARCHAR(25), + password_hash BINARY(60), + stream_key CHAR(20), + record_flag TINYINT, + is_mod TINYINT +); \ No newline at end of file diff --git a/install/setup.sh b/install/setup.sh new file mode 100644 index 0000000..58a64b4 --- /dev/null +++ b/install/setup.sh @@ -0,0 +1,43 @@ +#!/bin/sh +echo "Please answer a few questions about your instance to get started." +echo "Default values are in brackets." +name="" +while [ -z "$name" ] +do + echo "Please enter a name for your instance.[]" + read name +done +domain="" +while [ -z "$domain" ] +do + echo "Please the domain name for your instance.[]" + read domain +done +echo "Please enter the path to the ffmpeg binary on your system.[$(which ffmpeg)]" +read ffmpeg +ffmpeg="${ffmpeg:=$(which ffmpeg)}" +echo "Please enter the user for the database.[satyr]" +read dbuser +dbuser="${dbuser:=satyr}" +echo "Please enter the password for the database.[autogenerated]" +read dbpassword +dbpassword="${dbpass:=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 15 | head -n 1)}" +echo "Please enter the name for the database.[satyr_db]" +read dbname +dbname="${dbname:=satyr_db}" +echo "Please enter the hostname for the database.[localhost]" +read dbhost +dbhost="${dbhost:=localhost}" +if [ "$dbhost" != "localhost" ] +then +echo "Please enter the ip this server will connect to the database with.[*]" +read dbclient +dbclient="${dbclient:='*'}" +else +dbclient="localhost" +fi +sed -e "s##$name#g" -e "s##$domain#g" -e "s##$ffmpeg#g" -e "s##$dbuser#g" -e "s##$dbname#g" -e "s##$dbpass#g" -e "s##$dbhost#g" install/template.local.toml > config/generated.toml +sed -e "s##$dbuser#g" -e "s##$dbname#g" -e "s##$dbpass#g" -e "s##$dbhost#g" -e "s##$dbclient#g" install/db_template.sql > install/db_setup.sql +echo "A setup script for the database has been generated at install/db_setup.sql. Please run it by connecting to your database software and executing 'source install/db_setup.sql;''" +echo "A default configuration file has been generated at config/generated.toml" +echo "If everything looks fine, move it to config/local.toml and start your instance." \ No newline at end of file diff --git a/install/template.local.toml b/install/template.local.toml new file mode 100644 index 0000000..d3bc491 --- /dev/null +++ b/install/template.local.toml @@ -0,0 +1,15 @@ +[satyr] +name = '' +domain = '' +registration = false + +[media] +streamKeys = false +record = false +ffmpeg = '' + +[database] +user = '' +password = '' +database = '' +host = '' diff --git a/package.json b/package.json index 2015eab..278d412 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "scripts": { "start": "node build/controller.js", "build": "tsc", - "user": "node build/cli.js" + "user": "node build/cli.js", + "setup": "sh install/setup.sh" }, "repository": { "type": "git", diff --git a/src/cli.ts b/src/cli.ts index f23bc3e..10ab855 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -2,7 +2,7 @@ import * as db from "./database" import * as flags from "flags"; import * as config from "config" -db.run(config.database, config.bcrypt); +db.init(config.database, config.bcrypt); flags.defineString('add', '', 'User to add'); flags.defineString('remove', '', 'User to remove'); diff --git a/src/controller.ts b/src/controller.ts index 712b62f..03268e2 100644 --- a/src/controller.ts +++ b/src/controller.ts @@ -1,11 +1,11 @@ import * as mediaserver from "./server"; import * as ircd from "./ircd"; import * as db from "./database"; -const config = require('config'); +import * as config from "config"; function run(): void{ - const dbcfg = config.database; - const bcryptcfg = config.bcrypt; + const dbcfg: object = config.database; + const bcryptcfg: object = config.bcrypt; const satyr: object = { privateEndpoint: config.media.privateEndpoint, record: config.media.record, @@ -47,9 +47,9 @@ function run(): void{ } }; - db.run(dbcfg, bcryptcfg); - mediaserver.boot(nms, satyr); - ircd.boot(); + db.init(dbcfg, bcryptcfg); + mediaserver.init(nms, satyr); + ircd.init(); } run(); export { run }; \ No newline at end of file diff --git a/src/database.ts b/src/database.ts index 5665db0..66ce58b 100644 --- a/src/database.ts +++ b/src/database.ts @@ -5,7 +5,7 @@ import { resolve } from "url"; var raw: any; var cryptoconfig: any; -function run (db: object, bcrypt: object){ +function init (db: object, bcrypt: object){ raw = mysql.createPool(db); cryptoconfig = bcrypt; } @@ -63,4 +63,4 @@ async function validatePassword(username: string, password: string){ ; } -export { query, raw, run, addUser, rmUser, addStreamKey, rmStreamKey }; \ No newline at end of file +export { query, raw, init, addUser, rmUser, addStreamKey, rmStreamKey }; \ No newline at end of file diff --git a/src/ircd.ts b/src/ircd.ts index ff1511b..aca74d8 100644 --- a/src/ircd.ts +++ b/src/ircd.ts @@ -1,6 +1,6 @@ import * as child from "child_process"; var ircd: child.ChildProcess; -function boot():void{ +function init():void{ ircd = child.execFile("./lib/inspircd-3.3.0/run/inspircd", ["restart"], (error, stdout, stderr) => { if (error){ console.log("[IRCD] Failed to start Inspircd"); @@ -17,4 +17,4 @@ function reloadSSL():void{ ircd.kill("SIGUSR1"); } -export { boot, reloadSSL }; \ No newline at end of file +export { init, reloadSSL }; \ No newline at end of file diff --git a/src/server.ts b/src/server.ts index 63f5e93..be0b352 100644 --- a/src/server.ts +++ b/src/server.ts @@ -3,7 +3,7 @@ import { mkdir } from "fs"; import * as db from "./database"; const { exec } = require('child_process'); -function boot (mediaconfig: any, satyrconfig: any) { +function init (mediaconfig: any, satyrconfig: any) { const nms = new NodeMediaServer(mediaconfig); nms.run(); @@ -95,4 +95,4 @@ function boot (mediaconfig: any, satyrconfig: any) { } }); } -export { boot }; \ No newline at end of file +export { init }; \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 963380a..b5196e1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,5 +5,5 @@ }, "include":[ "src/**/*" - ], -} + ] +} \ No newline at end of file