commit b9135dc0aa1791a6b3496081d05179c5562a222b Author: sigonasr2, Sig, Sigo Date: Wed Jun 29 12:40:46 2022 -0500 Initial commit diff --git a/C/scripts/build.sh b/C/scripts/build.sh new file mode 100644 index 0000000..d3b2ff9 --- /dev/null +++ b/C/scripts/build.sh @@ -0,0 +1,5 @@ +#Compiles the entire program then runs it, producing an executable. +#C +if gcc $(find . -type f -name "*.c") -lncurses -o ${PROJECT_NAME}; then + ./${PROJECT_NAME} +fi \ No newline at end of file diff --git a/C/scripts/commit.sh b/C/scripts/commit.sh new file mode 100755 index 0000000..0f56a8f --- /dev/null +++ b/C/scripts/commit.sh @@ -0,0 +1,20 @@ +#Adds a commit message and pushes project to github repository. +#C +COMMIT_MESSAGE="$*" +FIRST_LINE=true +while IFS= read -r line +do +if [ "$FIRST_LINE" = true ]; then + COMMIT_MESSAGE+=" + +Co-authored-by: $line" +FIRST_LINE=false +else + COMMIT_MESSAGE+=" +Co-authored-by: $line" +fi +done < utils/.coauthors +git add -u +git add * +git commit -m "$COMMIT_MESSAGE" +git push \ No newline at end of file diff --git a/Java/scripts/build.sh b/Java/scripts/build.sh new file mode 100755 index 0000000..c5b6b67 --- /dev/null +++ b/Java/scripts/build.sh @@ -0,0 +1,17 @@ +#Builds and runs the project. +#Java +source ${LANGUAGE}/scripts/version_info +javac -source ${SOURCE_VERSION} -target ${TARGET_VERSION} -Xlint:unchecked -cp ${CLASS_PATH} -d ${OUT_DIR} ${PROJECT_DIR}/*.java +printf "\n\n\nRunning Program...\n\n" +ORIGINAL_LOC=$(pwd) +cd $OUT_DIR +if java ${CUSTOM_PARAMS} -cp .:../lib/bin/ -XX:+UseZGC -Djava.library.path="${LIBRARY_PATH}" ${MAIN_CLASS} "$@"; then + ${ORIGINAL_LOC}/${LANGUAGE}/scripts/clean.sh + exit +fi +if java ${CUSTOM_PARAMS} -cp .:../lib/bin/ -XX:+UnlockExperimentalVMOptions -XX:+UseZGC -Djava.library.path="${LIBRARY_PATH}" ${MAIN_CLASS} "$@"; then + ${ORIGINAL_LOC}/${LANGUAGE}/scripts/clean.sh + exit +fi +java ${CUSTOM_PARAMS} -cp .:../lib/bin/ -XX:+PrintCommandLineFlags -Djava.library.path="${LIBRARY_PATH}" ${MAIN_CLASS} "$@" +${ORIGINAL_LOC}/${LANGUAGE}/scripts/clean.sh \ No newline at end of file diff --git a/Java/scripts/build2.sh b/Java/scripts/build2.sh new file mode 100644 index 0000000..53fe062 --- /dev/null +++ b/Java/scripts/build2.sh @@ -0,0 +1,17 @@ +#Builds and runs the project for Windows. +#Java +source ${LANGUAGE}/scripts/version_info +javac -source ${SOURCE_VERSION} -target ${TARGET_VERSION} -Xlint:unchecked -cp ${CLASS_PATH_WINDOWS} -d ${OUT_DIR} ${PROJECT_DIR}/*.java +printf "\n\n\nRunning Program...\n\n" +ORIGINAL_LOC=$(pwd) +cd $OUT_DIR +if java ${CUSTOM_PARAMS} -cp ".;../lib/bin/" -XX:+UseZGC "-Djava.library.path=${LIBRARY_PATH}" ${MAIN_CLASS} "$@"; then + ${ORIGINAL_LOC}/${LANGUAGE}/scripts/clean.sh + exit +fi +if java ${CUSTOM_PARAMS} -cp ".;../lib/bin/" -XX:+UnlockExperimentalVMOptions -XX:+UseZGC "-Djava.library.path=${LIBRARY_PATH}" ${MAIN_CLASS} "$@"; then + ${ORIGINAL_LOC}/${LANGUAGE}/scripts/clean.sh + exit +fi +java ${CUSTOM_PARAMS} -cp ".;../lib/bin/" -XX:+PrintCommandLineFlags "-Djava.library.path=${LIBRARY_PATH}" ${MAIN_CLASS} "$@" +${ORIGINAL_LOC}/${LANGUAGE}/scripts/clean.sh \ No newline at end of file diff --git a/Java/scripts/clean.sh b/Java/scripts/clean.sh new file mode 100755 index 0000000..0963522 --- /dev/null +++ b/Java/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/Java/scripts/commit.sh b/Java/scripts/commit.sh new file mode 100755 index 0000000..36b45b5 --- /dev/null +++ b/Java/scripts/commit.sh @@ -0,0 +1,20 @@ +#Adds a commit message and pushes project to github repository. +#Java +COMMIT_MESSAGE="$*" +FIRST_LINE=true +while IFS= read -r line +do +if [ "$FIRST_LINE" = true ]; then + COMMIT_MESSAGE+=" + +Co-authored-by: $line" +FIRST_LINE=false +else + COMMIT_MESSAGE+=" +Co-authored-by: $line" +fi +done < utils/.coauthors +git add -u +git add * +git commit -m "$COMMIT_MESSAGE" +git push \ No newline at end of file diff --git a/Java/scripts/filelist b/Java/scripts/filelist new file mode 100644 index 0000000..9e5004d --- /dev/null +++ b/Java/scripts/filelist @@ -0,0 +1,10 @@ +build2.sh +build.sh +clean.sh +commit.sh +jar2.sh +jar.sh +release.sh +update.sh +version_info +zip.sh diff --git a/Java/scripts/jar.sh b/Java/scripts/jar.sh new file mode 100755 index 0000000..61d1759 --- /dev/null +++ b/Java/scripts/jar.sh @@ -0,0 +1,17 @@ +#Builds a runnable jar file using ${MAIN_CLASS} as an entry point and then runs the newly generated jar. +#Java +source ${LANGUAGE}/scripts/version_info +rm -Rf bin/* +javac -source ${SOURCE_VERSION} -target ${TARGET_VERSION} -Xlint:unchecked -cp ${CLASS_PATH} -d ${OUT_DIR} ${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 +jar uf ${PROJECT_NAME}.jar -C ../lib/bin/ . +printf "\n\n\nRunning Program...\n\n" +java ${CUSTOM_PARAMS} -cp .:../lib/bin -Djava.library.path="${LIBRARY_PATH}" -jar ${PROJECT_NAME}.jar "$@" +${ORIGINAL_LOC}/${LANGUAGE}/scripts/clean.sh +cd .. diff --git a/Java/scripts/jar2.sh b/Java/scripts/jar2.sh new file mode 100755 index 0000000..9167bb8 --- /dev/null +++ b/Java/scripts/jar2.sh @@ -0,0 +1,17 @@ +#Builds a runnable jar file using ${MAIN_CLASS} as an entry point and then runs the newly generated jar for Windows. +#Java +source ${LANGUAGE}/scripts/version_info +rm -Rf bin/* +javac -source ${SOURCE_VERSION} -target ${TARGET_VERSION} -Xlint:unchecked -cp ${CLASS_PATH_WINDOWS} -d ${OUT_DIR} ${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 +jar uf ${PROJECT_NAME}.jar -C ../lib/bin/ . +printf "\n\n\nRunning Program...\n\n" +java ${CUSTOM_PARAMS} -cp .;../lib/bin "-Djava.library.path=${LIBRARY_PATH}" -jar ${PROJECT_NAME}.jar "$@" +${ORIGINAL_LOC}/${LANGUAGE}/scripts/clean.sh +cd .. diff --git a/Java/scripts/md5 b/Java/scripts/md5 new file mode 100644 index 0000000..b2c3eed --- /dev/null +++ b/Java/scripts/md5 @@ -0,0 +1,9 @@ +build2.sh:b1c6b7c6b2eb19ba54be6824bda8805b - +build.sh:5df470d49036bf7565493739aeebeaa8 - +clean.sh:668a2f9b568c55f6a044a509315032f6 - +commit.sh:5e4448db9ad48e72ec3a1ff4f5763b41 - +jar2.sh:7977fc138ee5db798d08c34734f0be93 - +jar.sh:821d5a109324d405f05c35c4bb129375 - +release.sh:027178aa6da76180401a188d8f03af64 - +update.sh:3be721658983183efa395984acd96b03 - +zip.sh:273f5a83b80a8e54022d60514dfeec0a - diff --git a/Java/scripts/release.sh b/Java/scripts/release.sh new file mode 100644 index 0000000..fca8c4b --- /dev/null +++ b/Java/scripts/release.sh @@ -0,0 +1,28 @@ +#Use ./sig release to create a custom installer based on OS. +#Java +source ${LANGUAGE}/scripts/version_info +FILES=$(cat ${LANGUAGE}/scripts/.package.files) +if [ "$1" = "windows" ];then + echo "Creating a package for Windows..." + echo "Not implemented yet." +elif [ "$1" = "mac" ];then + echo "Creating a package for Mac..." + echo "Not implemented yet." +elif [ "$1" = "linux" ];then + echo "Creating a package for Linux..." + cd .. + mkdir -vp RabiCloneOut/in + for f in $FILES + do + cp -Rv --parents $PROJECT_NAME/$f RabiCloneOut/in + done + jpackage --verbose --input RabiCloneOut/in/RabiClone --main-jar bin/RabiClone.jar --main-class sig.RabiClone --type app-image --dest RabiCloneOut + cp -Rv RabiCloneOut/RabiClone/lib/app/* RabiCloneOut/RabiClone + jpackage --verbose --app-image RabiCloneOut/RabiClone --name RabiClone + rm -Rfv RabiCloneOut + cd RabiClone + echo "Done!" +else + echo "Usage: " + echo " ./sig release " +fi \ No newline at end of file diff --git a/Java/scripts/update.sh b/Java/scripts/update.sh new file mode 100755 index 0000000..517be05 --- /dev/null +++ b/Java/scripts/update.sh @@ -0,0 +1,3 @@ +#Pulls the latest version of the repository. +#Java +git pull \ No newline at end of file diff --git a/Java/scripts/version_info b/Java/scripts/version_info new file mode 100644 index 0000000..719f74f --- /dev/null +++ b/Java/scripts/version_info @@ -0,0 +1,3 @@ +export SOURCE_VERSION="8" +export TARGET_VERSION="8" +export RELEASE_VERSION="0.0a" \ No newline at end of file diff --git a/Java/scripts/zip.sh b/Java/scripts/zip.sh new file mode 100644 index 0000000..4de5b1a --- /dev/null +++ b/Java/scripts/zip.sh @@ -0,0 +1,14 @@ +#Create a zip folder containing all dependencies. For quick release. +#Java +source ${LANGUAGE}/scripts/version_info +TARGET_FILE="${PROJECT_NAME}_${RELEASE_VERSION}.zip" +FILES=$(cat ${LANGUAGE}/scripts/.package.files) +echo "Creating Package $TARGET_FILE..." +for f in $FILES +do + zip -ur $TARGET_FILE $f +done +echo "Complete!" +echo "" +echo "" +echo "" \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..0a3a1b9 --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +This repository contains general build scripts and pipelines for all languages that I incorporate in my projects. The goal is to provide an easy retrieval and update system for the project. Each script will be a shell script containing the following template: +```bash + #Short description about what I do + #Language[Folder] + # #The script's code goes in here. + # rm -Rf out/* + # javac -Xlint:unchecked -cp ${PROJECT_DIR}/.. -d ${OUT_DIR} ${PROJECT_DIR}/*.java + # printf "\n\n\nRunning Program...\n\n" + # cd $OUT_DIR + # java ${MAIN_CLASS} "$@" + # ../scripts/clean.sh + +``` +Each language will be in the following structure: +``` + - + -- + ---[script files.sh] +``` + +The `sig` script will display by default any scripts in the `scripts` folder, therefore when creating a project, copy over the scripts folder of the desired language into your project then the `sig` script handles the rest appropriately. If your project requires multiple languages and build setups, then you can use the `sig2` command, which has an additional parameter to specify the language when running it. When setting up a multi-language setup, you'll just copy the entire folder to include the programming language itself. So a multi-language project structure may look something like this: +``` + -C + --scripts + ---build.sh + ---clean.sh + ---make.sh + -Java + --scripts + ---build.sh + ---clean.sh + ---jar.sh +``` diff --git a/install b/install new file mode 100755 index 0000000..cf8dc5d --- /dev/null +++ b/install @@ -0,0 +1,15 @@ +echo "Initializing..." +FILES=$(ls -dA */) +LANGUAGES=() +for f in $FILES +do + if [ "$f" != "scripts/" ] && [ "$f" != "utils/" ]; + then + LANGUAGES+=(""${f::-1}"") + fi +done +echo "Languages Detected:" +for f in "${LANGUAGES[@]}" +do + printf "\t%-15s\n" $f +done \ No newline at end of file diff --git a/scripts/commit.sh b/scripts/commit.sh new file mode 100755 index 0000000..2040dfd --- /dev/null +++ b/scripts/commit.sh @@ -0,0 +1,32 @@ +#Adds a commit message and pushes project to github repository. +# + +source utils/search.sh + +find . -type f -name md5 -delete +find . -type f -name filelist -delete + +#Generate a new hash for every sub-directory, which may require an update. +FILES=$(cat utils/.updateDirectories) +COMMIT_MESSAGE="$*" +FIRST_LINE=true +while IFS= read -r line +do +if [ "$FIRST_LINE" = true ]; then + COMMIT_MESSAGE+=" + +Co-authored-by: $line" +FIRST_LINE=false +else + COMMIT_MESSAGE+=" +Co-authored-by: $line" +fi +done < utils/.coauthors +for f in $FILES +do + search $f +done +git add -u +git add * +git commit -m "$COMMIT_MESSAGE" +git push \ No newline at end of file diff --git a/scripts/filelist b/scripts/filelist new file mode 100644 index 0000000..d3dfe86 --- /dev/null +++ b/scripts/filelist @@ -0,0 +1,2 @@ +commit.sh +update.sh diff --git a/scripts/md5 b/scripts/md5 new file mode 100644 index 0000000..d2a5b9b --- /dev/null +++ b/scripts/md5 @@ -0,0 +1,2 @@ +commit.sh:ea122668a72b4445c10b6e9070f7bbd8 - +update.sh:7fda194f24fbd8779221066cbbc04b3f - diff --git a/scripts/update.sh b/scripts/update.sh new file mode 100755 index 0000000..26af9ea --- /dev/null +++ b/scripts/update.sh @@ -0,0 +1,3 @@ +#Pulls the latest version of the repository. +# +git pull \ No newline at end of file diff --git a/sig b/sig new file mode 100755 index 0000000..5e2514a --- /dev/null +++ b/sig @@ -0,0 +1,15 @@ +export AUTO_UPDATE=true + +source utils/define.sh + +define PROJECT_NAME "JavaProjectTemplate" +define PROJECT_DIR "src/sig" +define MAIN_CLASS "sig.${PROJECT_NAME}" +define OUT_DIR "bin" +define LIBRARY_PATH "../lib" +define CLASS_PATH "${PROJECT_DIR}/..:lib/bin" +define CLASS_PATH_WINDOWS "${PROJECT_DIR}/..;lib/bin" +define CUSTOM_PARAMS "" +define LANGUAGE "" + +source utils/main.sh \ No newline at end of file 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..214fc50 --- /dev/null +++ b/utils/define.sh @@ -0,0 +1,26 @@ +export VARS=("") + +export LANGUAGE="" + +function define() { + VARS+=("$1") + value="${*:2}" + eval export "$1"='$value' +} + +if [[ $(pwd) != *"SigScript" && $AUTO_UPDATE = "true" && $1 != "update" ]]; then + source utils/search.sh + + find . -type f -name md5 -delete + find . -type f -name filelist -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/filelist b/utils/filelist new file mode 100644 index 0000000..95ad5ff --- /dev/null +++ b/utils/filelist @@ -0,0 +1,5 @@ +.coauthors +define.sh +main.sh +search.sh +.updateDirectories diff --git a/utils/main.sh b/utils/main.sh new file mode 100644 index 0000000..d299d6b --- /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 ./$LANGUAGE/scripts 2>/dev/null | sed -e 's/\.sh$//' | sed -e 's/^/ /') + for f in $FILES + do + if [ -f "./$LANGUAGE/scripts/$f.sh" ]; then + DESC="$(head -n1 ./$LANGUAGE/scripts/$f.sh)" + printf "\n\t%-15s%-65s" $f "${DESC:1}" + fi + done + echo "" + exit +fi + +./$LANGUAGE/scripts/$1.sh "${*:2}" \ No newline at end of file diff --git a/utils/md5 b/utils/md5 new file mode 100644 index 0000000..baa339d --- /dev/null +++ b/utils/md5 @@ -0,0 +1,4 @@ +define.sh:3ecab0dffe2adfb950f3eb7c7061b750 - +main.sh:d3d1bd0b56d8114eb7479964227f8576 - +search.sh:81d08f5ff48e8a44b5f68387d426da05 - +.updateDirectories:0ede00461e947494545e694040787b3f - diff --git a/utils/search.sh b/utils/search.sh new file mode 100644 index 0000000..99a69b3 --- /dev/null +++ b/utils/search.sh @@ -0,0 +1,103 @@ +function search() { + FILES2=$(ls -A $1 2>/dev/null) + 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" ] && [ $g != "filelist" ] && [ $g != ".package.files" ]; then + if [ $g != ".coauthors" ] && [ $g != "version_info" ]; then + SUM=$(md5sum < $1$g) + echo "$g:$SUM" >> $1md5 + fi + echo "$g" >> $1filelist + else + echo " ignoring $g..." + fi + fi + done +} + +function check() { + echo "Check $1" + FILES2=$(ls -A $1 2>/dev/null) + 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]}" + echo "LINE -- $g" + if [ "$g" != "md5" ] && [ "$g" != "filelist" ] && [ "$g" != ".package.files" ]; then + if [ -f $1$g ]; + then + if [ "$g" != ".coauthors" ] && [ "$g" != "version_info" ]; then + echo "++Redownload $1$g..." + if [ -f "$1$g" ]; then + curl -H 'Cache-Control: no-cache, no-store' "https://raw.githubusercontent.com/sigonasr2/SigScript/main/$1$g" --output $1$g + 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 $LANGUAGE/scripts/$g + fi + 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 + if [ -f "$1/filelist" ]; + then + echo " filelist: https://raw.githubusercontent.com/sigonasr2/SigScript/main/$1filelist" + curl -H 'Cache-Control: no-cache, no-store' -s "https://raw.githubusercontent.com/sigonasr2/SigScript/main/$1filelist" --output /tmp/out + cmp -s $1/filelist /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]}" + echo "LINE -- $g" + if [ "$g" != "md5" ] && [ "$g" != "filelist" ] && [ "$g" != ".package.files" ]; then + if [ -f $1$g ]; + then + if [ "$g" != ".coauthors" ] && [ "$g" != "version_info" ]; then + echo "++Redownload $1$g..." + if [ -f "$1$g" ]; then + curl -H 'Cache-Control: no-cache, no-store' "https://raw.githubusercontent.com/sigonasr2/SigScript/main/$1$g" --output $1$g + 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 $LANGUAGE/scripts/$g + fi + 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 +}