Auto-update: Wed Jun 26 10:08:59 PDT 2024

This commit is contained in:
sanj 2024-06-26 10:08:59 -07:00
parent fc622ee3fc
commit 5fb31080f2
3 changed files with 136 additions and 15 deletions

BIN
.DS_Store vendored

Binary file not shown.

75
pf Executable file
View file

@ -0,0 +1,75 @@
#!/usr/bin/python3
import socket
import threading
import select
def forward(source, destination):
try:
while True:
ready, _, _ = select.select([source], [], [], 1)
if ready:
data = source.recv(4096)
if not data:
break
destination.sendall(data)
except (OSError, socket.error) as e:
print(f"Connection error: {e}")
finally:
try:
source.shutdown(socket.SHUT_RD)
except OSError:
pass
try:
destination.shutdown(socket.SHUT_WR)
except OSError:
pass
def handle(client_socket, remote_host, remote_port):
try:
remote_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
remote_socket.connect((remote_host, remote_port))
thread1 = threading.Thread(target=forward, args=(client_socket, remote_socket))
thread2 = threading.Thread(target=forward, args=(remote_socket, client_socket))
thread1.start()
thread2.start()
thread1.join()
thread2.join()
except Exception as e:
print(f"Error in handle: {e}")
finally:
client_socket.close()
remote_socket.close()
def create_forwarder(local_host, local_port, remote_host, remote_port):
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_socket.bind((local_host, local_port))
server_socket.listen(5)
print(f"Forwarding {local_host}:{local_port} to {remote_host}:{remote_port}")
while True:
try:
client_socket, address = server_socket.accept()
print(f"Received connection from {address}")
threading.Thread(target=handle, args=(client_socket, remote_host, remote_port)).start()
except Exception as e:
print(f"Error accepting connection: {e}")
def main():
listen_ip = '0.0.0.0'
imap_thread = threading.Thread(target=create_forwarder, args=(listen_ip, 1143, '127.0.0.1', 1142))
imap_thread.start()
smtp_thread = threading.Thread(target=create_forwarder, args=(listen_ip, 1025, '127.0.0.1', 1024))
smtp_thread.start()
imap_thread.join()
smtp_thread.join()
if __name__ == "__main__":
main()

76
up
View file

@ -1,23 +1,69 @@
#!/bin/bash #!/bin/bash
# Navigate to your project directory # Path to the file containing the list of repositories
cd ~/workshop/sijapi REPOS_FILE=~/workshop/repos.txt
# Pull the latest changes from the repository # Check if the repos file exists
echo "Pulling from main branch..." if [ ! -f "$REPOS_FILE" ]; then
git pull origin main echo "Error: $REPOS_FILE does not exist."
exit 1
fi
# Add changes to the Git index (staging area) # Read the repos file and process each directory
echo "Adding all changes..." while IFS= read -r repo_path || [[ -n "$repo_path" ]]; do
git add . # Trim whitespace
repo_path=$(echo "$repo_path" | xargs)
# Commit changes # Skip empty lines
echo "Committing changes..." [ -z "$repo_path" ] && continue
git commit -m "Auto-update: $(date)"
# Push changes to the remote repository # Expand tilde to home directory
echo "Pushing all changes..." repo_path="${repo_path/#\~/$HOME}"
git push origin main
echo "Update complete!" # Check if the directory exists
if [ ! -d "$repo_path" ]; then
echo "Warning: Directory $repo_path does not exist. Skipping."
continue
fi
echo "Processing repository: $repo_path"
# Navigate to the project directory
cd "$repo_path" || { echo "Error: Unable to change to directory $repo_path"; continue; }
# Check if it's a git repository
if [ ! -d .git ]; then
echo "Warning: $repo_path is not a git repository. Skipping."
continue
fi
# Get the current branch
current_branch=$(git rev-parse --abbrev-ref HEAD)
# Pull the latest changes from the repository
echo "Pulling from $current_branch branch..."
git pull origin "$current_branch"
# Add changes to the Git index (staging area)
echo "Adding all changes..."
git add .
# Check if there are changes to commit
if git diff-index --quiet HEAD --; then
echo "No changes to commit."
else
# Commit changes
echo "Committing changes..."
git commit -m "Auto-update: $(date)"
# Push changes to the remote repository
echo "Pushing all changes..."
git push origin "$current_branch"
fi
echo "Update complete for $repo_path!"
echo "----------------------------------------"
done < "$REPOS_FILE"
echo "All repositories processed."