version checking improved

This commit is contained in:
timerix 2022-10-03 11:28:07 +06:00
parent b514eda08d
commit 286ce67bbe
3 changed files with 28 additions and 36 deletions

View File

@ -3,7 +3,7 @@ My C/C++ build system written in bash.
Repo contains some scripts (functions, init, etc.), which can be used in your custom task scripts. There are also some default tasks. Repo contains some scripts (functions, init, etc.), which can be used in your custom task scripts. There are also some default tasks.
All tasks should be launched through `Makefile`. Tasks can be configured in `.config` file (it is automatically created by init.sh). All tasks should be launched through `Makefile`. Tasks can be configured in `current.config` file (it is automatically created by init.sh).
## How to set up ## How to set up

View File

@ -1,7 +1,8 @@
#!/bin/bash #!/bin/bash
CONFIG_VER=2 CBUILD_VERSION=2
CONFIG_VERSION=1
PROJECT=some_project PROJECT="NULL"
CMP_C=gcc CMP_C=gcc
CMP_CPP=g++ CMP_CPP=g++
STD_C=c11 STD_C=c11

55
init.sh
View File

@ -1,44 +1,35 @@
#!/bin/bash #!/bin/bash
source cbuild/colors.sh source cbuild/colors.sh
source cbuild/functions.sh source cbuild/functions.sh
set -eo pipefail
function create_default_config(){ # copying default config from cbuild if it not exists
if [ -f "default.config" ]; then if [ ! -f default.config ]; then
cp default.config .config cp cbuild/default.config default.config
else printf "${YELLOW}Default config didn't exist, copied from cbuild.\n"
cp cbuild/default.config .config
fi fi
printf "${YELLOW}Default config created.\nEdit it.\n" # getting some values from default config
} source default.config
DEFAULT_CONFIG_VERSION=$CONFIG_VERSION
DEFAULT_CBUILD_VERSION=$CBUILD_VERSION
#.config # reading current config or creating default
if [ ! -f ".config" ]; then if [ ! -f current.config ]; then
printf "${YELLOW}./.config doesn't exist\n" printf "${YELLOW}./current.config doesn't exist\n"
create_default_config cp default.config current.config
printf "${GRAY}" printf "${YELLOW}New config created from the default.\nEdit it.\n${GRAY}"
exit exit
fi fi
source .config source current.config
#version check # checking versions
if [ ! $CONFIG_VER -eq 2 ]; then if [ ! $CBUILD_VERSION -eq $DEFAULT_CBUILD_VERSION ]; then
printf "${RED}Your config version isn't correct\n" printf "${RED}Your config was created for outdated cbuild version\n${GRAY}"
while true; do exit
printf "${WHITE}Backup current config and create default one? (y/n) " fi
read answ if [ ! $CONFIG_VERSION -eq $DEFAULT_CONFIG_VERSION ]; then
case $answ in printf "${RED}Your config version isn't correct\n${GRAY}"
[Yy] ) exit
cp .config .config.backup
create_default_config
printf "${GRAY}"
exit;;
[Nn] )
printf "${GRAY}"
exit;;
* ) printf "${RED}incorrect answer\n";;
esac
done
fi fi
mkdir -p "$OUTDIR" mkdir -p "$OUTDIR"