From 844625a84e302078090bcf61c330acd00e5f07c2 Mon Sep 17 00:00:00 2001 From: Khushal P Soonderji Date: Fri, 14 Nov 2025 16:52:50 +0530 Subject: [PATCH] (20251114) Initial Commit. --- .gitignore | 8 ++++ README_GIT.md | 83 +++++++++++++++++++++++++++++++++++++++++ freeze_requirements.sh | 6 +++ from_git.sh | 7 ++++ kill.sh | 16 ++++++++ pull_utils.sh | 6 +++ push_utils.sh | 25 +++++++++++++ requirements.txt | Bin 0 -> 1934 bytes reset_utils.sh | 12 ++++++ rsync_dir.sh | 44 ++++++++++++++++++++++ run.sh | 10 +++++ servers.txt | 3 ++ setup.sh | 20 ++++++++++ ssh_server.sh | 38 +++++++++++++++++++ to_git.sh | 21 +++++++++++ 15 files changed, 299 insertions(+) create mode 100644 .gitignore create mode 100644 README_GIT.md create mode 100644 freeze_requirements.sh create mode 100644 from_git.sh create mode 100644 kill.sh create mode 100644 pull_utils.sh create mode 100644 push_utils.sh create mode 100644 requirements.txt create mode 100644 reset_utils.sh create mode 100644 rsync_dir.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/.gitignore b/.gitignore new file mode 100644 index 0000000..ebb370b --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +/.venv/ +/.idea/ +**/__pycache__/ +__pycache__/ + +*.pem +*.pyc +*.pyd \ No newline at end of file diff --git a/README_GIT.md b/README_GIT.md new file mode 100644 index 0000000..c41f623 --- /dev/null +++ b/README_GIT.md @@ -0,0 +1,83 @@ + +# GIT CHEATSHEET +## By Sharvil (20240927) +Perform these steps on creating a new project. + +_**ASSUMPTION:** You are already in your project directory in the command line terminal._ + +--- + +### STEP 0. +#### Initialize Git in your new project: +Do this when creating a new project directory. +Do this **ONLY ONCE**. +```commandline +git init +``` + +### STEP 1. +#### Create a `.gitignore` file: +Add files/directories in it which you don't want to sync to git. +Update this as frequently as your project needs you to. Start with this: +``` +/.venv/ +/.idea/ +**/__pycache__/ +*.pem +``` + +### STEP 2. +#### Create a repository on Gitea (web UI): +Do this **ONLY ONCE**. +Open the following URL: https://wtt.ditscentre.in/ and sign in. +- Ensure that the owner is `ditscentre` (img 0). +- Give your repository a name. Preferably keep it the same as the project name that you made locally (img 0). +- Type in a brief description of your project (img 0). + +![img 0](https://nexcom.ditscentre.in/utils/files/small/download/66f66a54196705ee2f25d28e) + +- Ensure that the default branch is `master` (img 1). +- Create the repository (img 1). + +![img 1](https://nexcom.ditscentre.in/utils/files/small/download/66f66a54196705ee2f25d28f) + +### STEP 3. +#### Add files and directories to the staging area: +The following command adds everything to the staging area. +The '.' is important, it refers to the current directory. +```commandline +git add . +``` + +### STEP 4. +#### Commit the changes to local git: +This step commits all the added (staged) changes to the local git instance with the provided comment. +```commandline +git commit -m "you comment here..." +``` + +### STEP 5. +#### We push the local commits to the repository: +The format of the command is: +``` +git push -u +``` + +--- + +## For Python Devs: How to add a common subtree (like `utils_v2`) + +The format of the command is: +``` +git subtree add --prefix= --squash +``` +Before you start: ensure that you have committed all pending changes. Then run the following command **ONLY ONCE**: +```commandline +git subtree add --prefix=utils_v2 https://wtt.ditscentre.in/ditscentre/utils_v2.git master --squash +``` +This will create a new directory named `utils_v2` in your project. +**Do NOT change the files in it.** Just import and use them in your scripts. +When you need to get the latest updates to these files, you must run a modification of the previous command: +```commandline +git subtree pull --prefix=utils_v2 https://wtt.ditscentre.in/ditscentre/utils_v2.git master --squash +``` \ No newline at end of file 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..5b73709 --- /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/logs_ui.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..f7fd3c8 --- /dev/null +++ b/kill.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# Kill all the scripts: +echo "Killing the script." +pkill -9 -f "$(pwd)/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/pull_utils.sh b/pull_utils.sh new file mode 100644 index 0000000..3c05dc1 --- /dev/null +++ b/pull_utils.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# To pull any updates made to utils from another project: +echo "Pulling from git." +git subtree pull --prefix=utils_v2 https://wtt.ditscentre.in/ditscentre/utils_v2.git master --squash +echo "Attempt done. Exiting." \ No newline at end of file diff --git a/push_utils.sh b/push_utils.sh new file mode 100644 index 0000000..e2f2eae --- /dev/null +++ b/push_utils.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Move to the directory of the subtree: +echo "Changing directory." +cd "utils_v2" || { echo "Failed to change directory."; exit 1; } + +# Accept a comment from the terminal: +echo "Comment: " +read -r COMMENT + +# Add all the modified files to the intended commit: +git add . +echo "Files added." + +# Make the commit: +git commit -m "$COMMENT" +echo "Commit done." + +# Return to the parent directory: +echo "Returning to parent directory." +cd .. + +echo "Pushing to git." +git subtree push --prefix=utils_v2 https://wtt.ditscentre.in/ditscentre/utils_v2.git master +echo "Attempt done. Exiting." \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..ab2967000cb0f5a12e227e5fd4fcefb173a39b8d GIT binary patch literal 1934 zcmZvd+iu!m5QP8hN_`ZfVCde3=rsZAgC_a@!MbDLhLSNi{6)-LVR@3c;}zTq>I&uu*R!K3YMMMT>J z>!);(b*m~>T1NC#k#8^2%Ty}%lp1-FdoIfmy^Odzsv95CA1=|Q5SGfm4vaf_8)5FE zh%QRmTX|IJP7hTI;Wtw16~Y77QugdYooRX(ueNPfi!P}(5f?jsd({8v>>L#`H_quO ztflZ{dmpvPYa4jUvWPr*z$(!hPiAJ9HsRN(*Hh%0_fx{3Y%68ygrd2i9QZ0OU95zL ziMFasy=ykt=}8&Nm{_F_H{nAxj}@^|hECNyOR$1@Di2V63F{AGWac~N$ed7V-ecXW z0?gI&hB8t`CRhVYt5^8J$9?3EE1{@m8!8y#SH;%pUY25H%beb;e{k)U8{L2- z*DnHvv%KUtQB)JCtR&Qjs+`XV$GY;IzsakW0uGA(sn2)HkTJuZnWK|79fb)+S;gjT z;JyytnqC3sD$j+vqqBvkHlE#}MLg=ziL*bCw-PI5u{zj8HpzW7%KH$CJqG@1sK+y5 zVoj)uTd@?*yYOMpXW^G~oP?qcPiJ8h$Jd1J%4aI3O3^cg$10}atsy!2HgnhPF1?A*mLidwcrV(WbYq2 zUSi49%wUaS9Mf^;|Qyl$`d+j`zLI^ScV851 zahUgBC|rfizJ*4+7r*RH6Bx`~*0HaPcb41dt8OI^xnUH=(`nb&_k405boAKs4YFzI z#7tsqBYve%nay!_eoxHdui(n{=xEqgv&O5t>U4{IMST&5--ulG9O`H5tph5uBUau) enAi_~=VtwMU_0kODy~z -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..1f04461 --- /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 "Files added." + +# Make the commit: +git commit -m "$COMMENT" +echo "Commit done." + +# Push th commit to git: +git push -u https://wtt.ditscentre.in/ditscentre/logs_ui.git master +echo "Attempt done. Exiting." \ No newline at end of file