]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/scripts/readhash
Merge remote-tracking branch 'trikolon/next' into next
[people/teissler/ipfire-2.x.git] / src / scripts / readhash
1 #!/bin/sh
2 #
3 # This script reads in variables from a config file, and produces a list of
4 # commands to run to set these as shell environment variables, it is
5 # intended to be used as follows:
6 #
7 # eval $(readhash /var/ipfire/main/settings)
8 #
9
10 # shell variables must consist of alphanumeric characters and underscores,
11 # and begin with an alphabetic character or underscore.
12 VARNAME='[A-Za-z_][A-Za-z0-9_]*'
13
14 # For the assigned value we only accept a limited number of characters - none
15 # of which are shell metachars
16 VARCHARS='A-Za-z0-9=/,.:%_@#+-'
17 VARVAL="[${VARCHARS}]*"
18
19 sed -ne "s/\(${VARNAME}\)=\(${VARVAL}\)$/\1=\2/p" $1
20
21 # Accept space only if it's quoted
22 sed -ne "s/\(${VARNAME}\)=\('[ ${VARCHARS}]*'\)$/\1=\2/p" $1