-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
executable file
·94 lines (74 loc) · 2.51 KB
/
configure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#! /bin/bash
# Script to generate the configuration '.config' file for the framework
# Copyright (C) 2008 Supercomputing Systems AG
#
# This library is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with this library; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
trim() {
# trim $1: cut of leading and trailing white space
# $1: the string to trim
echo "$1" | grep -oE "[^ \t\n].*[^ \t\n]"
}
get_config() {
# get_config $1 $2: load a configuration from a configuration file
# $1: the name of the configuration file
# $2: name of the configuration
if [ -e "$1" ]; then
trim "$(grep -E "^$2" < $1 | cut -d "=" -f 2)"
fi
}
read_config() {
# read_config $1: read settings from a configuration file
# $1: name of the configuration file
local NAME, VALUE
cat "$1" | while read i; do
NAME=$(trim $(echo $i | cut -d "=" -f 1))
VALUE=$(trim $(echo $i | cut -d "=" -f 2))
eval $NAME="$VALUE"
done
}
ask() {
# ask $1 $2: ask the user something and return the answer
# $1: the default value
# $2: the prompt
local REPLY
read -e -p "$2 [$1]: "
[ "$REPLY" ] && echo "$REPLY" || echo "$1"
}
# global parameters
CONFIG_FILE=".config"
CONFIG_NAMES=(CONFIG_FRAMEWORK CONFIG_TARGET_IP)
CONFIG_PROMPTS=("Enter the path to the framework you want to use", "Enter the IP address of the target device")
CONFIG_VALUES=("../oscar" "")
# load the configurations
for i in ${!CONFIG_NAMES[*]}; do
NAME=${CONFIG_NAMES[$i]}
VALUE=$(get_config "$CONFIG_FILE" "$NAME")
[ "$VALUE" ] && CONFIG_VALUES[$i]=$VALUE
done
# ask the user about configurations
for i in ${!CONFIG_NAMES[*]}; do
PROMPT=${CONFIG_PROMPTS[$i]}
VALUE=${CONFIG_VALUES[$i]}
CONFIG_VALUES[$i]=$(ask "$VALUE" "$PROMPT")
done
# write the configuration file
rm -f "${CONFIG_FILE}_new"
for i in ${!CONFIG_NAMES[*]}; do
NAME=${CONFIG_NAMES[$i]}
VALUE=${CONFIG_VALUES[$i]}
echo "$NAME = $VALUE" >> "${CONFIG_FILE}_new"
done
mv -f "${CONFIG_FILE}_new" "${CONFIG_FILE}"
exit 0