From aa8b87de1ab567d24ef573ab6023bdcd4932e7fd Mon Sep 17 00:00:00 2001 From: Nic0Nic0Nii Date: Fri, 20 May 2022 18:02:57 +0000 Subject: [PATCH] Include SigScript build system Co-authored-by: sigonasr2 --- scripts/build.sh | 9 +++ scripts/clean.sh | 4 + scripts/commit.sh | 13 ++++ scripts/jar.sh | 16 ++++ scripts/lean.sh | 1 + scripts/md5 | 5 ++ sig | 8 ++ {sig => src/sig}/MultipartUtility.java | 0 {sig => src/sig}/client.java | 0 .../exceptions/FailedResponseException.java | 0 {sig => src/sig}/requests/GETRequest.java | 0 {sig => src/sig}/requests/POSTRequest.java | 0 utils/.coauthors | 1 + utils/.updateDirectories | 3 + utils/define.sh | 23 ++++++ utils/main.sh | 28 +++++++ utils/md5 | 5 ++ utils/search.sh | 77 +++++++++++++++++++ 18 files changed, 193 insertions(+) create mode 100755 scripts/build.sh create mode 100755 scripts/clean.sh create mode 100755 scripts/commit.sh create mode 100755 scripts/jar.sh create mode 100644 scripts/lean.sh create mode 100644 scripts/md5 create mode 100755 sig rename {sig => src/sig}/MultipartUtility.java (100%) rename {sig => src/sig}/client.java (100%) rename {sig => src/sig}/exceptions/FailedResponseException.java (100%) rename {sig => src/sig}/requests/GETRequest.java (100%) rename {sig => src/sig}/requests/POSTRequest.java (100%) create mode 100644 utils/.coauthors create mode 100644 utils/.updateDirectories create mode 100755 utils/define.sh create mode 100644 utils/main.sh create mode 100644 utils/md5 create mode 100644 utils/search.sh diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100755 index 0000000..bdcd96d --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,9 @@ +#Builds and runs the project. +#Java +rm -Rf out/* +javac -Xlint:unchecked -cp ${PROJECT_DIR}/.. -d ${OUT_DIR} ${PROJECT_DIR}/*.java +printf "\n\n\nRunning Program...\n\n" +ORIGINAL_LOC=$(pwd) +cd $OUT_DIR +java ${MAIN_CLASS} "$@" +${ORIGINAL_LOC}/scripts/clean.sh \ No newline at end of file diff --git a/scripts/clean.sh b/scripts/clean.sh new file mode 100755 index 0000000..55f2398 --- /dev/null +++ b/scripts/clean.sh @@ -0,0 +1,4 @@ +#Cleans up and removes unused files. +#Java +find . -type f -name *.class -delete +find . -type f -name manifest -delete \ No newline at end of file diff --git a/scripts/commit.sh b/scripts/commit.sh new file mode 100755 index 0000000..6c49768 --- /dev/null +++ b/scripts/commit.sh @@ -0,0 +1,13 @@ +#Adds a commit message and pushes project to github repository. +#Java +COMMIT_MESSAGE="$*" +while IFS= read -r line +do + COMMIT_MESSAGE+=" + +Co-authored-by: $line" +done < utils/.coauthors +git add -u +git add * +git commit -m "$COMMIT_MESSAGE" +git push \ No newline at end of file diff --git a/scripts/jar.sh b/scripts/jar.sh new file mode 100755 index 0000000..441b43b --- /dev/null +++ b/scripts/jar.sh @@ -0,0 +1,16 @@ +#Builds a runnable jar file using ${MAIN_CLASS} as an entry point and then runs the newly generated jar. +#Java +rm -Rf bin/* +javac -Xlint:unchecked -cp src -d bin ${PROJECT_DIR}/${PROJECT_NAME}.java +printf "\n\n\nGenerating Manifest...\n\n" +touch manifest +echo "Main-Class: ${MAIN_CLASS}" >> manifest +printf "\n\n\nCreating Jar...\n\n" +ORIGINAL_LOC=$(pwd) +cd ${OUT_DIR} +jar cfm ${PROJECT_NAME}.jar ${ORIGINAL_LOC}/manifest sig +printf "\n\n\nRunning Program...\n\n" +java -jar ${PROJECT_NAME}.jar +mv ${PROJECT_NAME}.jar ${ORIGINAL_LOC} +cd .. +./scripts/clean.sh \ No newline at end of file diff --git a/scripts/lean.sh b/scripts/lean.sh new file mode 100644 index 0000000..1becba2 --- /dev/null +++ b/scripts/lean.sh @@ -0,0 +1 @@ +404: Not Found \ No newline at end of file diff --git a/scripts/md5 b/scripts/md5 new file mode 100644 index 0000000..c4273a3 --- /dev/null +++ b/scripts/md5 @@ -0,0 +1,5 @@ +build.sh:a833e7598ad65672a9c01306d244b49f - +clean.sh:96ce35f2d2dcb555421e00a6afda23ca - +commit.sh:21af1fa6f09d01679c9e11408967264a - +jar.sh:2ac636f584c43a1124affb9ea6bdc7bf - +lean.sh:3be7b8b182ccd96e48989b4e57311193 - diff --git a/sig b/sig new file mode 100755 index 0000000..58966a5 --- /dev/null +++ b/sig @@ -0,0 +1,8 @@ +source utils/define.sh + +define PROJECT_NAME "HttpClient" +define PROJECT_DIR "src/sig" +define MAIN_CLASS "sig.client" +define OUT_DIR "bin" + +source utils/main.sh \ No newline at end of file diff --git a/sig/MultipartUtility.java b/src/sig/MultipartUtility.java similarity index 100% rename from sig/MultipartUtility.java rename to src/sig/MultipartUtility.java diff --git a/sig/client.java b/src/sig/client.java similarity index 100% rename from sig/client.java rename to src/sig/client.java diff --git a/sig/exceptions/FailedResponseException.java b/src/sig/exceptions/FailedResponseException.java similarity index 100% rename from sig/exceptions/FailedResponseException.java rename to src/sig/exceptions/FailedResponseException.java diff --git a/sig/requests/GETRequest.java b/src/sig/requests/GETRequest.java similarity index 100% rename from sig/requests/GETRequest.java rename to src/sig/requests/GETRequest.java diff --git a/sig/requests/POSTRequest.java b/src/sig/requests/POSTRequest.java similarity index 100% rename from sig/requests/POSTRequest.java rename to src/sig/requests/POSTRequest.java diff --git a/utils/.coauthors b/utils/.coauthors new file mode 100644 index 0000000..b904d0f --- /dev/null +++ b/utils/.coauthors @@ -0,0 +1 @@ +sigonasr2 diff --git a/utils/.updateDirectories b/utils/.updateDirectories new file mode 100644 index 0000000..e4dde11 --- /dev/null +++ b/utils/.updateDirectories @@ -0,0 +1,3 @@ +Java/ +scripts/ +utils/ \ No newline at end of file diff --git a/utils/define.sh b/utils/define.sh new file mode 100755 index 0000000..0926c6c --- /dev/null +++ b/utils/define.sh @@ -0,0 +1,23 @@ +export VARS=("") + +function define() { + VARS+=("$1") + value="${*:2}" + eval export "$1"='$value' +} + +if [[ $(pwd) != *"SigScript" ]]; then + source utils/search.sh + + find . -type f -name md5 -delete + + #Check for hashes + FILES=$(cat utils/.updateDirectories) + for f in $FILES + do + search $f + check $f + done +else + echo "Dev build, no checks required." +fi \ No newline at end of file diff --git a/utils/main.sh b/utils/main.sh new file mode 100644 index 0000000..645950d --- /dev/null +++ b/utils/main.sh @@ -0,0 +1,28 @@ +if [ -z "$1" ] + then + echo "" + echo " Usage: ./sig {args}" + echo "" + printf "====\tCurrent Configuration" + printf "\t=====================" + for t in ${VARS[@]} + do + printf "\n\t%-15s%20s" $t ${!t} + done + printf "\n=====================================================" + echo "" + echo "" + echo " Command List:" + FILES=$(ls -1A ./scripts | sed -e 's/\.sh$//' | sed -e 's/^/ /') + for f in $FILES + do + if [ $f != "md5" ]; then + DESC="$(head -n1 ./scripts/$f.sh)" + printf "\n\t%-15s%-65s" $f "${DESC:1}" + fi + done + echo "" + exit +fi + +./scripts/$1.sh "${*:2}" \ No newline at end of file diff --git a/utils/md5 b/utils/md5 new file mode 100644 index 0000000..715e752 --- /dev/null +++ b/utils/md5 @@ -0,0 +1,5 @@ +.coauthors:3785ad38663e5fc43e574914ad067294 - +define.sh:d6b20a25a04a60d94f466e48fa60ac69 - +main.sh:32a1f953ffca8584d1eb57c0ecd8a582 - +search.sh:28d0ede8345514d80cc68cc756870002 - +.updateDirectories:0ede00461e947494545e694040787b3f - diff --git a/utils/search.sh b/utils/search.sh new file mode 100644 index 0000000..5392df5 --- /dev/null +++ b/utils/search.sh @@ -0,0 +1,77 @@ +function search() { + FILES2=$(ls -A $1) + for g in $FILES2 + do + if [ -d $1$g ]; + then + echo "$1$g is a directory" + search $1$g/ + else + echo "$1$g is a file" + if [ $g != "md5" ]; then + SUM=$(md5sum < $1$g) + echo "$g:$SUM" >> $1md5 + else + echo " md5 file, ignoring..." + fi + fi + done +} + +function check() { + echo "Check $1" + FILES2=$(ls -A $1) + if [ -f "$1/md5" ]; + then + echo " md5: https://raw.githubusercontent.com/sigonasr2/SigScript/main/$1md5" + curl -H 'Cache-Control: no-cache, no-store' -s https://raw.githubusercontent.com/sigonasr2/SigScript/main/$1md5 --output /tmp/out + cmp -s $1/md5 /tmp/out + if [ "$?" -ne 0 ] + then + echo " Differences detected!" + cat /tmp/out + while IFS= read -r line + do + IFS=':' read -ra split <<< $line + g="${split[0]}" + if [ "$g" != "md5" ]; then + if [ -f $1$g ]; + then + echo "++Redownload $1$g..." + if [ -f "$1$g" ]; then + #Read the 2nd line and see if it has a special directory. + CHECKLINE=$(sed -n '2{p;q;}' $1$g) + if [ "${CHECKLINE:0:1}" = "#" ]; then + #This could be a different diff, try that one. + echo " md5: https://raw.githubusercontent.com/sigonasr2/SigScript/main/${CHECKLINE:1}/$1md5" + curl -H 'Cache-Control: no-cache, no-store' -s https://raw.githubusercontent.com/sigonasr2/SigScript/main/${CHECKLINE:1}/$1md5 --output /tmp/out + cmp -s $1/md5 /tmp/out + if [ "$?" -ne 0 ] + then + echo " Differences detected here too." + curl -H 'Cache-Control: no-cache, no-store' https://raw.githubusercontent.com/sigonasr2/SigScript/main/${CHECKLINE:1}/$1$g --output $1$g + fi + else + curl -H 'Cache-Control: no-cache, no-store' https://raw.githubusercontent.com/sigonasr2/SigScript/main/$1$g --output $1$g + fi + else + echo "===Could not find directory, assuming regular scripts directory exists." + curl -H 'Cache-Control: no-cache, no-store' https://raw.githubusercontent.com/sigonasr2/SigScript/main/$1$g --output scripts/$g + fi + else + echo "++==Downloading $1$g..." + curl -H 'Cache-Control: no-cache, no-store' https://raw.githubusercontent.com/sigonasr2/SigScript/main/$1$g --output $1$g + fi + fi + done < /tmp/out + fi + fi + for g in $FILES2 + do + if [ -d $1$g ]; + then + echo "$1$g is a directory" + check $1$g/ + fi + done +} \ No newline at end of file