From 742f3cae05b18e335249d5660421a34820b3a915 Mon Sep 17 00:00:00 2001 From: ION606 Date: Wed, 26 Jun 2024 18:59:59 -0400 Subject: [PATCH] added base adding and removing --- .ionign | 2 ++ change.sh | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ clone.sh | 1 + push.sh | 2 +- run.sh | 8 ++++++ status.sh | 42 +++++++++++++++++++++++++++--- 6 files changed, 128 insertions(+), 5 deletions(-) create mode 100644 .ionign create mode 100644 change.sh diff --git a/.ionign b/.ionign new file mode 100644 index 0000000..eadefd4 --- /dev/null +++ b/.ionign @@ -0,0 +1,2 @@ +.git/* +LICENSE \ No newline at end of file diff --git a/change.sh b/change.sh new file mode 100644 index 0000000..2509e75 --- /dev/null +++ b/change.sh @@ -0,0 +1,78 @@ +#!/bin/bash + +# helper function +file_not_in_ogfiles() { + local file="$1" + for og_file in "${og_files[@]}"; do + if [[ "$og_file" == "$file" ]]; then + return 1 # File found + fi + done + return 0 # File not found +} + + +if [ -z "$2" ]; then + echo -e "\e[31mERROR!\e[0m please specify what to $1, or use \e[34mionvcs $1 .\e[0m to select all" + exit 1 +fi + +action="$1" +regex="$2" + + +# Check the .ionign file +ignore_file="$PWD/.ionign" +if [ -f "$ignore_file" ]; then + # Read the .ionign file into an array + mapfile -t ignore_patterns < "$ignore_file" +else + ignore_patterns=() +fi + +# Find all files that match the regex +matching_files=$(find . -type f | grep -E "./${regex}") +mapfile -t og_files < ".ionvcs/ogfiles.config" + + +# Filter out ignored files +filtered_files=$(echo "$matching_files" | while read -r file; do + ignored=false + for pattern in "${ignore_patterns[@]}"; do + if [[ "$file" == *"$pattern"* ]]; then + ignored=true + break + fi + done + for pattern in "${og_files[@]}"; do + if [[ "$file" == *"$pattern"* ]]; then + ignored=true + break + fi + done + if [ "$ignored" = false ]; then + echo "$file" + fi +done) + +if [ "$action" = "add" ]; then + echo "Added:" + for file in $filtered_files; do + echo -e "\e[0;32m$file\e[0m" + + if ! grep -qx "$file" ".ionvcs/add.config"; then + echo "$file" >> ".ionvcs/add.config" + elif file_not_in_ogfiles "$file"; then + echo "$file" >> ".ionvcs/remove.config" + fi + done + elif [ "$action" = "unstage" ]; then + echo "Unstaged:" + for file in $filtered_files; do + echo -e "\e[0;31m$file\e[0m" + + sed -i "\|^$file$|d" ".ionvcs/add.config" + done +else + exit 1 +fi \ No newline at end of file diff --git a/clone.sh b/clone.sh index 47201e0..29db5c8 100644 --- a/clone.sh +++ b/clone.sh @@ -43,4 +43,5 @@ chmod 600 "$CONF_FILE" # Use rsync with sshpass to copy files with a progress bar echo -n "cloning..." /usr/bin/sshpass -p "$password" rsync -a --info=progress2 --no-i-r -h -e ssh "$REMOTE_PATH" "$DEST_FOLDER" || { echo "failed to clone!"; exit 1; } +echo "$(find . -type f ! -wholename '.ionvcs/*')" > .ionvcs/ogfiles.config echo "done!" \ No newline at end of file diff --git a/push.sh b/push.sh index ee83211..3d0b1fc 100644 --- a/push.sh +++ b/push.sh @@ -45,5 +45,5 @@ fi # Use rsync with sshpass to copy files with a progress bar echo -n "cloning..." -/usr/bin/sshpass -p "$password" rsync -avcn --exclude-from="$PWD/.ionign" --info=progress2 --no-i-r -h -e ssh "$DEST_FOLDER" "$REMOTE_PATH" || { echo "failed to clone!"; exit 1; } +/usr/bin/sshpass -p "$password" rsync -avcn --include-from="$PWD/.ionvcs/add.config" --info=progress2 --no-i-r -h -e ssh "$DEST_FOLDER" "$REMOTE_PATH" || { echo "failed to clone!"; exit 1; } echo "done!" \ No newline at end of file diff --git a/run.sh b/run.sh index b52d736..c742f5c 100644 --- a/run.sh +++ b/run.sh @@ -28,6 +28,14 @@ case $COMMAND in bash $HOME/ionsrc/help.sh ;; + "unstage") + bash $HOME/ionsrc/change.sh unstage "$@" + ;; + + "add") + bash $HOME/ionsrc/change.sh add "$@" + ;; + *) echo "UNKNOWN COMMAND \"$COMMAND\"" GREEN='\033[0;31m' diff --git a/status.sh b/status.sh index 68771f7..9e00912 100644 --- a/status.sh +++ b/status.sh @@ -24,13 +24,47 @@ else fi # Use rsync with sshpass to check for differences without copying -DIFF_OUTPUT=$(/usr/bin/sshpass -p "$password" rsync -avcn --delete -e ssh "$REMOTE_PATH" "$DEST_FOLDER") +DIFF_OUTPUT=$(/usr/bin/sshpass -p "$password" rsync -avcn --delete -e ssh "$REMOTE_PATH" "$DEST_FOLDER") || echo "FAILED TO CONNECT TO SOURCE!" # Check if there are differences if [ ! -z "$DIFF_OUTPUT" ]; then echo -e "\e[1;32mdifferences found\e[0m" echo "$DIFF_OUTPUT" - exit 1; else - echo "no changes found!" -fi \ No newline at end of file + echo "no changes found from remote" +fi + +# Files +ogfiles=".ionvcs/ogfiles.config" +addfiles=".ionvcs/add.config" + +# Check if the necessary files exist +if [ ! -f "$ogfiles" ]; then + echo "The file $ogfiles does not exist." + exit 1 +fi + +if [ ! -f "$addfiles" ]; then + echo "The file $addfiles does not exist." + exit 1 +fi + +# Read the .ionvcs/add.config into an array +mapfile -t add_files < "$addfiles" +mapfile -t all_files < "$ogfiles" + + +# Read the .ionvcs/ogfiles.config and process each line +while IFS= read -r file; do + if [ ! -f "$file" ]; then + # File is not in the current directory + echo -e "\e[0;31m$file\e[0m" + fi +done < "$ogfiles" + +while IFS= read -r file; do + if ! (printf '%s\n' "${all_files[@]}" | grep -qx "$file"); then + # File is in .ionvcs/add.config + echo -e "\e[0;32m$file\e[0m" + fi +done < "$addfiles" \ No newline at end of file