setup script improvements

This commit is contained in:
mrfry 2023-04-08 18:18:56 +02:00
parent 2fc64811e2
commit e46fed69c3

View file

@ -1,45 +1,37 @@
#!/bin/bash #!/bin/bash
hr() { baseDir=$(pwd)
if [ -t 0 ]; then
printf '\033[0;32m%*s\033[0m\n' "$(tput cols)" '' | tr ' ' '='
fi
}
log() { hr() { [ -t 0 ] && printf '\033[0;32m%*s\033[0m\n' "$(tput cols)" '' | tr ' ' '='; }
hr
echo -e "\033[0;34m${@}\033[0m" log() { hr; echo -e "\033[0;34m${*@}\033[0m"; hr; }
hr
}
checkFile() { checkFile() {
if [ ! -f "$@" ]; then if [ ! -f "${*@}" ]; then
log "$@ does not exists, exiting" log "${*@} does not exists, exiting"
exit exit
fi fi
}
function setupJson() {
if [ ! -f "$1" ]; then
echo "Setting up ${1}"
echo '{}' >"$1"
fi
} }
makeNextSubmodule() { makeNextSubmodule() {
log "Making ${1}" log "Making ${1}"
pushd "submodules/${1}/" || exit cd "submodules/${1}/" || exit
npm install npm install
npm audit fix > /dev/null 2> /dev/null npm audit fix > /dev/null 2> /dev/null
npm run export checkFile "make.sh"
popd || exit ./make.sh
# TODO: check if link exists npx --yes next telemetry disable
linkTarget="$PWD/nextStatic/${2}" cd "${baseDir}" || exit
if [ ! -f "${linkTarget}" ]; then # TODO: check if link exists
ln -sf "$PWD/submodules/${1}/out" "${linkTarget}" linkTarget="$PWD/nextStatic/${2}"
fi if [ ! -f "${linkTarget}" ]; then
ln -sf "$PWD/submodules/${1}/out" "${linkTarget}"
fi
} }
# ------------------------------------------------------------------------------------
# Git submodules
# ------------------------------------------------------------------------------------
log 'Updating / Cloning project' log 'Updating / Cloning project'
checkFile "$PWD/src/server.ts" checkFile "$PWD/src/server.ts"
@ -49,52 +41,55 @@ checkFile "$PWD/package-lock.json"
git pull || exit git pull || exit
git submodule update --init --recursive || exit git submodule update --init --recursive || exit
log "Making project"
npm install
npm audit fix > /dev/null 2> /dev/null
npm run export
mkdir "$PWD/nextStatic"
# ------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------
makeNextSubmodule "qmining-page" "qminingPagePublic" # Creating directory structure
makeNextSubmodule "qmining-data-editor" "dataEditorPublic"
# ------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------
log "mkdir-ing"
log "Making moodle test userscript"
mkdir -pv "$PWD/publicDirs/qminingPublic/moodle-test-userscript"
checkFile "$PWD/submodules/moodle-test-userscript/stable.user.js"
ln -sfv "$PWD/submodules/moodle-test-userscript/stable.user.js" "$PWD/publicDirs/qminingPublic/moodle-test-userscript/"
ln -sfv "$PWD/submodules/moodle-test-userscript/stable.user.js" "$PWD/publicDirs/qminingPublic/"
log "mkdir-ing/touching :3"
# TODO: make server create these itself # TODO: make server create these itself
mkdir -pv stats mkdir -pv stats
mkdir -pv stats/logs mkdir -pv stats/logs
mkdir -pv stats/vlogs mkdir -pv stats/vlogs
mkdir -pv data mkdir -pv data
mkdir -pv data/dbs mkdir -pv data/dbs
touch data/nolog mkdir -p publicDirs/qminingPublic
#JSONS
setupJson stats/stats
setupJson stats/vstats
setupJson stats/idstats
setupJson stats/idvstats
touch publicDirs/qminingPublic/motd touch publicDirs/qminingPublic/motd
# ------------------------------------------------------------------------------------
# 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 if [ -z "$(ls -A ./data/dbs)" ]; then
log "Making DB-s" log "Making DB-s"
pushd src/standaloneUtils || exit cd src/standaloneUtils || exit
NS_SQL_DEBUG_LOG=1 NS_LOGLEVEL=2 node dbSetup.js NS_SQL_DEBUG_LOG=1 NS_LOGLEVEL=2 node dbSetup.js
mv ./*.db ../../data/dbs mv ./*.db ../../data/dbs
popd || exit cd "${baseDir}" || exit
else
log "Dbs already exist, skipping"
fi fi
log "Disabling next telemetry" # ------------------------------------------------------------------------------------
npx --yes next telemetry disable
log "Done! development mode: 'npm run dev', prod mode: 'npm run start', tests: 'npm run test'" log "Done! development mode: 'npm run dev', prod mode: 'npm run start', tests: 'npm run test'"