From 286ce67bbecfac950fd550098afc69f163364111 Mon Sep 17 00:00:00 2001 From: timerix Date: Mon, 3 Oct 2022 11:28:07 +0600 Subject: [PATCH] version checking improved --- README.md | 2 +- default.config | 5 +++-- init.sh | 57 +++++++++++++++++++++----------------------------- 3 files changed, 28 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 8911694..4dc35d2 100644 --- a/README.md +++ b/README.md @@ -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. -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 diff --git a/default.config b/default.config index e3454c1..5b35cac 100644 --- a/default.config +++ b/default.config @@ -1,7 +1,8 @@ #!/bin/bash -CONFIG_VER=2 +CBUILD_VERSION=2 +CONFIG_VERSION=1 -PROJECT=some_project +PROJECT="NULL" CMP_C=gcc CMP_CPP=g++ STD_C=c11 diff --git a/init.sh b/init.sh index e989f10..a40f623 100644 --- a/init.sh +++ b/init.sh @@ -1,44 +1,35 @@ #!/bin/bash - source cbuild/colors.sh source cbuild/functions.sh +set -eo pipefail -function create_default_config(){ - if [ -f "default.config" ]; then - cp default.config .config - else - cp cbuild/default.config .config - fi - printf "${YELLOW}Default config created.\nEdit it.\n" -} +# copying default config from cbuild if it not exists +if [ ! -f default.config ]; then + cp cbuild/default.config default.config + printf "${YELLOW}Default config didn't exist, copied from cbuild.\n" +fi +# getting some values from default config +source default.config +DEFAULT_CONFIG_VERSION=$CONFIG_VERSION +DEFAULT_CBUILD_VERSION=$CBUILD_VERSION -#.config -if [ ! -f ".config" ]; then - printf "${YELLOW}./.config doesn't exist\n" - create_default_config - printf "${GRAY}" +# reading current config or creating default +if [ ! -f current.config ]; then + printf "${YELLOW}./current.config doesn't exist\n" + cp default.config current.config + printf "${YELLOW}New config created from the default.\nEdit it.\n${GRAY}" exit fi -source .config +source current.config -#version check -if [ ! $CONFIG_VER -eq 2 ]; then - printf "${RED}Your config version isn't correct\n" - while true; do - printf "${WHITE}Backup current config and create default one? (y/n) " - read answ - case $answ in - [Yy] ) - cp .config .config.backup - create_default_config - printf "${GRAY}" - exit;; - [Nn] ) - printf "${GRAY}" - exit;; - * ) printf "${RED}incorrect answer\n";; - esac - done +# checking versions +if [ ! $CBUILD_VERSION -eq $DEFAULT_CBUILD_VERSION ]; then + printf "${RED}Your config was created for outdated cbuild version\n${GRAY}" + exit +fi +if [ ! $CONFIG_VERSION -eq $DEFAULT_CONFIG_VERSION ]; then + printf "${RED}Your config version isn't correct\n${GRAY}" + exit fi mkdir -p "$OUTDIR"