Index: .gitignore =================================================================== diff -u -r19632962daaf74f75aebddb56833168214339903 -r0a37372b3a9d73b6a2781b7519e2b1ba78cd0da5 --- .gitignore (.../.gitignore) (revision 19632962daaf74f75aebddb56833168214339903) +++ .gitignore (.../.gitignore) (revision 0a37372b3a9d73b6a2781b7519e2b1ba78cd0da5) @@ -1,3 +1,5 @@ _MCOSX .DS_Store + +*.sh~ Index: DRT Server Setup Instruction.docx =================================================================== diff -u Binary files differ Index: DRT application install & config - fundamentals.txt =================================================================== diff -u --- DRT application install & config - fundamentals.txt (revision 0) +++ DRT application install & config - fundamentals.txt (revision 0a37372b3a9d73b6a2781b7519e2b1ba78cd0da5) @@ -0,0 +1,39 @@ + +A. Install dependencies: + + 1. Install node v16 + + sudo apt update && sudo apt install curl + + curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - + sudo apt-get install -y nodejs + + node -v (confirm version 16 is running) + + + 2. Install Redis + + sudo apt install redis-server + + +B. Deploy latest version of the DRT app (git clone preferred) + +C. Install app dependencies + + npm install + +D. Change configuration for DRT environment + + change apps/mt-client/src/environments/environment.prod.ts - with specific env conf + + change .env - with specific env conf + +E. Build application + + npm run build:client + + npm run build:api + +F. Start application + + node ./dist/apps/mt-api/main.js \ No newline at end of file Fisheye: Tag 0a37372b3a9d73b6a2781b7519e2b1ba78cd0da5 refers to a dead (removed) revision in file `DRT application install & config - v.0.2.6.txt'. Fisheye: No comparison available. Pass `N' to diff? Index: environments/production/.env =================================================================== diff -u --- environments/production/.env (revision 0) +++ environments/production/.env (revision 0a37372b3a9d73b6a2781b7519e2b1ba78cd0da5) @@ -0,0 +1,14 @@ +KC_SERVER=https://identity.moda-flx-connect.com/auth +KC_TOKEN=https://identity.moda-flx-connect.com/auth/realms/Main/protocol/openid-connect/token +KC_CLIENT=MtClient +KC_SECRET=dfEkuOB64QQcAIPUOU78dKJblDydmr5L +KC_REALM=Main +KC_ISSUER=https://identity.moda-flx-connect.com/auth/realms/Main +TOKEN_LIFETIME=5 +CLOUD_ENDPOINT=https://api.moda-flx-connect.com +PM2_PUBLIC_KEY=q465bgyvfmbel6r +PM2_SECRET_KEY=qkil6kfd643m8tu +DEVICE_HTTP_PORT=80 +DEVICE_HTTP_SCHEMA=http +REDIS_HOST=localhost +REDIS_PORT=6379 Index: environments/production/environment.prod.ts =================================================================== diff -u --- environments/production/environment.prod.ts (revision 0) +++ environments/production/environment.prod.ts (revision 0a37372b3a9d73b6a2781b7519e2b1ba78cd0da5) @@ -0,0 +1,15 @@ +export const environment = { + production: true, + api: 'http://:3000', + ws: 'wss://:3000', + auth: { + issuer: 'https://identity.moda-flx-connect.com/auth/realms/Main', + redirectUri: 'http://:3000', + silentRefreshRedirectUri: 'http://:3000/silent-refresh.html', + clientId: 'frontend-client', + requireHttps: false, + scope: 'openid profile email offline_access', + responseType: 'code', + disableAtHashCheck: true + } +}; Index: environments/quality/.env =================================================================== diff -u --- environments/quality/.env (revision 0) +++ environments/quality/.env (revision 0a37372b3a9d73b6a2781b7519e2b1ba78cd0da5) @@ -0,0 +1,15 @@ +KC_SERVER=https://identity.diality.qa.kebormed.com/auth +KC_TOKEN=https://identity.diality.qa.kebormed.com/auth/realms/Main/protocol/openid-connect/token +KC_CLIENT=MtClient +KC_SECRET=dfEkuOB64QQcAIPUOU78dKJblDydmr5L +KC_REALM=Main +KC_ISSUER=https://identity.diality.qa.kebormed.com/auth/realms/Main +TOKEN_LIFETIME=5 + +CLOUD_ENDPOINT=https://api.diality.qa.kebormed.com + +DEVICE_HTTP_PORT=80 +DEVICE_HTTP_SCHEMA=http + +REDIS_HOST=localhost +REDIS_PORT=6379 Index: environments/quality/environment.prod.ts =================================================================== diff -u --- environments/quality/environment.prod.ts (revision 0) +++ environments/quality/environment.prod.ts (revision 0a37372b3a9d73b6a2781b7519e2b1ba78cd0da5) @@ -0,0 +1,15 @@ +export const environment = { + production: true, + api: 'http://:3000', + ws: 'wss://:3000', + auth: { + issuer: 'https://identity.diality.qa.kebormed.com/auth/realms/Main', + redirectUri: 'http://:3000', + silentRefreshRedirectUri: 'http://:3000/silent-refresh.html', + clientId: 'frontend-client', + requireHttps: false, + scope: 'openid profile email offline_access', + responseType: 'code', + disableAtHashCheck: true + } +}; Index: environments/staging/.env =================================================================== diff -u --- environments/staging/.env (revision 0) +++ environments/staging/.env (revision 0a37372b3a9d73b6a2781b7519e2b1ba78cd0da5) @@ -0,0 +1,17 @@ +KC_SERVER=https://identity.diality.staging.kebormed.com/auth +KC_TOKEN=https://identity.diality.staging.kebormed.com/auth/realms/Main/protocol/openid-connect/token +KC_CLIENT=MtClient +KC_SECRET=ZzpgJ2ZMANYKcQIDTQTyiSLJyr3sphJv +KC_REALM=Main +KC_ISSUER=https://identity.diality.staging.kebormed.com/auth/realms/Main +TOKEN_LIFETIME=5 + + +CLOUD_ENDPOINT=https://api.diality.staging.kebormed.com + + +DEVICE_HTTP_PORT=80 +DEVICE_HTTP_SCHEMA=http + +REDIS_HOST=localhost +REDIS_PORT=6379 Index: environments/staging/environment.prod.ts =================================================================== diff -u --- environments/staging/environment.prod.ts (revision 0) +++ environments/staging/environment.prod.ts (revision 0a37372b3a9d73b6a2781b7519e2b1ba78cd0da5) @@ -0,0 +1,15 @@ +export const environment = { + production: true, + api: 'http://172.31.99.117:3000', + ws: 'wss://172.31.99.117:3000', + auth: { + issuer: 'https://identity.diality.staging.kebormed.com/auth/realms/Main', + redirectUri: 'http://172.31.99.117:3000', + silentRefreshRedirectUri: 'http://172.31.99.117:3000/silent-refresh.html', + clientId: 'frontend-client', + requireHttps: false, + scope: 'openid profile email offline_access', + responseType: 'code', + disableAtHashCheck: true + } +}; Index: install.sh =================================================================== diff -u --- install.sh (revision 0) +++ install.sh (revision 0a37372b3a9d73b6a2781b7519e2b1ba78cd0da5) @@ -0,0 +1,308 @@ +#!/bin/bash + +TRUE=0 +FALSE=1 + +# ---------- Error definition +ERR_DRT_SERVER_DIR_EXISTS=1 +ERR_DRT_SERVER_ENV_INVALID=2 +ERR_DRT_SERVER_IP_EMPTY=3 +ERR_DRT_SERVER_NJS_FAILED=4 +ERR_DRT_SERVER_RED_FAILED=5 +ERR_DRT_SERVER_ENV_NOTFOUND=6 +ERR_DRT_SERVER_ENV_ENV_NOTFOUND=7 +ERR_DRT_SERVER_ENV_PTS_NOTFOUND=8 +ERR_DRT_SERVER_ENV_PTS_IP_SET=9 + +# ---------- Varialbes definition +HOSTNAME=$(hostname) +ENVIRONMENT_LIST="production staging quality" + +# ---------- DRT Server Variables +DRT_SERVER_DIR="drt-server" +DRT_SERVER_SRC=/boot/$DRT_SERVER_DIR +DRT_SERVER_DST=$HOME/$DRT_SERVER_DIR +DRT_SERVER_ENV="${HOSTNAME:4}" +DRT_SERVER_IP="$(ip -4 address show wlan0 | grep -oP '\d+.\d+.\d+.\d+' | head -n1)" +DRT_SERVER_NJS="" +DRT_SERVER_RED="" +DRT_SERVER_ENV_DIR="environments" +DRT_SERVER_ENV_PATH=$DRT_SERVER_DST/$DRT_SERVER_ENV_DIR +DRT_SERVER_ENV_ENV=".env" +DRT_SERVER_ENV_PTS="environment.prod.ts" +DRT_SERVER_ENV_PTS_DST="apps/mt-client/src/environments/" +DRT_SERVER_ENV_PTS_IP_PLACEHOLDER="" + +# ---------------------------------------------------------------------------------------------------- +# -------------------------------------------------- OS Configuration, Setup +# ---------------------------------------------------------------------------------------------------- + +function check_print() { + echo "Environment : $DRT_SERVER_ENV" + echo "IP Address : $DRT_SERVER_IP" + echo "Node JS : $DRT_SERVER_NJS" + echo "Redis Server : $DRT_SERVER_RED" +} + +function check_environment() { + local ENV=$( grep "$DRT_SERVER_ENV" <<< "$ENVIRONMENT_LIST" ) + if [[ -z $ENV ]]; then + echo "---------------------------------------- ERR: Invalid environment '$DRT_SERVER_ENV' " + exit $ERR_DRT_SERVER_ENV_INVALID + fi +} + +function check_ip() { + local IP=$( grep "$DRT_SERVER_ENV" <<< "$ENVIRONMENT_LIST" ) + if [[ -z $DRT_SERVER_IP ]]; then + echo "---------------------------------------- ERR: Server IP is not set " + exit $ERR_DRT_SERVER_IP_EMPTY + fi +} + +function version_node_js() { + DRT_SERVER_NJS="$(node -v)" +} + +function install_node_js() { + version_node_js + if [[ -n "$DRT_SERVER_NJS" ]]; then + echo "---------------------------------------- NodeJs already installed $DRT_SERVER_NJS " + return + fi + cd + curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - + sudo apt install nodejs -y + version_node_js + if [[ -z "$DRT_SERVER_NJS" ]]; then + echo "---------------------------------------- ERR: NodeJs installation FAILED " + exit $ERR_DRT_SERVER_NJS_FAILED + fi +} + +function version_redis_server() { + DRT_SERVER_RED="$(redis-server -v | grep -oP '\d+.\d+.\d+' | head -n1)" +} + +function install_redis_server() { + version_redis_server + if [[ -n "$DRT_SERVER_RED" ]]; then + echo "---------------------------------------- Redis Server already installed $DRT_SERVER_RED " + return + fi + cd + sudo apt install redis-server -y + version_redis_server + if [[ -z "$DRT_SERVER_RED" ]]; then + echo "---------------------------------------- ERR: Redis Server installation FAILED" + exit $ERR_DRT_SERVER_RED_FAILED + fi +} + +# ---------------------------------------------------------------------------------------------------- +# -------------------------------------------------- DRT SERVER +# ---------------------------------------------------------------------------------------------------- + +function drt_server_copy() { + local CONTINUE="N" + if [[ -d $DRT_SERVER_DST ]]; then + read -p "The $DRT_SERVER_DST exists, if you continue the entire content will be removed. continue? [y/N]" -n 1 -i "N" -r CONTINUE + echo "" + if [ "$CONTINUE" == "Y" ] || [ "$CONTINUE" == "y" ]; then + echo "---------------------------------------- DRT Server removing the folder '$DRT_SERVER_DST'" + rm -frd $DRT_SERVER_DST + sync;sync;sync + else + echo "---------------------------------------- ERR: DRT Server installation ABORT" + exit $ERR_DRT_SERVER_DIR_EXISTS + fi + fi + cp -r $DRT_SERVER_SRC $DRT_SERVER_DST + echo "---------------------------------------- DRT Server copied to the folder '$PWD'" +} + +function drt_server_install() { + cd $DRT_SERVER_DST + echo "current path '$PWD'" + npm install +} + +function drt_server_configuration() { + local ENV_DIR_SRC=$DRT_SERVER_ENV_PATH/$DRT_SERVER_ENV + local ENV_ENV_FILE_SRC=$ENV_DIR_SRC/$DRT_SERVER_ENV_ENV + local ENV_ENV_FOLD_DST=$DRT_SERVER_DST + local ENV_PTS_FILE_SRC=$ENV_DIR_SRC/$DRT_SERVER_ENV_PTS + local ENV_PTS_FOLD_DST=$DRT_SERVER_DST/$DRT_SERVER_ENV_PTS_DST + local ENV_PTS_FILE_DST=$ENV_PTS_FOLD_DST/$DRT_SERVER_ENV_PTS + + if [[ -d $ENV_DIR_SRC ]]; then + # ---------- copy env file + cp $ENV_ENV_FILE_SRC $ENV_ENV_FOLD_DST + if [[ ! $? ]]; then + echo "---------------------------------------- ERR: DRT Server env file cannot be set" + exit $ERR_DRT_SERVER_ENV_ENV_NOTFOUND + fi + + # ---------- copy .ts file + cp $ENV_PTS_FILE_SRC $ENV_PTS_FOLD_DST + if [[ ! $? ]]; then + echo "---------------------------------------- ERR: DRT Server .ts file cannot be set" + exit $ERR_DRT_SERVER_ENV_PTS_NOTFOUND + fi + fi + + # ---------- set server ip + sed -i "s/$DRT_SERVER_ENV_PTS_IP_PLACEHOLDER/$DRT_SERVER_IP/" $ENV_PTS_FILE_DST + if [[ ! $? ]]; then + echo "---------------------------------------- ERR: DRT Server .ts file cannot be configured" + exit $ERR_DRT_SERVER_ENV_PTS_IP_SET + fi +} + +function drt_server_build() { + cd $DRT_SERVER_DST + npm run build:client + npm run build:api +} + +function drt_server_autostart() { + # create a symlink for manual execution + # TODO create a script to stop/start the service instead of a direct symlink + local RUNSH="run.sh" + cd $DRT_SERVER_DST + echo -e "#!/bin/bash\n" \ + "\n" \ + "function is_running() {\n" \ + " if [[ -n \$(ps aux | grep \"node dist\" | grep -v grep) ]]\n" \ + " then return $TRUE; else return $FALSE; fi\n" \ + "}\n" \ + "\n" \ + "function is_kill() {\n" \ + " if [[ \"\$1\" == \"-k\" ]]\n" \ + " then return $TRUE; else return $FALSE; fi\n" \ + "}\n" \ + "\n" \ + "function is_status() {\n" \ + " if [[ \"\$1\" == \"-s\" ]]\n" \ + " then return $TRUE; else return $FALSE; fi\n" \ + "}\n" \ + "\n" \ + "function is_help() {\n" \ + " if [[ \"\$1\" == \"-h\" ]]\n" \ + " then\n" \ + " echo \"-h displays help\"\n" \ + " echo \"-s displays DRT Server status (optional)\"\n" \ + " echo \"-k kills DRT Server\"\n" \ + " exit 0\n" \ + " fi\n" \ + "}\n" \ + "\n" \ + "is_help \$1\n" \ + "\n" \ + "if is_running; then\n" \ + " if is_kill \$1; then\n" \ + " echo \"--------------------------------------- DRT Server is stopping\"\n" \ + " killall node\n" \ + " sleep 5\n" \ + " if is_running; then\n" \ + " echo \"--------------------------------------- DRT Server stop FAILED\"\n" \ + " else\n" \ + " echo \"--------------------------------------- DRT Server stopped\"\n" \ + " fi\n" \ + " exit 0\n" \ + " else\n" \ + " echo \"--------------------------------------- DRT Server is running\"\n" \ + " exit 0\n" \ + " fi\n" \ + "else\n" \ + " if is_kill \$1 || is_status \$1; then\n" \ + " echo \"--------------------------------------- DRT Server is NOT running\"\n" \ + " exit 0\n" \ + " fi\n" \ + "fi\n" \ + "\n" \ + "echo \"--------------------------------------- DRT Server starting ...\"\n" \ + "cd /home/denali/drt-server\n" \ + "node dist/apps/mt-api/main.js &\n" \ + "sleep 10\n" \ + "if is_running; then\n" \ + " echo \"--------------------------------------- DRT Server started\"\n" \ + "else\n" \ + " echo \"---------------------------------- ERR: DRT Server start FAILED\"\n" \ + "fi\n" \ + "\n" \ + > $RUNSH + + chmod a+x $RUNSH + + cd + if [ -e drt ]; then rm drt; fi + ln -s $DRT_SERVER_DST/run.sh drt + + # TODO : add a service to autostart the drt server on each reboot + + # create drt-server.service + # [Unit] + # Description=DRT Server + # Wants= + # + # [Service] + # ExecStart=/path/to/your/executable + # # Add any other relevant configuration options here + # + # [Install] + # WantedBy=multi-user.target + + # systemctl enable drt-server + # systemctl start drt-server +} + +function drt_server_cleanup() { + # ---------- remove the residue env files + rm -frd $DRT_SERVER_ENV_PATH +} + +# ---------------------------------------------------------------------------------------------------- +# -------------------------------------------------- MAIN +# ---------------------------------------------------------------------------------------------------- + +echo "---------------------------------------- Checking OS" +check_environment +check_ip + +echo "---------------------------------------- Updating OS" +sudo apt update +sudo apt upgrade -y + +echo "---------------------------------------- Installing curl" +sudo apt install curl + +echo "---------------------------------------- Installing NodeJS" +install_node_js + +echo "---------------------------------------- Installing Redis Server" +install_redis_server + +echo "---------------------------------------- DRT-Server Copy" +drt_server_copy + +echo "---------------------------------------- DRT-Server Install" +drt_server_install + +echo "---------------------------------------- DRT-Server Configuration" +drt_server_configuration + +echo "---------------------------------------- DRT-Server Build" +drt_server_build + +echo "---------------------------------------- DRT-Server Autostart" +drt_server_autostart + +echo "---------------------------------------- DRT-Server Cleanup" +drt_server_cleanup + +echo "---------------------------------------- Installation summary" +check_print +echo "---------------------------------------- Installation Complete" + + Index: readme.md =================================================================== diff -u --- readme.md (revision 0) +++ readme.md (revision 0a37372b3a9d73b6a2781b7519e2b1ba78cd0da5) @@ -0,0 +1,12 @@ +Version: 0.2.7 + +After the version 0.2.6 with the 0.2.7 an auto mated installation script has been created. +The current installation uses the RaspberryPi 4B 4GB as the main device to install the DRT. +The instruction to setup the DRT server is added to this repository and will later officially added to the document management system. + +Read the DRT application install & config - fundamentals.txt +to know what has to be done in details on any linux server + +Read DRT Server Setup Instruction.dox +to know how to setup a DRT server from scratch on a RaspberyPi 4B 4GB +