From 776cc32b4450dfc026f7dd938a22ecbd64883594 Mon Sep 17 00:00:00 2001 From: Khushaal Choithramani Date: Thu, 19 Oct 2023 20:37:04 +0100 Subject: [PATCH 1/4] backup --- .DS_Store | Bin 0 -> 6148 bytes allBackups/.DS_Store | Bin 0 -> 6148 bytes allBackups/sample | 0 backup_code.sh | 19 +++++++++++++++++++ user/.DS_Store | Bin 0 -> 6148 bytes 5 files changed, 19 insertions(+) create mode 100644 .DS_Store create mode 100644 allBackups/.DS_Store create mode 100644 allBackups/sample create mode 100755 backup_code.sh create mode 100644 user/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..008b6bcab1150945ab772e8ac99a10f2c27f8273 GIT binary patch literal 6148 zcmeHK%Wl&^6ur}$)@h*%5=dQIf@KIvn^r~Lm=G3hF^@$-!H%QGs^f`br$LG$WnKOS zw)_CUz(25O!wSwk5;-L429=lQS~F)n_c7x$_8kuqvHBpa5*3NaMiFRjp;{tBFUo?f z>7E@RlQDd1(HRY>N9lsK=`ai!2L3h%#J9UeKE=4|z}ffvB<8Ik<^l8~IXpxuf0u&R z3ZGz@_O#E(pchAJR;heuYwOmvjZJ&g-nL(R9X|9jKO3ZVzked`o^c)r)3zVHh}y$u z@zx`rWPX&i`_dr_+c0_cGD<=|tn)zv)liIkWrIYget+O3wcN!7r}e?0MqTs@LM(9(b9`OxNX&hJH`&ukXLyJmH_j`<>H= zm+E_+)v*`e6TJ>}`C5O&`1$pl&iN`)e*^aRRSsfe8wLym|0Dwhu4+leset7zX|;2AI|G8g)F9-dh(QPVBV~${Q3R p!fv8ax}ehAv22K~co#(qbdG2MU5yik=z*9Y0ZD_Y3H;|M3s>%!6u)5^y0> zW?<$_CNsIoxgnDwBA%|R3DKB{Mo_`Q0n9fd=S4d*@W?)p^%^Ux>6R)=bl1s_z<*>w z_U?$*^h7IqgnsT{hF@VfpD*jYnAdrZOnFT%pfB$#@OrE3`^jvPo2BNO=~=JIW$EjU z-mXthuk!0z|2j>seo?i2=-l0x8x1!Y2nK?I9c2JLTV!--7&aIP27-YN1M+=HP{G2n zHPlZBjE(@nA;K!~>~zSIpWFl3dh#a%87mWU|*SiLSbDU z*H4;GTo{H827-ZY2KMZ5EdBrd=lOrTD2{@GU|^>h;9)r{r+6gqt(}LHUYnpdP!Y*% l4L2olv=t*)TJbSd1@R;fuyAY*5rM>yfYJ~q82D2LJ^)PzNB#f+ literal 0 HcmV?d00001 diff --git a/allBackups/sample b/allBackups/sample new file mode 100644 index 0000000..e69de29 diff --git a/backup_code.sh b/backup_code.sh new file mode 100755 index 0000000..5345618 --- /dev/null +++ b/backup_code.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +source_folder="./user" +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/user/.DS_Store b/user/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..1e08732522c6718712f1cecc3049ce9cd16bbc6a GIT binary patch literal 6148 zcmeHKyJ|u~5S@t<1RF~mVZT7|50;B5Qu_l@lkSQ_u)mex<)0;I9t8Aik-|pK!0g$b zowLiH;?5lr(dPKM5SfU`2yQ4R8~SGZ<~@7Khyvj_qm{4scE8=U`%N$VcEGr=@-1uG z$>EBR19gV|`H$P}0~nHjZDTu}ik@Kg%uaJgDGcv9BZ-s7y+7WfC;a?Wrw%$ Date: Thu, 19 Oct 2023 23:55:20 +0100 Subject: [PATCH 2/4] khushh changes --- .DS_Store | Bin 6148 -> 8196 bytes allBackups/.DS_Store | Bin 6148 -> 8196 bytes allBackups/backup_code.sh | 19 +++++++ allBackups/{sample => hello.txt} | 0 allBackups/mkc.sh | 32 ++++++++++++ allBackups/user/.DS_Store | Bin 0 -> 6148 bytes allBackups/user/hello.txt | 0 allBackups/user/xyz.txt | 0 allBackups/versions.sh | 41 +++++++++++++++ allBackups/versions/.DS_Store | Bin 0 -> 6148 bytes .../versions/hello.txt_versions/.DS_Store | Bin 0 -> 6148 bytes .../versions/hello.txt_versions/hello_v1.txt | 5 ++ allUsers.txt | 1 - backup_code.sh | 2 +- hello.txt | 2 + user/.DS_Store | Bin 6148 -> 6148 bytes user/hello.txt | 0 user/xyz.txt | 0 user_code.sh | 49 ------------------ versions.sh | 43 +++++++++++++++ versions/.DS_Store | Bin 0 -> 6148 bytes versions/hello.txt_versions/.DS_Store | Bin 0 -> 6148 bytes 22 files changed, 143 insertions(+), 51 deletions(-) create mode 100755 allBackups/backup_code.sh rename allBackups/{sample => hello.txt} (100%) create mode 100755 allBackups/mkc.sh create mode 100644 allBackups/user/.DS_Store create mode 100644 allBackups/user/hello.txt create mode 100644 allBackups/user/xyz.txt create mode 100755 allBackups/versions.sh create mode 100644 allBackups/versions/.DS_Store create mode 100644 allBackups/versions/hello.txt_versions/.DS_Store create mode 100644 allBackups/versions/hello.txt_versions/hello_v1.txt delete mode 100644 allUsers.txt create mode 100644 hello.txt create mode 100644 user/hello.txt create mode 100644 user/xyz.txt delete mode 100755 user_code.sh create mode 100755 versions.sh create mode 100644 versions/.DS_Store create mode 100644 versions/hello.txt_versions/.DS_Store diff --git a/.DS_Store b/.DS_Store index 008b6bcab1150945ab772e8ac99a10f2c27f8273..5b4b87b5daacea2f5a6e4bf7665a6b4c5e294799 100644 GIT binary patch delta 674 zcmZoMXmOBWU|?W$DortDU;r^WfEYvza8E20o2aMAD7rCVH}hr%jz7$c**Q2SHn1>? zPIh3C5b(^&Pfp6oPXeh0ns9Nl3Cj`@BXd(71!HrIS{;RIOCtjv1ruYl$!}P~Cs(s- zTQIx>s@44u20#`A11CcULn=cK5au)JF_bV=FqEK~ngUccVe%SQbyim(OK%dJ$mBPy zD{xt3Joz@;1bYsKGN7qN48;tYKy&jLic!sESOhew3&|B|>L-V>G~u+M9!)VraZb8n zaB_Zb0nktwz)+K$@8SXtDh~cF)tBxS9CZXL#-c8TfVwP*j|wsfTUr)el$VpAmkzXu z5s10bLj@S(#S9r}VFU7p8YFBs7H(t`WCrqqK!O`c0AoOad$S9 zP{L5bP=aR6dZ2N7|G|KPVX}ju9vhN6AKfZ_mSYlZWjik_Pyx6Q;yMKAF9sLqFh7fG(83|7G^G)v|2cxUfU#opb! zH>ud;`#aT&eS7!rWKys;uitv`w0Y?F1AZ*eo|t}&&?WVKKEB0P=G=~)LE!V?0CvH> zOm0H0Ce}STdDNjTtbBAAwWA;KznRdkKwWqW#X0mWs8Mzv6QKvhF^tbQ0Z2+*PwH&Y)3X)fHG*Cs-EsKi(oIt^cq3G|c%K z1&jj!pa9D?oJJi1WH;|M3s>%!6u)5^y0> zW?<$_CNsIoxgnDwBA%|R3DKB{Mo_`Q0n9fd=S4d*@W?)p^%^Ux>6R)=bl1s_z<*>w z_U?$*^h7IqgnsT{hF@VfpD*jYnAdrZOnFT%pfB$#@OrE3`^jvPo2BNO=~=JIW$EjU z-mXthuk!0z|2j>seo?i2=-l0x8x1!Y2nK?I9c2JLTV!--7&aIP27-YN1M+=HP{G2n zHPlZBjE(@nA;K!~>~zSIpWFl3dh#a%87mWU|*SiLSbDU z*H4;GTo{H827-ZY2KMZ5EdBrd=lOrTD2{@GU|^>h;9)r{r+6gqt(}LHUYnpdP!Y*% l4L2olv=t*)TJbSd1@R;fuyAY*5rM>yfYJ~q82D2LJ^)PzNB#f+ 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/sample b/allBackups/hello.txt similarity index 100% rename from allBackups/sample rename to allBackups/hello.txt 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 0000000000000000000000000000000000000000..fa132e20630a5fac65e53b47be2ed251c9d0917e GIT binary patch literal 6148 zcmeHKyH3O~5FEov9HP0B(qDi?4TU)!1vNi_4v;7!r8y*^O2_Z;hcNp95(QccG<(_| zdp(=IOcC1v%KGu{6j%XR(hc!yVQ#i=KC`{d7#4pOf(~(DZ;xI*0d`di#V|z$>tB3Yd5I4h?BQDSnsV-!tUKR8WF!M#XWePoh*u=x;WQ zWBC40Ylv1HBbpXDkMT9i)1)Zd?F+H7S-WwwF6(kjz7L0b8kYTXQgr&`x2E<=>oi)# z{pfWvnD&}?pXsdZC)r?Z2}wLamv?WHEY{PGo@8-hxuI*24cX{5w`a56gGVj3cW^jw zso9g=c1!K=J)X}S^4|T2Pha*vrlU-MwyPn5{mj~J#sz#qu##Ts=}vf}NBM%dDsQB_ zUDil`fAQ(!NB-?-b#8oZZa%!;e9yvhmg?*jb6jY4X~{lZV+HvCl3Qy$M?W>MfLGw( zC}8#n1veNlRu1jffx=z^fHkD8AvT`}hNBn*#>ydDV8T&>jw<+yAsiif#r*=t%Auo^ z;LC^LCkwuz2>W!5uWWY`fkR(<1-t@R71(suraAwg|M~uZmE>z)0k6P+rGTh)!)^yl z;EzP-=ZAWB`Qh*DR8X7X>J$Z|8M9&%>TzE?WBMd_*V+pY<;(0@sX;xP9DyCZKFTX uy=G5$<2on|(T<7Hj=Ax6d=W)i*L=J2~@)*Ck{vu|eS5a3{J Y-+1sl^JIPzT}Fn@jv|MdCpNGE0KkhUtN;K2 delta 116 zcmZoMXfc=|&e%4wP;8=}q9`K+0|O8XFfimWq&@&O0vwEO8$W($p3E> allUsers.txt - echo "User Created Successfully!" - -fi -} - -menu - - - diff --git a/versions.sh b/versions.sh new file mode 100755 index 0000000..92d7879 --- /dev/null +++ b/versions.sh @@ -0,0 +1,43 @@ +#!/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 "$ogPath" + cat "${folderPath}/${versionSelected}" > "$ogPath" + echo "Rollback was succesfull" + else + echo "Invalid choice. Please enter 1 or 2." + 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 + print_menu $versionsPath $versionSelected $file_path + else + echo "File does not exist" + fi +} +root_function + diff --git a/versions/.DS_Store b/versions/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..beca0b155538ae209d55c19041f3b0befdde5c17 GIT binary patch literal 6148 zcmeHKU5gVj6usH4Hgyq-DC}dv*P`7I-4$PEYZdm@5q(gpot?5BoKA+$bh}UrOf(~(DZ;xI*0d`di#V|z$>tB3Yd5I4h?BQDSnsV-!tUKR8WF!M#XWePoh*u=x;WQ zWBC40Ylv1HBbpXDkMT9i)1)Zd?F+H7S-WwwF6(kjz7L0b8kYTXQgr&`x2E<=>oi)# z{pfWvnD&}?pXsdZC)r?Z2}wLamv?WHEY{PGo@8-hxuI*24cX{5w`a56gGVj3cW^jw zso9g=c1!K=J)X}S^4|T2Pha*vrlU-MwyPn5{mj~J#sz#qu##Ts=}vf}NBM%dDsQB_ zUDil`fAQ(!NB-?-b#8oZZa%!;e9yvhmg?*jb6jY4X~{lZV+HvCl3Qy$M?W>MfLGw( zC}8#n1veNlRu1jffx=z^fHkD8AvT`}hNBn*#>ydDV8T&>jw<+yAsiif#r*=t%Auo^ z;LC^LCkwuz2>W!5uWWY`fkR(<1-t@R71(suraAwg|M~uZmE>z)0k6P+rGTh)!)^yl z;EzP-=ZAWB`Qh*DR8X7X>J$Z|8M9&%>TzE?WBMd_*V+pY<;(0@sX;xP9DyCZKFTX uy=G5$<2on|(T<7Hj=Ax6d=W)i*L= Date: Fri, 20 Oct 2023 00:40:58 +0100 Subject: [PATCH 3/4] changes --- .DS_Store | Bin 8196 -> 8196 bytes hello.txt | 1 + versions.sh | 17 ++++++++++++++--- versions/hello.txt_versions/.DS_Store | Bin 6148 -> 6148 bytes versions/hello.txt_versions/hello_v1.txt | 3 +++ 5 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 versions/hello.txt_versions/hello_v1.txt diff --git a/.DS_Store b/.DS_Store index 5b4b87b5daacea2f5a6e4bf7665a6b4c5e294799..9d28e6fe6d5d5a5b23030bc97e8bdd437914d208 100644 GIT binary patch delta 18 ZcmZp1XmQxEP>|J|fq`My=4FC$d;mJg1c delta 18 ZcmZp1XmQxEP>?l+fq`Md=4FC$d;mJe1-bwL diff --git a/hello.txt b/hello.txt index ba8cd98..31e4492 100644 --- a/hello.txt +++ b/hello.txt @@ -1,2 +1,3 @@ Testing Testing + diff --git a/versions.sh b/versions.sh index 92d7879..4fe6dca 100755 --- a/versions.sh +++ b/versions.sh @@ -7,6 +7,7 @@ print_menu () { echo "Select an operation:" echo "[1] Read a Version" echo "[2] Rollback a Version" + echo "[3] Exit" read -p "Enter your choice: " choice @@ -17,9 +18,13 @@ print_menu () { elif [ "$choice" == "2" ]; then echo "$ogPath" cat "${folderPath}/${versionSelected}" > "$ogPath" - echo "Rollback was succesfull" + 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 } @@ -33,8 +38,14 @@ root_function () { 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 + 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 diff --git a/versions/hello.txt_versions/.DS_Store b/versions/hello.txt_versions/.DS_Store index 44986d413f43663495e5ff5fe80f14ca03d58a04..4331088a569fd91e70d6ed9c17eda8b4a1fcb3f7 100644 GIT binary patch delta 16 XcmZoMXfc?uoz; Date: Fri, 20 Oct 2023 11:43:08 +0100 Subject: [PATCH 4/4] file.sh --- file.sh | 421 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 421 insertions(+) create mode 100644 file.sh 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