Unix

Contents

Unix#

1#

#!/bin/bash

# Create the bdncsv directory if it doesn't exist
mkdir -p bdncsv

# Find and move all .csv files into the bdncsv directory
find . -maxdepth 1 -type f -iname "*.csv" -exec mv {} bdncsv/ \;

2#

#!/bin/bash

# Create the bdnimages directory if it doesn't exist
mkdir -p bdnimages

# Find and move all .jpg, .jpeg, and .png files into the bdnimages directory
find . -maxdepth 1 -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" \) -exec mv {} bdnimages/ \;

3#

#!/bin/bash

# Create the bdnpdfs directory if it doesn't exist
mkdir -p bdnpdfs

# Find and move all .pdf files into the bdnpdfs directory
find . -maxdepth 1 -type f -iname "*.pdf" -exec mv {} bdnpdfs/ \;

4#

#!/bin/bash

# Create the bdnpy directory if it doesn't exist
mkdir -p bdnpy

# Find and move all .py files into the bdnpy directory
find . -maxdepth 1 -type f -iname "*.py" -exec mv {} bdnpy/ \;

4#

#!/bin/bash

# Create the bdnsh directory if it doesn't exist
mkdir -p bdnsh

# Find and move all .sh files into the bdnsh directory
find . -maxdepth 1 -type f -iname "*.sh" -exec mv {} bdnsh/ \;

5#

#!/bin/bash

# Function to reset to a clean state.
reset_state() {
    # Abort any ongoing rebase.
    git rebase --abort &> /dev/null && echo "Aborted an ongoing rebase."

    # Stash any unstaged changes to ensure operations can proceed.
    git stash save "Unstaged changes before running githis.sh" && echo "Stashed unsaved changes."

    # Remove any lingering rebase directories.
    if [ -d ".git/rebase-merge" ] || [ -d ".git/rebase-apply" ]; then
        rm -rf .git/rebase-*
        echo "Removed lingering rebase directories."
    fi
}

# Navigate to the main working directory.
cd ~/dropbox/1f.ἡἔρις,κ/1.ontology

# Navigate to the six100 directory.
cd six100 || { echo "Directory six100 does not exist. Exiting."; exit 1; }

# Reset to a clean state.
reset_state

# Fetch the latest changes from temp_og_repo using SSH.
if git fetch git@github.com:afecdvi/temp_og_repo.git main; then
    echo "Successfully fetched changes via SSH."
else
    echo "Failed to fetch changes using SSH. Exiting."
    exit 1
fi

# Reset the local branch to match the fetched changes.
git reset --hard FETCH_HEAD
echo "Local branch reset to match fetched changes."

# Check for network connection.
if ! ping -c 1 google.com &> /dev/null; then
    echo "No internet connection. Exiting."
    exit 1
fi

# Check repository size.
REPO_SIZE=$(du -sh .git | cut -f1)
echo "Repository size: $REPO_SIZE"

# Adjust Git configurations.
POST_BUFFER_SIZE=$(( (RANDOM % 200 + 300) * 1048576 ))
LOW_SPEED_LIMIT=$(( RANDOM % 5000 + 2000 ))
LOW_SPEED_TIME=$(( RANDOM % 60 + 30 ))

git config http.postBuffer $POST_BUFFER_SIZE
git config http.lowSpeedLimit $LOW_SPEED_LIMIT
git config http.lowSpeedTime $LOW_SPEED_TIME
echo "Adjusted Git's buffer size to $POST_BUFFER_SIZE, low speed limit to $LOW_SPEED_LIMIT and low speed time to $LOW_SPEED_TIME."

# Push the changes to the remote repository using SSH and verbose logging.
if git push git@github.com:afecdvi/og.git main --force -v; then
    echo "Successfully pushed changes using SSH."
    # Unstash any changes we stashed earlier.
    git stash pop &> /dev/null && echo "Restored previously stashed changes."
    echo "Script completed successfully!"
else
    echo "Failed to push changes even with SSH. Exiting."
    git stash pop &> /dev/null && echo "Restored previously stashed changes."
    exit 1
fi