first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / scripts / buildor / version_utils.sh
1 #!/bin/bash
2
3 # version_utils:
4 #
5 # Some utilities for dealing with version stamps.
6
7 function print_instructions {
8   echo -e "\
9 This script processes version numbers in an ini file formatted file.  It\n\
10 currently only supports one set of version numbers in the file, in the form:\n\
11   major=0\n\
12   minor=420\n\
13   revision=2323\n\
14   build=0\n\
15 The first parameter to the script is a command.  The available commands\n\
16 consists of:\n\
17   show\n\
18 The second parameter is the version file to process.\n\
19 All parameters are required."
20
21   exit 5
22 }
23
24 command=$1
25 if [ -z "$command" ]; then print_instructions; fi
26 version_file=$2
27 if [ -z "$version_file" ]; then print_instructions; fi
28
29 #echo got a command $command and version file $version_file
30
31 if [ "$command" = "show" ]; then
32   # show the version in the version file.
33   if [ ! -f "$version_file" ]; then
34     echo "The version file \"$version_file\" doesn't seem to exist."
35     exit 8
36   fi
37   major=$(grep 'major=' "$version_file" | sed -e 's/.*major=\([! #]*\)/\1/')
38   minor=$(grep 'minor=' "$version_file" | sed -e 's/.*minor=\([! #]*\)/\1/')
39   revision=$(grep 'revision=' "$version_file" | sed -e 's/.*revision=\([! #]*\)/\1/')
40   build=$(grep 'build=' "$version_file" | sed -e 's/.*build=\([! #]*\)/\1/')
41 #echo major=$major minor=$minor rev=$revision build=$build
42
43   echo -n $major.$minor.$revision.$build
44 fi
45
46