diff --git a/scripts/build.sh b/scripts/build.sh index fec7872..bdcd96d 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,7 +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} "$@" -../scripts/clean.sh \ No newline at end of file +${ORIGINAL_LOC}/scripts/clean.sh \ No newline at end of file diff --git a/scripts/clean.sh b/scripts/clean.sh index 1a1d44f..55f2398 100755 --- a/scripts/clean.sh +++ b/scripts/clean.sh @@ -1,3 +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 index b93040a..ac215af 100755 --- a/scripts/commit.sh +++ b/scripts/commit.sh @@ -1,4 +1,5 @@ #Adds a commit message and pushes project to github repository. +#Java git add -u git add * git commit -m "$*" diff --git a/scripts/jar.sh b/scripts/jar.sh index 7927af0..441b43b 100755 --- a/scripts/jar.sh +++ b/scripts/jar.sh @@ -1,14 +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 ../manifest sig +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 .. +mv ${PROJECT_NAME}.jar ${ORIGINAL_LOC} cd .. ./scripts/clean.sh \ No newline at end of file diff --git a/sig b/sig index 6f3e062..5f8d83f 100755 --- a/sig +++ b/sig @@ -1,32 +1,8 @@ -export PROJECT_NAME="JavaProjectTemplate" -export PROJECT_DIR="src/sig" -export MAIN_CLASS="sig.${PROJECT_NAME}" -export OUT_DIR="bin" +source utils/define.sh +define PROJECT_NAME "JavaProjectTemplate" +define PROJECT_DIR "src/sig" +define MAIN_CLASS "sig.${PROJECT_NAME}" +define OUT_DIR "bin" -if [ -z "$1" ] - then - echo "" - echo " Usage: ./sig {args}" - echo "" - printf "====\tCurrent Configuration" - printf "\t=====================" - printf "\n\t%-15s%20s" PROJECT_NAME ${PROJECT_NAME} - printf "\n\t%-15s%20s" PROJECT_DIR ${PROJECT_DIR} - printf "\n\t%-15s%20s" MAIN_CLASS ${MAIN_CLASS} - printf "\n\t%-15s%20s" OUT_DIR ${OUT_DIR} - printf "\n=====================================================" - echo "" - echo "" - echo " Command List:" - FILES=$(ls -1 ./scripts | sed -e 's/\.sh$//' | sed -e 's/^/ /') - for f in $FILES - do - DESC="$(head -n1 ./scripts/$f.sh)" - printf "\n\t%-15s%-65s" $f "${DESC:1}" - done - echo "" - exit -fi - -./scripts/$1.sh "${*:2}" \ No newline at end of file +source utils/main.sh \ No newline at end of file diff --git a/utils/define.sh b/utils/define.sh new file mode 100755 index 0000000..3b693db --- /dev/null +++ b/utils/define.sh @@ -0,0 +1,22 @@ +export VARS=("") + +function define() { + VARS+=("$1") + value="${*:2}" + eval "$1"='$value' +} + +if [[ $(pwd) != *"SigScript" ]]; then + source utils/search.sh + + find . -type f -name md5 -delete + + #Check for hashes + 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..fef0069 --- /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 -1 ./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/search.sh b/utils/search.sh new file mode 100644 index 0000000..a477997 --- /dev/null +++ b/utils/search.sh @@ -0,0 +1,53 @@ +function search() { + FILES2=$(ls $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 + md5sum < $1$g >> $1md5 + else + echo " md5 file, ignoring..." + fi + fi + done +} + +function check() { + echo "Check $1" + FILES2=$(ls $1) + REDOWNLOAD=false + if [ -f "$1/md5" ]; + then + echo " md5: https://raw.githubusercontent.com/sigonasr2/SigScript/main/$1md5" + curl -s https://raw.githubusercontent.com/sigonasr2/SigScript/main/$1md5 --output /tmp/out + DIFF=$(diff $1/md5 /tmp/out) + if [ "$DIFF" != "" ] + then + echo " Differences detected!" + REDOWNLOAD=true + fi + fi + for g in $FILES2 + do + if [ -d $1$g ]; + then + echo "$1$g is a directory" + check $1$g/ + else + if [ "$REDOWNLOAD" = "true" ]; then + echo "++Redownload $1$g..." + if [ -f "$1$g" ]; then + curl https://raw.githubusercontent.com/sigonasr2/SigScript/main/$1$g --output $1$g + else + echo "===Could not find directory, assuming regular scripts directory exists." + curl https://raw.githubusercontent.com/sigonasr2/SigScript/main/$1$g --output scripts/$g + fi + fi + fi + done +} \ No newline at end of file