From aa5980efd6b179bc67f838ab68cce82c66a06532 Mon Sep 17 00:00:00 2001 From: GenZmeY Date: Wed, 10 May 2023 06:12:32 +0300 Subject: [PATCH] add script update feature --- README.md | 8 +++++++- builder | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index be09c6e..0c2ad21 100644 --- a/README.md +++ b/README.md @@ -25,10 +25,16 @@ Make sure that the location of folders and files in your project as follows (Cor Open git-bash and go to your project: `cd ` Add submodule: `git submodule add https://github.com/GenZmeY/KF2-BuildTools tools` -**updating build tools:** +**updating build tools (manual)** Get updates: `pushd tools && git pull && popd` Commit the changes: `git add tools && git commit -m 'update tools'` +## Updating build tools +Since version 1.9.0 build script can update itself: +`./tools/builder --update` + +*if you have an older version you need to update once manually to start using this feature* + ### 2. As standalone script Just create a `tools` folder and put [builder](builder) there. Now you can use the script in the same way as in the first case, but you will have to update it yourself. diff --git a/builder b/builder index 6348fea..9a2e7b5 100644 --- a/builder +++ b/builder @@ -131,6 +131,7 @@ ArgQuiet="false" ArgHoldEditor="false" ArgNoColors="false" ArgForce="false" +ArgUpdate="false" # Colors RED='' @@ -241,6 +242,7 @@ ${BLD}Available options:${DEF} -he, --hold-editor do not close kf2editor automatically -nc, --no-colors do not use color output -d, --debug print every executed command (script debug) + --update update build tools -v, --version show version -h, --help show this help @@ -1021,6 +1023,53 @@ function run_test () CMD //C "$(cygpath -w "$KFGame")" "$Map?Difficulty=$Difficulty?GameLength=$GameLength?Game=$Game?Mutator=$Mutators?$Args" $UseUnpublished -log } +function update () +{ + pushd "$ScriptDir" &> /dev/null + if command -v git &> /dev/null && git rev-parse --git-dir &> /dev/null; then + update_by_git + elif command -v curl &> /dev/null; then + update_by_curl + else + err "Can't update: curl not found" + fi + popd &> /dev/null +} + +function update_by_git () +{ + if git pull origin master; then + pushd "$MutSource" &> /dev/null + git add "$ScriptDir" &> /dev/null + git commit -m "update build tools" + popd &> /dev/null + msg "Successfully updated" "${GRN}" + else + err "Error downloading update" + fi +} + +function update_by_curl () +{ + local Url='https://raw.githubusercontent.com/GenZmeY/KF2-BuildTools/master/builder' + local New + + New="$(mktemp.exe -u)" + + if curl -L "$Url" -o "$New"; then + if cmp -s "$ScriptFullname" "$New"; then + msg "Already the latest version" "${GRN}" + else + mv -f "$New" "$ScriptFullname" + msg "Successfully updated" "${GRN}" + fi + else + err "Error downloading update" + fi + + rm -f "$New" +} + function parse_combined_params () # $1: Combined short parameters { local Param="${1}" @@ -1069,6 +1118,7 @@ function parse_params () # $@: Args -he | --hold-editor ) ArgHoldEditor="true" ;; -nc | --no-color ) ArgNoColors="true" ;; -f | --force ) ArgForce="true" ;; + --update ) ArgUpdate="true" ;; --* ) die "Unknown option: ${1}" 1 ;; -* ) parse_combined_params "${1}" ;; * ) if [[ -n "${1-}" ]]; then die "Unknown option: ${1-}" 1; fi; break ;; @@ -1112,6 +1162,7 @@ function main () if is_true "$ArgCompile" || is_true "$ArgBrew"; then backup_kfeditorconf; fi # Actions + if is_true "$ArgUpdate"; then update; fi if is_true "$ArgInit"; then init; fi if is_true "$ArgCompile"; then compile; fi if is_true "$ArgBrew"; then brew; fi