diff options
author | Joel Kronqvist <work.joelkronqvist@gmail.com> | 2022-10-15 20:05:32 +0300 |
---|---|---|
committer | Joel Kronqvist <work.joelkronqvist@gmail.com> | 2022-10-15 20:05:32 +0300 |
commit | b2925ef2579050c484a552f2cd9c0ffed11fb1e9 (patch) | |
tree | cf7708162afe815ef855e8af5e9a1012d2587ff6 | |
parent | 98a7a9947828514372d873b88fcdcdf44a358dd3 (diff) | |
download | LYLLRuoka-b2925ef2579050c484a552f2cd9c0ffed11fb1e9.tar.gz LYLLRuoka-b2925ef2579050c484a552f2cd9c0ffed11fb1e9.zip |
Bug fixes & started setup.sh
-rw-r--r-- | dbparse.js | 4 | ||||
-rw-r--r-- | food.js | 3 | ||||
-rw-r--r-- | server.js | 21 | ||||
-rwxr-xr-x | setup.sh | 50 | ||||
-rw-r--r-- | update.js | 12 |
5 files changed, 75 insertions, 15 deletions
@@ -129,7 +129,7 @@ async function writeShift(weekday, shiftId, shiftLine, courseLine, DB) className = null; dbOperations.push(DB.execute( - `INSERT INTO shifts VALUES (${weekday}, ${shiftId}, ?, ?, ?)`, + `INSERT IGNORE INTO shifts VALUES (${weekday}, ${shiftId}, ?, ?, ?)`, [courseName, teacherName, className] )); } @@ -195,4 +195,4 @@ exports.build = writeShifts; exports.get = getShift; exports.randomIndex = getRandomIndex; exports.find = findExpression; -exports.getNextChar = getNextChar;
\ No newline at end of file +exports.getNextChar = getNextChar; @@ -48,6 +48,7 @@ async function buildFoods(DB) } } await Promise.all(foodInitOperations); + console.log("Foods built"); } function getFoodLink(week) @@ -58,4 +59,4 @@ function getFoodLink(week) exports.foods = scrapeFood; exports.link = getFoodLink; -exports.build = buildFoods;
\ No newline at end of file +exports.build = buildFoods; @@ -35,7 +35,7 @@ async function init() ]); - // https options, you need to get a certificate in the file ../Certificate for the server to work + // https options, you need to get a certificate in the file ../Certificate for the server to work const httpsOpts = { key: httpsKey, cert: httpsCert @@ -264,10 +264,21 @@ async function buildMain(args) [week, day] ) ]); - res["food-header"] = `${food[0].header} ${food[0].datestring}`; - res["vege-header"] = vege[0].header; - res["food"] = food[0].food; - res["vege"] = vege[0].food; + + if (food[0] !== undefined) { + res["food-header"] = `${food[0].header} ${food[0].datestring}`; + res["food"] = food[0].food; + } else { + res["food-header"] = `Kouluruoka ${weekdays[day]}`; + res["food"] = "Päivän ruoka puuttuu tietokannasta."; + } + if (food[1] !== undefined) { + res["vege-header"] = vege[0].header; + res["vege"] = vege[0].food; + } else { + res["vege-header"] = `Kasvisruoka ${weekdays[day]}`; + res["vege"] = "Päivän kasvisruoka puuttuu tietokannasta." + } data_string = build_replace(data_string, res); diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..548c7d3 --- /dev/null +++ b/setup.sh @@ -0,0 +1,50 @@ +#!/bin/sh + +echo "WIP. Don't use this yet." + +if [ "$(whoami)" != "root" ]; then + echo "ERROR: not root. This script installs stuff, so this should be run as root. If you aren't comfortable with it, you can do the installing yourself: it's not hyper advanced." + exit +fi + +echo "Install directory for LYLLRuoka? (leave blank for home)\n>" +read path +cd path + +git clone "https://github.com/JoelHMikael/FoodJS.git" + +apt install curl +curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - +apt-get install -y nodejs + +npm install mysql2 + +apt install mysql-server +echo "\nn\nn\nY\nY\nY\nY\n" | mysql_secure_installation +echo "CREATE DATABASE lyllruoka;\nUSE lyllruoka;\n\nCREATE TABLE shiftnames (\n\tday INT,\n\tid INT,\n\tname VARCHAR(128) NOT NULL,\n\tPRIMARY KEY (day, id)\n);\nCREATE TABLE classes (\n\tcourse VARCHAR(6) PRIMARY KEY,\n\tclass VARCHAR(4)\n);\nCREATE TABLE shifts (\n\tday INT,\n\tshift INT,\n\tcourse VARCHAR(6),\n\tteacher VARCHAR(4),\n\tclass VARCHAR(4),\n\tPRIMARY KEY (day, course)\n);\nCREATE TABLE devs (\n\tid INT PRIMARY KEY AUTO_INCREMENT,\n\tname VARCHAR(30) NOT NULL,\n\tdescription VARCHAR(128),\n\tcontact VARCHAR(40) DEFAULT ''\n);\nCREATE TABLE stats (\n start DATE PRIMARY KEY,\n uptime INT,\n requests INT,\n requests_per_day INT\n);\nCREATE TABLE exams (\n\tstart DATE,\n\tend DATE,\n\tmessage VARCHAR(256),\n\tPRIMARY KEY (start, end)\n);\nCREATE TABLE foods ( \n week INT,\n day INT,\n vegetarian TINYINT,\n header VARCHAR(15),\n dateString VARCHAR(13),\n food VARCHAR(256)\n);" | mysql + +echo "Choose the mysql user hostname (type localhost, if unsure)\n>" +read host +echo "Choose the mysql username?\n> " +read name +echo "Choose the mysql password?\n>" +read -s passw + +echo "CREATE USER '$name'@'$host' IDENTIFIED BY '$passw';\nGRANT ALL ON lyllruoka.* TO '$name'@'$host';\n" +echo "{\n\t\"host\": \"$host\",\n\t\"user\": \"$name\",\n\t\"password\": \"$passw\",\n\t\"database\": \"lyllruoka\"\n}" > dblogin.txt + +echo "Do you want to create a temporary testing certificate? [Y/n]" +read ans +if [ "$ans" == "n" ]; then + echo "Install finished!" + exit +fi + +openssl genrsa -out key.pem +echo "FI\nUusimaa\nLohja\nLohjan Yhteislyseon Lukio\n\n\n\n\n" | openssl req -new -key key.pem -out csr.pem +openssl x509 -req -days 9999 -in csr.pem -signkey key.pem -out cert.pem +rm csr.pem +mkdir -p Certificate +mv -t Certificate key.pem cert.pem + +echo "Install finished!" @@ -6,14 +6,12 @@ const parse = require("./dbparse.js"); // Run this if you want to build the database from text files async function buildDB(dbcredentials, shiftPath, ...classfiles) { - let shiftCont = await openFile(shiftPath); const DB = new database.Database(JSON.parse(dbcredentials)); - shiftCont = shiftCont.toString("utf-8").replaceAll("\r", ""); // \r because of the \r\n newline on windows which creates problems + let shiftCont = await openFile(shiftPath); + shiftCont = shiftCont.toString("utf-8").replaceAll("\r", ""); // \r because of the \r\n newline on windows which may create problems - await Promise.all([ - parseClasses(DB, ...classfiles), - parse.build(shiftCont, DB) - ]); + await parseClasses(DB, ...classfiles), + await parse.build(shiftCont, DB) return 0; } @@ -23,4 +21,4 @@ exports.update = buildDB; const openFile = require("./Functions/open.js").file; const dbcredentials = await openFile("../dblogin.txt"); await updateDB.update(dbcredentials, "./shifts.txt", "./Kurssitarjottimet/2016Classes.txt", "./Kurssitarjottimet/NewClasses.txt"); -*/
\ No newline at end of file +*/ |