From ce895bddaafc4053931551d222cf4610df854dda Mon Sep 17 00:00:00 2001 From: ION606 Date: Wed, 26 Jun 2024 12:03:29 -0400 Subject: [PATCH] initial code commit --- .gitignore | 1 + README.md | 24 +++++++++++++++++++++++- clone.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ getuser.sh | 8 ++++++++ help.sh | 11 +++++++++++ init.sh | 10 ++++++++++ ionsrc.desktop | 9 +++++++++ login.sh | 19 +++++++++++++++++++ push.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ run.sh | 30 ++++++++++++++++++++++++++++++ 10 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 clone.sh create mode 100644 getuser.sh create mode 100644 help.sh create mode 100644 init.sh create mode 100644 ionsrc.desktop create mode 100644 login.sh create mode 100644 push.sh create mode 100644 run.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7de9e31 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.ionvcs \ No newline at end of file diff --git a/README.md b/README.md index cf182bd..4a50731 100644 --- a/README.md +++ b/README.md @@ -1 +1,23 @@ -# VCS \ No newline at end of file +# My remote sourcing system + +## Running +## Option 1: The Script +just use `curl -fsSL -o ivcs.sh https://github.com/ION606/VCS/raw/main/setup.sh && chmod +x ivcs.sh && sudo ./ivcs.sh` + + +## Option 2: Maually +1. install `sshpass ssh pv` using your package manager +2. clone `https://github.com/ION606/VCS.git` +3. move `ionsrc.desktop` to wherever your system stores .desktop files +4. move the rest of the files to `~/ionsrc/` + +## Commands +format: `ionvcs [args]` + +| Command | Args | Description | +|----------|-------------|---------------------------------| +| clone | \ | Clone a repository. | +| user | \ | Get user information. | +| init | N/A | Initialize a repository. | +| login | N/A | Login to the system. | +| push | [-f] | Push changes to the repository. | \ No newline at end of file diff --git a/clone.sh b/clone.sh new file mode 100644 index 0000000..1e9f226 --- /dev/null +++ b/clone.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# Navigate to the current working directory +cd "$PWD" +mkdir -p .ionvcs + +# Check if a path is provided as an argument +if [ -z "$1" ]; then + echo "please provide a path to clone (like ~/Desktop/code_here)" + exit 1 +fi + +# Set the destination folder +if [ -n "$2" ]; then + DEST_FOLDER="$PWD/$2" +else + DEST_FOLDER="$PWD" +fi + +# Create the destination folder if it doesn't exist +mkdir -p "$DEST_FOLDER" + +# Source the credentials file if it exists +if [ -f "$HOME/ionsrc/creds.txt" ]; then + source "$HOME/ionsrc/creds.txt" +else + echo "credentials file not found! (please use the login command)" + exit 1 +fi + +# Set the remote path for rsync +REMOTE_PATH="$username@$src:$1" +CONF_FILE="$PWD/.ionvcs/src.config" + +# Write configuration details to the .ionvcs/src.config file +echo "csrc=$REMOTE_PATH" > "$CONF_FILE" +echo "lastdate=$(date)" >> "$CONF_FILE" +echo "user=$username" >> "$CONF_FILE" + +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 "done!" \ No newline at end of file diff --git a/getuser.sh b/getuser.sh new file mode 100644 index 0000000..030cce4 --- /dev/null +++ b/getuser.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +if [ -f "$HOME/ionsrc/creds.txt" ]; then + source "$HOME/ionsrc/creds.txt" + echo "logged in as $username!" +else + echo "no user found!" +fi \ No newline at end of file diff --git a/help.sh b/help.sh new file mode 100644 index 0000000..c35a2ce --- /dev/null +++ b/help.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +echo "Usage: ionvcs [args]" +echo +printf "%-15s %-20s %-30s\n" "Command" "Args" "Description" +printf "%-15s %-20s %-30s\n" "-------" "-----" "-----------" +printf "%-15s %-20s %-30s\n" "clone" "" "Clone a repository." +printf "%-15s %-20s %-30s\n" "user" "" "Get user information." +printf "%-15s %-20s %-30s\n" "init" "N/A" "Initialize a repository." +printf "%-15s %-20s %-30s\n" "login" "N/A" "Login to the system." +printf "%-15s %-20s %-30s\n" "push" "[-f]" "Push changes to the repository." diff --git a/init.sh b/init.sh new file mode 100644 index 0000000..c8a5985 --- /dev/null +++ b/init.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# make sure the libraries are installed +sudo dnf -y install sshpass ssh pv || sudo apt-get -y install sshpass ssh pv + + +git clone https://github.com/ION606/VCS.git .ionvcs +sudo mv .ionvcs/ionsrc.desktop /usr/share/applications/ionsrc.desktop || echo "FAILED TO MAKE DESKTOP FOLDER" +mkdir -p ~/ionsrc +mv .ionvcs/* ~/ionsrc/ \ No newline at end of file diff --git a/ionsrc.desktop b/ionsrc.desktop new file mode 100644 index 0000000..036c0d0 --- /dev/null +++ b/ionsrc.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] +Version=1.0 +Name=ION VCS +Comment=A custom utility to fetch and send code to my server +Exec=~/ionsrc/run.sh +Icon=~/ionsrc/icon.png +Terminal=true +Type=Application +Categories=Utility; diff --git a/login.sh b/login.sh new file mode 100644 index 0000000..984b989 --- /dev/null +++ b/login.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +CREDSFILE="$HOME/ionsrc/creds.txt" + +read -p "Enter source IP/URL: " src; +read -p "Enter your username: " username; +read -sp "Enter your password: " password; + +echo ""; + +echo "src=$src" > "$CREDSFILE"; +echo "username=$username" >> "$CREDSFILE"; +echo "password=$password" >> "$CREDSFILE"; + +# Secure the file +chmod 600 "$CREDSFILE"; + +echo "Logged in!"; +exit; \ No newline at end of file diff --git a/push.sh b/push.sh new file mode 100644 index 0000000..9e018c2 --- /dev/null +++ b/push.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +# Navigate to the current working directory +cd "$PWD" + +if [ ! -f "$HOME/ionsrc/creds.txt" ]; then + echo "credentials file not found!" + exit 1 +elif [ ! -f "$PWD/.ionvcs/src.config"]; then + echo "config file not found!" + exit 1 +fi + +source "$HOME/ionsrc/creds.txt" +source "$PWD/.ionvcs/src.config" + +# Set the remote path for rsync +REMOTE_PATH="$csrc" + + +while getopts ":of" opt; do + case $opt in + f) + force_flag=true + ;; + esac +done + + +# 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") + +# Check if there are differences +if [ ! -z "$DIFF_OUTPUT" && ! $force_flag ]; then + echo "conflicts found between the local and remote directories (make sure they're correct and re-run using the -f flag):" + echo "$DIFF_OUTPUT" + exit 1; +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; } +echo "done!" \ No newline at end of file diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..131ac1e --- /dev/null +++ b/run.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +COMMAND="$1"; +shift; + +case $COMMAND in + "clone") + bash clone.sh "$@" + ;; + + "push") + bash push.sh "$@" + ;; + + "login") + bash login.sh "$@" + ;; + + "user") + bash getuser.sh + ;; + + "help") + bash help.sh + ;; + + *) + echo "UNKNOWN COMMAND \"$@\"" + ;; +esac \ No newline at end of file