#!/bin/bash baseDir=$(pwd) domainPath="./data/domain" hr() { [ -t 0 ] && printf '\033[0;32m%*s\033[0m\n' "$(tput cols)" '' | tr ' ' '='; } log() { hr; echo -e "\033[0;34m${@}\033[0m"; hr; } checkFile() { if [ ! -f "${@}" ]; then log "${@} does not exists, exiting" exit fi } makeNextSubmodule() { log "Making ${1}" cd "submodules/${1}/" || exit npm install npm audit fix > /dev/null 2> /dev/null checkFile "make.sh" ./make.sh || exit npx --yes next telemetry disable cd "${baseDir}" || exit # TODO: check if link exists linkTarget="$PWD/nextStatic/${2}" if [ ! -f "${linkTarget}" ]; then ln -sf "$PWD/submodules/${1}/out" "${linkTarget}" fi } # ------------------------------------------------------------------------------------ # Checking if we are ready to go # ------------------------------------------------------------------------------------ checkFile "$PWD/src/server.ts" checkFile "$PWD/package.json" checkFile "$PWD/package-lock.json" if [ ! -f "${domainPath}" ]; then echo -e "\033[0;41m${domainPath} does not exist!\033[0m" echo "Please create it, and re-run this script." echo "Expected content: domain, ex.:'frylabs.net' (without http:// and /)" exit fi # ------------------------------------------------------------------------------------ # Creating directory structure # ------------------------------------------------------------------------------------ log "mkdir-ing" # TODO: make server create these itself mkdir -pv stats mkdir -pv stats/logs mkdir -pv stats/vlogs mkdir -pv data mkdir -pv data/dbs mkdir -p publicDirs/qminingPublic touch publicDirs/qminingPublic/motd # ------------------------------------------------------------------------------------ # Git submodules # ------------------------------------------------------------------------------------ log 'Updating / Cloning project' git pull || exit git submodule update --init --recursive || exit # ------------------------------------------------------------------------------------ # DB-s # ------------------------------------------------------------------------------------ log "Making project" npm install npm audit fix > /dev/null 2> /dev/null npm run export # ------------------------------------------------------------------------------------ # Next js submodules # ------------------------------------------------------------------------------------ mkdir "$PWD/nextStatic" makeNextSubmodule "qmining-page" "qminingPagePublic" makeNextSubmodule "qmining-data-editor" "dataEditorPublic" # ------------------------------------------------------------------------------------ # Moodle test userscript # ------------------------------------------------------------------------------------ log "Making moodle test userscript" checkFile "$PWD/submodules/moodle-test-userscript/stable.user.js" mkdir -pv "$PWD/publicDirs/qminingPublic/moodle-test-userscript" ln -sfv "$PWD/submodules/moodle-test-userscript/stable.user.js" "$PWD/publicDirs/qminingPublic/moodle-test-userscript/" # ------------------------------------------------------------------------------------ # DB-s # ------------------------------------------------------------------------------------ if [ -z "$(ls -A ./data/dbs)" ]; then log "Making DB-s" cd src/standaloneUtils || exit NS_SQL_DEBUG_LOG=1 NS_LOGLEVEL=2 node dbSetup.js mv ./*.db ../../data/dbs cd "${baseDir}" || exit else log "Dbs already exist, skipping" fi # ------------------------------------------------------------------------------------ log "Done! development mode: 'npm run dev', prod mode: 'npm run start', tests: 'npm run test'"