From e860edd913fe3bcc351a87c239306b8d25e676ea Mon Sep 17 00:00:00 2001 From: Bohdan Marukhnenko Date: Sat, 18 Feb 2023 15:02:55 +0200 Subject: [PATCH] Fix broken linux scripts --- tools/install-cacher.sh | 5 +++-- tools/load-cache.sh | 47 ++++++++++++++++++----------------------- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/tools/install-cacher.sh b/tools/install-cacher.sh index c293a12..69bc2a2 100644 --- a/tools/install-cacher.sh +++ b/tools/install-cacher.sh @@ -19,6 +19,7 @@ if [ -z $root_dir ]; then root_dir=$DEF_ROOT_DIR fi +echo $root_dir if [ -f $root_dir/bin/$BIN_FILE ]; then echo Module already installed. Exiting exit @@ -35,8 +36,8 @@ cd $TEMP_DIR go build -o $BIN_FILE main.go mkdir -p $root_dir/bin -mv $BIN_FILE $ROOT_DIR/bin/ -cd $ROOT_DIR +mv $BIN_FILE $root_dir/bin/ +cd $root_dir rm -rf $TEMP_DIR echo Done diff --git a/tools/load-cache.sh b/tools/load-cache.sh index 9282409..605ed8f 100644 --- a/tools/load-cache.sh +++ b/tools/load-cache.sh @@ -5,9 +5,26 @@ API_URL=https://mia.mobil.knute.edu.ua SCRIPT_DIR=$(dirname $(realpath $0)) ROOT_DIR=$(dirname $SCRIPT_DIR) -echo $DATE_START $DATE_END +# Setup cache file +function setup_cache { + mv $ROOT_DIR/cache/temp-mkr-cache.sqlite $ROOT_DIR/cache/mkr-cache.sqlite || ( + echo Failed to setup cache file. Perhaps you forgot to stop the bot first? + touch $ROOT_DIR/cache/temp-mkr-cache.loaded + return 1 + ) + clear_temp_cache + echo Done + return 0 +} -exit 0 +# Function that clears broken cache in case of error +function clear_temp_cache { + rm -f $ROOT_DIR/cache/temp-mkr-cache.* || ( + echo Failed to clear temp cache + return 1 + ) + return 0 +} # Check if cache is already loaded if [ -f $ROOT_DIR/cache/temp-mkr-cache.loaded ]; then @@ -18,38 +35,16 @@ clear_temp_cache # Install cacher if not installed echo Installing cacher -bash $SCRIPT_DIR/install-cacher.sh -y || ( +bash $ROOT_DIR/tools/install-cacher.sh -y || ( echo Failed to install cacher exit 1 ) && echo Cacher installed # Load cache -bash $ROOT_DIR/tools/load_cache.sh -url=$API_URL -dateStart=$DATE_START -dateEnd=$DATE_END -output="$ROOT_DIR/cache/temp-mkr-cache.sqlite" || ( +$ROOT_DIR/bin/cacher -url=$API_URL -dateStart=$DATE_START -dateEnd=$DATE_END -output="$ROOT_DIR/cache/temp-mkr-cache.sqlite" || ( echo Failed to load cache clear_temp_cache exit 1 ) setup_cache || exit 1 - - -# Setup cache file -function setup_cache { - mv $ROOT_DIR/cache/temp-mkr-cache.sqlite $ROOT_DIR/cache/mkr-cache.sqlite || ( - echo Failed to setup cache file. Perhaps you forgot to stop the bot first? - touch $ROOT_DIR/cache/temp-mkr-cache.loaded - return 1 - ) - clear_temp_cache - echo Done - return 0 -} - -# Function that clears broken cache in case of error -function clear_temp_cache { - rm $ROOT_DIR/cache/temp-mkr-cache.* || ( - echo Failed to clear temp cache - return 1 - ) - return 0 -}