From 4445bceac05303258ed88a0ee3b657cfdbd7c8b5 Mon Sep 17 00:00:00 2001 From: khushal Date: Thu, 10 Oct 2024 12:06:13 +0530 Subject: [PATCH] (20241010) With some shell scripts. --- api/main.py | 8 +++- freeze_requirements.sh | 6 +++ from_git.sh | 7 ++++ kill.sh | 16 ++++++++ run.sh | 10 +++++ servers.txt | 3 ++ setup.sh | 20 +++++++++ ssh_server.sh | 38 ++++++++++++++++++ to_git.sh | 21 ++++++++++ .../__pycache__/async_quart.cpython-310.pyc | Bin 22964 -> 23261 bytes utils_v2/api/async_quart.py | 3 -- 11 files changed, 127 insertions(+), 5 deletions(-) create mode 100644 freeze_requirements.sh create mode 100644 from_git.sh create mode 100644 kill.sh create mode 100644 run.sh create mode 100644 servers.txt create mode 100644 setup.sh create mode 100644 ssh_server.sh create mode 100644 to_git.sh diff --git a/api/main.py b/api/main.py index 58fd358..e2c5cca 100644 --- a/api/main.py +++ b/api/main.py @@ -273,8 +273,12 @@ async def change_maintenance(action): # Enable or disable debugging only if the password matches: action = action.lower() - if action == "enable": current_app.is_under_maintenance = True - elif action == "disable": current_app.is_under_maintenance = False + if action == "enable": + current_app.is_under_maintenance = True + os.environ["IS_UNDER_MAINTENANCE"] = "True" + elif action == "disable": + current_app.is_under_maintenance = False + os.environ["IS_UNDER_MAINTENANCE"] = "False" return "ok" diff --git a/freeze_requirements.sh b/freeze_requirements.sh new file mode 100644 index 0000000..8984b3a --- /dev/null +++ b/freeze_requirements.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# Just found this better than remembering the freeze command. +# This is beyond silly. +# Okay, bye! +pip3 freeze > requirements.txt \ No newline at end of file diff --git a/from_git.sh b/from_git.sh new file mode 100644 index 0000000..70c21a7 --- /dev/null +++ b/from_git.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +# Run this on the server. +# Not suitable for collaborative environments: +echo "Pulling from git." +git pull https://wtt.ditscentre.in/ditscentre/api_internal.git +echo "Attempt done. Exiting." \ No newline at end of file diff --git a/kill.sh b/kill.sh new file mode 100644 index 0000000..159505a --- /dev/null +++ b/kill.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# Kill all the scripts: +echo "Killing the script." +pkill -9 -f "$(pwd)/api/main.py" + +# Get the name of the current directory, +# and kill the monitors of the above scripts: +echo "Killing the monitors." +PARENT_WD=$(pwd) +CURRENT_DIR_NAME=$(basename "$PARENT_WD") +pgrep -f "$CURRENT_DIR_NAME.*python" | xargs kill -9 + +# All done: +echo "Done!" +exit 0 \ No newline at end of file diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..3688c40 --- /dev/null +++ b/run.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# Use this to run the microservice without any docker setup. +source .venv/bin/activate +python3 "$(pwd)/api/main.py" --host "0.0.0.0" --port 5102 --script-id "yZqq2NVo" --debug & +deactivate + +# All done: +echo "Done!" +exit 0 \ No newline at end of file diff --git a/servers.txt b/servers.txt new file mode 100644 index 0000000..007c32e --- /dev/null +++ b/servers.txt @@ -0,0 +1,3 @@ +kbdev.bicree.com +wtt.ditscentre.in +del.ditscentre.in \ No newline at end of file diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..3c14ed1 --- /dev/null +++ b/setup.sh @@ -0,0 +1,20 @@ +# We create a Virtual Environment. +# The format is: +# python -m venv +echo "Making a virtual environment (if needed)" +python3 -m venv .venv + +# Next we activate the newly created Virtual Environment. +echo "Activating the virtual environment." +source .venv/bin/activate + +# Now we install the requirements. +echo "Installing pending requirements." +pip3 install -r requirements.txt + +# Now we deactivate the Virtual Environment. +echo "Deactivation the virtual environment." +deactivate + +# Setup Done. +echo "Attempt done. Exiting." \ No newline at end of file diff --git a/ssh_server.sh b/ssh_server.sh new file mode 100644 index 0000000..1991711 --- /dev/null +++ b/ssh_server.sh @@ -0,0 +1,38 @@ +#!/bin/bash +# A quick command to connect to any of the available servers. + +# Read the servers from the file into an array: +mapfile -t SERVERS < servers.txt + +# Display the numbered list of server options: +echo "Please select a server:" +for i in "${!SERVERS[@]}"; do + echo "$((i + 1)). ${SERVERS[i]}" +done + +# Prompt the user for their selection +read -rp "Select a server by the number ... : " SELECTION + +# Validate the selection +if [[ $SELECTION -gt 0 && $SELECTION -le ${#SERVERS[@]} ]]; then + + # Note down the selection in a variable: + SELECTED_SERVER=${SERVERS[$((SELECTION - 1))]} + + # Ask the user which directory he wants to upload and his username on the server: + read -rp "Your username on the server ..... : " USER + + # Run the command: + ssh -p 19991 "$USER@$SELECTED_SERVER" + + # Exit with success (assuming that the actual data sending went well): + echo "session ended" + exit 0 + +else + + # In case of a wrong server selection, exit with failure. + echo "Invalid selection. Please run the script again." + exit 1 + +fi diff --git a/to_git.sh b/to_git.sh new file mode 100644 index 0000000..eda8f3d --- /dev/null +++ b/to_git.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# NOTES: +# Run this on the development machine. +# NOT to be used in a collaborative environment: + +# Accept a comment from the terminal: +echo "Comment: " +read -r COMMENT + +# Add all the modified files to the intended commit: +git add . +echo "File added." + +# Make the commit: +git commit -m "$COMMENT" +echo "Commit done." + +# Push th commit to git: +git push -u https://wtt.ditscentre.in/ditscentre/api_internal.git master +echo "Attempt done. Exiting." \ No newline at end of file diff --git a/utils_v2/api/__pycache__/async_quart.cpython-310.pyc b/utils_v2/api/__pycache__/async_quart.cpython-310.pyc index b773a45f024105c14b549ac49456a2947bb2eccd..b8bf0a8b8d1831e9cd49cc29fa609ae46a28c2d4 100644 GIT binary patch delta 2740 zcmaJ@eQZtFERcgCx66>^d+B$8s1VidJVA`f>Q#GmW#?HB> zbC}Rx@_zT+bI;d3_uTXRhDomffOs{J$7O-1?o`qE^reg5YV!Asp`R{LLS3o4Se;sX zQh~RAy(QN01q&^v?nMiAtBq%@u_o%F-bG7nBQ2q&Fm9sjRB242W%Qv%ITmobXqfuc z&A=(A6^pi5kglhdAh(5Xpne!bw1?Kv+C>s;rgc;SPK&e3Sw(wkJzZ!3cB|9%`5%qY zM%o0tt@|D*eF^R00kGW1sNaBIv(cB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3Hu0#2{$7$+C7QHfH+6*7YJXFQ0 z7%TMD+ryg@JT;&%#1vSPuOT#xx7MZN56{(u&Bg4h9UCl)hFA#tqbpbtjz_2c4J@BX AHvj+t diff --git a/utils_v2/api/async_quart.py b/utils_v2/api/async_quart.py index ffcd260..8749a76 100644 --- a/utils_v2/api/async_quart.py +++ b/utils_v2/api/async_quart.py @@ -55,10 +55,7 @@ import datetime # System-level activities: import io -<<<<<<< HEAD -======= import os ->>>>>>> 0450b2a445509ef536ccf8598ab31a0e4ba09f18 # For Pydantic data-behaviour_models: import pydantic