-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/JAlcocerT/Linux
- Loading branch information
Showing
23 changed files
with
687 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/bash | ||
|
||
# Define the base directory where the repositories are/will be located | ||
BASE_DIR="/home/jalcocert/Desktop/GIT_SYNC/GITEA" | ||
|
||
# Ensure the base directory exists | ||
mkdir -p "$BASE_DIR" | ||
|
||
# Define repository URLs - GITEA | ||
REPO1_URL="http://192.168.3.200:3033/fossengineer/FOSSENGINEER.git" | ||
REPO2_URL="http://192.168.3.200:3033/fossengineer/Py_Stocks.git" | ||
|
||
# Define local directories (relative to BASE_DIR) where you want to pull the repositories | ||
REPO1_DIR="${BASE_DIR}/FOSSENGINEER" | ||
REPO2_DIR="${BASE_DIR}/Py_Stocks" | ||
|
||
# Function to pull or clone a repository | ||
pull_or_clone() { | ||
local repo_url=$1 | ||
local repo_dir=$2 | ||
|
||
# Check if the directory exists and is a git repository | ||
if [ -d "$repo_dir/.git" ]; then | ||
echo "Updating $repo_dir from $repo_url" | ||
git -C "$repo_dir" pull | ||
else | ||
echo "Cloning $repo_url into $repo_dir" | ||
git clone "$repo_url" "$repo_dir" | ||
fi | ||
} | ||
|
||
# Pull or clone each repository | ||
pull_or_clone "$REPO1_URL" "$REPO1_DIR" | ||
pull_or_clone "$REPO2_URL" "$REPO2_DIR" | ||
|
||
echo "Operation completed." |
88 changes: 88 additions & 0 deletions
88
Z_Linux_Installations_101/Cron_Examples/git_sync_uptimekuma.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import requests | ||
import datetime | ||
from pathlib import Path | ||
import subprocess | ||
|
||
# Repositories to update: (URL, local directory name) | ||
REPOSITORIES = [ | ||
("http://192.168.3.200:3033/fossengineer/FOSSENGINEER.git", "FOSSENGINEER"), | ||
("http://192.168.3.200:3033/fossengineer/Py_Stocks.git", "Py_Stocks"), | ||
] | ||
|
||
BASE_DIR = "/home/jalcocert/Desktop/GIT_SYNC/GITEA3" | ||
UPTIME_KUMA_PUSH_URL = "http://192.168.3.200:3001/api/push/Xe6iHxz97X?status=up&msg=OK&ping=" #"http://uptimekuma.mydomain.com/api/push/xyz" | ||
|
||
def git_clone_or_pull(repo_url, local_dir): | ||
"""Clones the repo if it doesn't exist, or pulls updates if it does.""" | ||
subprocess.run(["mkdir", "-p", str(local_dir)], check=True) | ||
if (local_dir / ".git").exists(): | ||
print(f"Updating existing repository in {local_dir}") | ||
subprocess.run(["git", "-C", str(local_dir), "pull"], check=True) | ||
else: | ||
print(f"Cloning new repository from {repo_url} into {local_dir}") | ||
subprocess.run(["git", "clone", repo_url, str(local_dir)], check=True) | ||
|
||
def update_status(): | ||
"""Sends a GET request to the Uptime Kuma monitoring endpoint.""" | ||
try: | ||
response = requests.get(UPTIME_KUMA_PUSH_URL) | ||
response.raise_for_status() | ||
print("Status update sent successfully.") | ||
except requests.RequestException as e: | ||
print(f"Failed to send status update to Uptime Kuma: {e}") | ||
|
||
def main(): | ||
for repo_url, repo_dir in REPOSITORIES: | ||
git_clone_or_pull(repo_url, Path(BASE_DIR) / repo_dir) | ||
|
||
# Send a GET request to Uptime Kuma's push URL to signal success | ||
update_status() | ||
|
||
if __name__ == "__main__": | ||
main() | ||
|
||
|
||
|
||
# import subprocess | ||
# import requests | ||
# import datetime | ||
|
||
# # Repositories to update: (URL, local directory name) | ||
# REPOSITORIES = [ | ||
# ("http://192.168.3.200:3033/fossengineer/FOSSENGINEER.git", "FOSSENGINEER"), | ||
# ("http://192.168.3.200:3033/fossengineer/Py_Stocks.git", "Py_Stocks"), | ||
# ] | ||
|
||
# BASE_DIR = "/home/jalcocert/Desktop/GIT_SYNC/GITEA2" | ||
# STATUS_ENDPOINT = "http://yourserver:5000/update_status" | ||
|
||
# def git_clone_or_pull(repo_url, local_dir): | ||
# """Clones the repo if it doesn't exist, or pulls updates if it does.""" | ||
# subprocess.run(["mkdir", "-p", local_dir], check=True) | ||
# if (local_dir / ".git").exists(): | ||
# print(f"Updating existing repository in {local_dir}") | ||
# subprocess.run(["git", "-C", local_dir, "pull"], check=True) | ||
# else: | ||
# print(f"Cloning new repository from {repo_url} into {local_dir}") | ||
# subprocess.run(["git", "clone", repo_url, local_dir], check=True) | ||
|
||
# def update_status(message): | ||
# """Sends a status update to the monitoring endpoint.""" | ||
# try: | ||
# response = requests.post(STATUS_ENDPOINT, data=message) | ||
# response.raise_for_status() | ||
# print("Status update sent successfully.") | ||
# except requests.RequestException as e: | ||
# print(f"Failed to send status update: {e}") | ||
|
||
# def main(): | ||
# from pathlib import Path | ||
# for repo_url, repo_dir in REPOSITORIES: | ||
# git_clone_or_pull(repo_url, Path(BASE_DIR) / repo_dir) | ||
|
||
# # Update the monitoring endpoint with completion status | ||
# now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') | ||
# update_status(f"Git sync script completed successfully at {now}") | ||
|
||
# if __name__ == "__main__": | ||
# main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/bash | ||
|
||
# Define the base directory where the repositories are/will be located | ||
BASE_DIR="/home/jalcocert/Desktop/GIT_SYNC/GITEA" | ||
|
||
# Ensure the base directory exists | ||
mkdir -p "$BASE_DIR" | ||
|
||
# Function to pull or clone a repository | ||
pull_or_clone() { | ||
local repo_url=$1 | ||
local repo_dir=$2 | ||
|
||
# Ensure the directory exists for the repo | ||
mkdir -p "$repo_dir" | ||
|
||
# Check if the directory exists and is a git repository | ||
if [ -d "$repo_dir/.git" ]; then | ||
echo "Updating $repo_dir from $repo_url" | ||
git -C "$repo_dir" pull | ||
else | ||
echo "Cloning $repo_url into $repo_dir" | ||
git clone "$repo_url" "$repo_dir" | ||
fi | ||
} | ||
|
||
# Loop through the arguments two by two (URL and DIR) | ||
while (( "$#" >= 2 )); do | ||
repo_url=$1 | ||
repo_dir="${BASE_DIR}/$2" | ||
pull_or_clone "$repo_url" "$repo_dir" | ||
# Shift by two to get to the next pair of arguments | ||
shift 2 | ||
done | ||
|
||
echo "Operation completed." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
* <https://jalcocert.github.io/Linux/docs/debian/useful_tools/#crontab-tasks> | ||
|
||
* v1 - hardcoded repositories | ||
* v2 - listed repositories | ||
|
||
```sh | ||
chmod +x /home/jalcocert/Desktop/GIT_SYNC/git_sync_v2.sh | ||
/home/jalcocert/Desktop/GIT_SYNC/git_sync_v2.sh http://192.168.3.200:3033/fossengineer/FOSSENGINEER FOSSENGINEER http://192.168.3.200:3033/fossengineer/Py_Stocks Py_Stocks | ||
``` | ||
|
||
|
||
@reboot /home/jalcocert/Desktop/GIT_SYNC/git_sync_v2.sh http://192.168.3.200:3033/fossengineer/BachataMeetv2-Astro BachataMeetv2-Astro http://192.168.3.200:3033/fossengineer/CyclingThere2 CyclingThere2 >> /home/jalcocert/Desktop/GIT_SYNC/git_sync_v2.log 2>&1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.