Skip to content

Commit

Permalink
Fix broken linux scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
cubicbyte committed Feb 18, 2023
1 parent 70eacc7 commit e860edd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 28 deletions.
5 changes: 3 additions & 2 deletions tools/install-cacher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
47 changes: 21 additions & 26 deletions tools/load-cache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

0 comments on commit e860edd

Please sign in to comment.