diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..9d28e6f Binary files /dev/null and b/.DS_Store differ diff --git a/allBackups/.DS_Store b/allBackups/.DS_Store new file mode 100644 index 0000000..702ed41 Binary files /dev/null and b/allBackups/.DS_Store differ diff --git a/allBackups/backup_code.sh b/allBackups/backup_code.sh new file mode 100755 index 0000000..4f8116d --- /dev/null +++ b/allBackups/backup_code.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +source_folder="./" +backup_folder="./allBackups" + + +if [ -d "$source_folder" ]; then + mkdir -p "$backup_folder" + + rsync -av "$source_folder/" "$backup_folder/" + + if [ $? -eq 0 ]; then + echo "Backup completed successfully." + else + echo "Backup failed. Please check the source and destination paths." + fi +else + echo "Source folder not found: $source_folder" +fi diff --git a/allBackups/hello.txt b/allBackups/hello.txt new file mode 100644 index 0000000..e69de29 diff --git a/allBackups/mkc.sh b/allBackups/mkc.sh new file mode 100755 index 0000000..e54cd3c --- /dev/null +++ b/allBackups/mkc.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +init() { +echo "initialised" +} +add() { +echo "added" +} +cin(){ +echo "Checked in" +} +cout(){ +echo "Checked Out" +} +log(){ +echo "print log" +} + +if [[ $1 =~ ^[0-9]+$ ]]; then + echo "invalid argument" + exit 1 +elif [ $1 == "init" ]; then + init +elif [ $1 == "add" ]; then + add +elif [ $1 == "cin" ]; then + cin +elif [ $1 == "cout" ]; then + cout +elif [ $1 == "log" ]; then + log +fi diff --git a/allBackups/user/.DS_Store b/allBackups/user/.DS_Store new file mode 100644 index 0000000..fa132e2 Binary files /dev/null and b/allBackups/user/.DS_Store differ diff --git a/allBackups/user/hello.txt b/allBackups/user/hello.txt new file mode 100644 index 0000000..e69de29 diff --git a/allBackups/user/xyz.txt b/allBackups/user/xyz.txt new file mode 100644 index 0000000..e69de29 diff --git a/allBackups/versions.sh b/allBackups/versions.sh new file mode 100755 index 0000000..46d7f48 --- /dev/null +++ b/allBackups/versions.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +print_menu () { + folderPath=$1 + versionSelected=$2 + ogPath=$3 + echo "Select an operation:" + echo "[1] Read a Version" + echo "[2] Rollback a Version" + + read -p "Enter your choice: " choice + + if [ "$choice" == "1" ]; then + echo "You selected 'Read a Version'." + cat "${folderPath}/${versionSelected}" + print_menu folderPath versionSelected + elif [ "$choice" == "2" ]; then + echo "You selected 'Rollback a Version'." + else + echo "Invalid choice. Please enter 1 or 2." + fi +} + +root_function () { + fileName="$1" + folderName="$2" + versionsPath="./versions/${fileName}_versions" + file_path="$folderName$fileName" + + if [ -e "$file_path" ]; then + echo "File Found, Select an Operation:" + echo "Versions Available:" + ls "$versionsPath" + read -p "Enter complete name of the version", versionSelected + print_menu $versionsPath $versionSelected $file_path + else + echo "File does not exist" + fi +} +root_function + diff --git a/allBackups/versions/.DS_Store b/allBackups/versions/.DS_Store new file mode 100644 index 0000000..beca0b1 Binary files /dev/null and b/allBackups/versions/.DS_Store differ diff --git a/allBackups/versions/hello.txt_versions/.DS_Store b/allBackups/versions/hello.txt_versions/.DS_Store new file mode 100644 index 0000000..44986d4 Binary files /dev/null and b/allBackups/versions/hello.txt_versions/.DS_Store differ diff --git a/allBackups/versions/hello.txt_versions/hello_v1.txt b/allBackups/versions/hello.txt_versions/hello_v1.txt new file mode 100644 index 0000000..eba909f --- /dev/null +++ b/allBackups/versions/hello.txt_versions/hello_v1.txt @@ -0,0 +1,5 @@ +Testing content +Testing contentTesting content +Testing content +Testing content +Testing contentTesting content \ No newline at end of file diff --git a/allUsers.txt b/allUsers.txt deleted file mode 100644 index bd77449..0000000 --- a/allUsers.txt +++ /dev/null @@ -1 +0,0 @@ -Khushh;k@gmail.com;;1234 diff --git a/backup_code.sh b/backup_code.sh new file mode 100755 index 0000000..4f8116d --- /dev/null +++ b/backup_code.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +source_folder="./" +backup_folder="./allBackups" + + +if [ -d "$source_folder" ]; then + mkdir -p "$backup_folder" + + rsync -av "$source_folder/" "$backup_folder/" + + if [ $? -eq 0 ]; then + echo "Backup completed successfully." + else + echo "Backup failed. Please check the source and destination paths." + fi +else + echo "Source folder not found: $source_folder" +fi diff --git a/file.sh b/file.sh new file mode 100644 index 0000000..621dd59 --- /dev/null +++ b/file.sh @@ -0,0 +1,421 @@ +#!/bin/bash + +create-rep(){ + local repos="$1" + for name in $repo; do + if [ -z "$name" ]; then + echo "Error: Repository without name??" + return 1 + fi + + if [ -e "$name" ]; then + echo "Error: Repository '$name' already exists." + return 1 + fi + + if mkdir "$name"; then + echo "Repository '$name' created successfully." + echo "------------------------------------------" >> "$name/$name.log" + echo "Description: Created the repo $name" > "$name/$name.log" + echo "Author: $USER" >> "$name/$name.log" + echo "Date: $(date)" >> "$name/$name.log" + echo "------------------------------------------" >> "$name/$name.log" + else + echo "Error: Unable to create Repository '$name'." + return 1 + fi + done +} + +add(){ + local repository="$1" + local files="$2" + if [ -e "$repository" ]; then + for file in $files; do + if [ -z "$file" ]; then + echo "Error: File name cannot be empty." + return 1 + fi + + if [ -e "$repository/$file" ]; then + echo "Error: File '$file' already exists." + return 1 + fi + + if touch "$repository/$file"; then + chmod u-w "$repository/$file" + mkdir -p "./versions" + mkdir -p "./versions/${files}_version" + touch "./versions/${files}_version/v1_${files}" + touch "./versions/${files}_version/version_manager.txt" + echo "1" > "./versions/${files}_version/version_manager.txt" + echo "File '$file' created successfully in repository '$repository'." + echo "Description: Created file $file in $repository" >> "$repository/$repository.log" + echo "Author: $USER" >> "$repository/$repository.log" + echo "Date: $(date)" >> "$repository/$repository.log" + echo "------------------------------------------" >> "$repository/$repository.log" + else + echo "Error: Unable to create file '$file'." + return 1 + fi + done + else + echo "Repository not found" + return 1 + fi +} + +remove(){ + local Myrepository="$1" + local filename="$2" + for repository in $Myrepository; do + if [ -e "$repository" ];then + if ! [ -n "$filename" ];then + if [ -n "$(ls -A "$repository")" ]; then + read -p "The repository '$repository' is not empty. Are you sure you want to delete it? (y/n): " confirm + if [ "$confirm" == "y" ]; then + if rm -r "$repository"; then + echo "Repository '$repository' removed successfully." + else + echo "Error: Unable to remove Repository '$repository'." + return 1 + fi + else + echo "Operation canceled." + fi + else + # Repository is empty, proceed with removal + if rmdir "$repository"; then + echo "Repository '$repository' removed successfully." + else + echo "Error: Unable to remove Repository '$repository'." + return 1 + fi + fi + else + for file in $filename; do + if [ -e "$repository/$file" ]; then + if rm "$repository/$file" ; then + echo "File '$file' removed successfully." + else + echo "Error: Unable to remove file '$file'." + return 1 + fi + else + echo "Error: File '$file' not found." + return 1 + fi + done + fi + else + echo "Repository not found" + fi +done +} + +check-out(){ + local repository="$1" + local files="$2" + if [ -e "$repository" ]; then + for file in $files; do + if [ -z "$file" ]; then + echo "Error: File name cannot be empty." + return 1 + fi + + if [ -e "$repository/$file" ] && [ ! -w "$repository/$file" ] && [ ! -r "$repository/$file" ]; then + chmod u+rw "$repository/$file" + nano "$repository/$file" + echo "File '$file' in '$repository' has been checked out now." + echo "Description: Checked out file $file in $repository" >> "$repository/$repository.log" + echo "Author: $USER" >> "$repository/$repository.log" + echo "Date: $(date)" >> "$repository/$repository.log" + echo "------------------------------------------" >> "$repository/$repository.log" + else + echo "This file is currently being edited by $USER" + return 1 + fi + done + else + echo "Repository not found" + + return 1 + fi +} + +check-in(){ + local repository="$1" + local files="$2" + local message="$3" + if [ -e "$repository" ]; then + for file in $files; do + if [ -z "$file" ]; then + echo "Error: File name cannot be empty." + return 1 + fi + + if [ -w "$repository/$file" ] && [ -r "$repository/$file" ]; then + chmod u-rw "$repository/$file" + versionFilePath="./versions/${file}_version/version_manager.txt" + first_line=$(head -n 1 "$versionFilePath") + new_number=$((first_line + 1)) + echo "$new_number" > "${versionFilePath}" + touch "./versions/${file}_version/v${new_number}_file" + sudo cat "$repository/$file" > "./versions/${file}_version/v${new_number}_file" + echo "File '$file' in '$repository' has been checked in now." + echo "Description: Modified file $file in $repository" >> "$repository/$repository.log" + echo "Author: $USER" >> "$repository/$repository.log" + echo "Message : $message" >> "$repository/$repository.log" + echo "Date: $(date)" >> "$repository/$repository.log" + echo "------------------------------------------" >> "$repository/$repository.log" + else + echo "File already checked in" + fi + done + else + echo "Repository not found" + return 1 + fi +} + +log(){ + local repository="$1" + if [ -e "$repository" ]; then + if [ -e "$repository/$repository.log" ]; then + cat "$repository/$repository.log" + else + echo "No Log File Found" + return 1 + fi + else + echo "Repository not found" + return 1 + fi +} + + +backup() { +local source_folder="./" +local backup_folder="./allBackups" + + +if [ -d "$source_folder" ]; then + mkdir -p "$backup_folder" + + sudo rsync -av "$source_folder/" "$backup_folder/" + + if [ $? -eq 0 ]; then + rm -r "./allBackups/allBackups" + echo "Backup completed successfully." + else + echo "Backup failed. Please check the source and destination paths." + fi +else + echo "Source folder not found: $source_folder" +fi + +} + + +print_menu () { + folderPath=$1 + versionSelected=$2 + ogPath=$3 + echo "Select an operation:" + echo "[1] Read a Version" + echo "[2] Rollback a Version" + echo "[3] Exit" + + read -p "Enter your choice: " choice + + if [ "$choice" == "1" ]; then + echo "You selected 'Read a Version'." + sudo cat "$ogPath" + print_menu $folderPath $versionSelected $ogPath + elif [ "$choice" == "2" ]; then + chmod u+rw "${folderPath}/${versionSelected}" + chmod u+rw "$ogPath" + sudo cat "${folderPath}/${versionSelected}" > "$ogPath" + echo "Rollback was successful" + elif [ "$choice" == "3" ]; then + echo "Exiting" + exit 0 + else + echo "Invalid choice. Please enter 1 or 2." + print_menu folderPath versionSelected ogPath + fi +} + +rollback () { + local fileName="$1" + local folderName="$2" + echo "$fileName" + echo "$folderName" + versionsPath="./versions/$1_version" + file_path="./$folderName/$fileName" + echo "$file_path" + + if [ -e "$file_path" ]; then + echo "$file_path" + echo "File Found, Select an Operation:" + echo "Versions Available:" + echo "File Name : $fileName" + ls "$versionsPath" + read -p "Enter complete name of the version: " versionSelected + if [ -e "$versionsPath/${versionSelected}" ]; then + echo "Version Found" + print_menu $versionsPath $versionSelected $file_path + else + echo "Version does not exist" + rollback + fi + else + echo "File does not exist" + fi +} + + +help() { + echo "Usage: $0 -c [-r \" ...\"] [-f \" ...\"]" + echo + echo "Options:" + echo " -c Specify the command (create-rep, add, remove, check-out, check-in, log, help)" + echo " -r \" ...\" Specify the repository name(s)" + echo " -f \" ...\" Specify the file name(s) (required for add and check-out)" + echo + echo "Commands:" + echo " create-rep Create a new repository" + echo " Options:" + echo " ... Specify the repository name(s)" + echo " Example:" + echo " $0 -c create-rep -r MyProject" + echo " $0 -c create-rep -r \"MyProject1 MyProject2 Myproject3\"" + echo "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*" + echo + echo " add Add a file to the repository" + echo " Options:" + echo " Specify the repository name" + echo " ... Specify the filename(s) to add to the repository" + echo " Example:" + echo " $0 -c add -r MyProject -f text.txt" + echo " $0 -c add -r MyProject1 -f \"text1.txt text2.txt\"" + echo "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*" + echo + echo " remove Remove a file or the entire repository" + echo " Options:" + echo " ... Specify the repository name(s)" + echo " ... (Optional) Specify the filename(s) to remove from the repository" + echo " Example:" + echo " $0 -c remove -r MyProject" + echo " $0 -c remove -r \"MyProject1 MyProject2\"" + echo " $0 -c remove -r MyProject -f text.txt" + echo " $0 -c remove -r MyProject1 -f \"text1.txt text2.txt\"" + echo "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*" + echo + echo " check-out Check out a file for editing" + echo " Options:" + echo " Specify the repository name" + echo " Specify the filename to check out for editing" + echo " Example:" + echo " $0 -c check-out -r MyProject -f text.txt" + echo "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*" + echo + echo " check-in Check in a file after editing" + echo " Options:" + echo " Specify the repository name" + echo " Example:" + echo " $0 -c check-in -r MyProject" + echo "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*" + echo + echo " log Display the project log" + echo " Options:" + echo " Specify the repository name" + echo " Example:" + echo " $0 -c log -r MyProject" + echo "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*" + echo + echo " help Display this help information" + echo " Options:" + echo " None" + echo " Example:" + echo " $0 -c help" + echo "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*" +} + +while getopts ":c:r:f:m:" opt; do + case $opt in + c) + command="$OPTARG" + ;; + r) + repo="$OPTARG" + ;; + f) + file="$OPTARG" + ;; + m) + message="$OPTARG" + ;; + \?) + echo "Invalid option: -$OPTARG" + echo "Try: -c for command, -r for repository, -f for file(s)." + exit 1 + ;; + :) + echo "Option -$OPTARG requires an argument." + exit 1 + ;; + esac +done + +case "$command" in + "create-rep") + create-rep "$repo" + ;; + "add") + add "$repo" "$file" + ;; + "remove") + if [ -n "$file" ]; then + remove "$repo" "$file" + else + remove "$repo" + fi + ;; + "check-out") + if [ -n "$file" ]; then + check-out "$repo" "$file" + else + echo "File name is required for check-out." + exit 1 + fi + ;; + "check-in") + if [ -n "$file" ]; then + check-in "$repo" "$file" "$message" + else + echo "File name is required for check-in." + exit 1 + fi + ;; + "log") + if [ -n "$repo" ]; then + log "$repo" + else + echo "Repository name is required to print the log" + exit 1 + fi + ;; + "backup") + backup + ;; + "rollback") + rollback "$file" "$repo" + ;; + "help") + help + ;; + *) + echo "Oops! Invalid command. Try: -c for command, -r for repository, -f for file." + ;; +esac diff --git a/hello.txt b/hello.txt new file mode 100644 index 0000000..31e4492 --- /dev/null +++ b/hello.txt @@ -0,0 +1,3 @@ +Testing +Testing + diff --git a/user/.DS_Store b/user/.DS_Store new file mode 100644 index 0000000..fa132e2 Binary files /dev/null and b/user/.DS_Store differ diff --git a/user/hello.txt b/user/hello.txt new file mode 100644 index 0000000..e69de29 diff --git a/user/xyz.txt b/user/xyz.txt new file mode 100644 index 0000000..e69de29 diff --git a/user_code.sh b/user_code.sh deleted file mode 100755 index f4dae41..0000000 --- a/user_code.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env bash - -file="allUsers.txt" - -menu(){ -echo "[1] Sign In"; -echo "[2] Sign Up"; -read -p "Choose an option: " option; -if [ $option == 1 ]; then - sign_in -else - sign_up -fi - -} - -sign_in(){ -read -p "Enter User Name: " user_name; -read -s -p "Enter Password: " user_password; - -if grep -q "^$user_name;.*;$user_password$" "$file"; then - echo "$user_name you are signed in successfully"; -else - echo "Invalid Username or Password"; - -fi - -} - -sign_up(){ -echo "Enter below details to create a new account" -read -p "Enter a new User Name: " user_name; -read -p "Enter your email address: " user_email; -read -p "Enter your Student Identification Number: " user_studentID; -read -s -p "Create a new Password: " user_password; - -if grep -q "^$user_name;" "$file"; then - echo "User Already Exists" -else - echo "$user_name;$user_email;$user_studentID;$user_password" >> allUsers.txt - echo "User Created Successfully!" - -fi -} - -menu - - - diff --git a/versions.sh b/versions.sh new file mode 100755 index 0000000..4fe6dca --- /dev/null +++ b/versions.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +print_menu () { + folderPath=$1 + versionSelected=$2 + ogPath=$3 + echo "Select an operation:" + echo "[1] Read a Version" + echo "[2] Rollback a Version" + echo "[3] Exit" + + read -p "Enter your choice: " choice + + if [ "$choice" == "1" ]; then + echo "You selected 'Read a Version'." + cat "${folderPath}/${versionSelected}" + print_menu folderPath versionSelected + elif [ "$choice" == "2" ]; then + echo "$ogPath" + cat "${folderPath}/${versionSelected}" > "$ogPath" + echo "Rollback was succesfull" + elif [ "$choice" == "3" ]; then + echo "Exiting" + exit 0 + else + echo "Invalid choice. Please enter 1 or 2." + print_menu folderPath versionSelected ogPath + fi +} + +root_function () { + fileName="hello.txt" + folderName="./" + versionsPath="./versions/${fileName}_versions" + file_path="$folderName$fileName" + + if [ -e "$file_path" ]; then + echo "File Found, Select an Operation:" + echo "Versions Available:" + ls "$versionsPath" + read -p "Enter complete name of the version: " versionSelected + if [ -e "$versionsPath/${versionSelected}" ]; then + echo "Version Found" + print_menu $versionsPath $versionSelected $file_path + else + echo "Version does not exist" + root_function + fi + else + echo "File does not exist" + fi +} +root_function + diff --git a/versions/.DS_Store b/versions/.DS_Store new file mode 100644 index 0000000..beca0b1 Binary files /dev/null and b/versions/.DS_Store differ diff --git a/versions/hello.txt_versions/.DS_Store b/versions/hello.txt_versions/.DS_Store new file mode 100644 index 0000000..4331088 Binary files /dev/null and b/versions/hello.txt_versions/.DS_Store differ diff --git a/versions/hello.txt_versions/hello_v1.txt b/versions/hello.txt_versions/hello_v1.txt new file mode 100644 index 0000000..31e4492 --- /dev/null +++ b/versions/hello.txt_versions/hello_v1.txt @@ -0,0 +1,3 @@ +Testing +Testing +