Merge pull request #577 from knnniggett/zmeditconfigdata

Add zmeditconfigdata.sh script to source
pull/579/merge
Andrew Bauer 2014-11-15 13:15:45 -06:00
commit 32ee3e8431
4 changed files with 123 additions and 6 deletions

View File

@ -159,4 +159,14 @@ the following steps.
6. Create new Pull Request
7. The team will then review, discuss and hopefully merge your changes.
### Package Maintainters
Many of the ZoneMinder configration variable default values are not configurable at build time through autotools or cmake. A new tool called *zmeditconfigdata.sh* has been added to allow package maintainers to manipulate any variable stored in ConfigData.pm without patching the source.
For example, let's say I have created a new ZoneMinder package that contains the cambolzola javascript file. However, by default cambozola support is turned off. To fix that, add this to the pacakging script:
```bash
./zmeditconfigdata.sh ZM_OPT_CAMBOZOLA yes
```
Note that zmeditconfigdata.sh is intended to be called prior to running cmake or configure.
[![Analytics](https://ga-beacon.appspot.com/UA-15147273-6/ZoneMinder/README.md)](https://github.com/igrigorik/ga-beacon)

View File

@ -22,8 +22,6 @@ URL: http://www.zoneminder.com/
#Source: https://github.com/ZoneMinder/ZoneMinder/archive/v%{version}.tar.gz
Source: ZoneMinder-%{version}.tar.gz
Patch1: zoneminder-1.28.0-defaults.patch
BuildRequires: cmake gnutls-devel systemd-units bzip2-devel
BuildRequires: community-mysql-devel pcre-devel libjpeg-turbo-devel
BuildRequires: perl(Archive::Tar) perl(Archive::Zip)
@ -66,7 +64,13 @@ too much degradation of performance.
%prep
%setup -q -n ZoneMinder-%{version}
%patch1 -p0 -b .defaults
# Change the following default values
./utils/zmeditconfigdata.sh ZM_PATH_ZMS /cgi-bin/zm/nph-zms
./utils/zmeditconfigdata.sh ZM_OPT_CAMBOZOLA yes
./utils/zmeditconfigdata.sh ZM_PATH_SWAP /dev/shm
./utils/zmeditconfigdata.sh ZM_UPLOAD_FTP_LOC_DIR /var/spool/zoneminder-upload
./utils/zmeditconfigdata.sh ZM_OPT_CONTROL yes
%build
%cmake \

View File

@ -17,8 +17,6 @@ URL: http://www.zoneminder.com/
#Source0: https://github.com/ZoneMinder/ZoneMinder/archive/v%{version}.tar.gz
Source0: ZoneMinder-%{version}.tar.gz
Patch1: zoneminder-1.28.0-defaults.patch
BuildRequires: cmake gnutls-devel bzip2-devel
BuildRequires: mysql-devel pcre-devel libjpeg-turbo-devel
BuildRequires: perl(Archive::Tar) perl(Archive::Zip)
@ -63,7 +61,12 @@ too much degradation of performance.
%prep
%setup -q -n ZoneMinder-%{version}
%patch1 -p0 -b .defaults
# Change the following default values
./utils/zmeditconfigdata.sh ZM_PATH_ZMS /cgi-bin/zm/nph-zms
./utils/zmeditconfigdata.sh ZM_OPT_CAMBOZOLA yes
./utils/zmeditconfigdata.sh ZM_PATH_SWAP /dev/shm
./utils/zmeditconfigdata.sh ZM_UPLOAD_FTP_LOC_DIR /var/spool/zoneminder-upload
./utils/zmeditconfigdata.sh ZM_OPT_CONTROL yes
%build
# Have to override CMAKE_INSTALL_LIBDIR for cmake < 2.8.7 due to this bug:

100
utils/zmeditconfigdata.sh Executable file
View File

@ -0,0 +1,100 @@
#!/bin/bash
# This script allows the package maintainer to change the default value
# of any variable specified in ConfigData.pm without writing a patch.
# Run this script from your build folder, before running configure or cmake.
usage()
{
cat <<EOF
USAGE:
$0 VARIABLE DEFAULT [CONFIGDATA DIRECTORY]
Replace the default value, DEFAULT, of the specified ZoneMinder
variable, VARIABLE, located in ConfigData.pm.in.
Default folder for ConfigData is ./scripts/ZoneMinder/lib/ZoneMinder
Specify CONFIGDATA DIRETORY to override.
Run this script from your build folder, before running configure or cmake.
EXAMPLE:
zmeditconfigdata.sh ZM_OPT_CAMBOZOLA yes
WARNING:
The user supplied value for DEFAULT is not checked for sanity. For example,
changing ZM_LANG_DEFAULT to "pony" will cause bad things to happen!
EOF
}
if [ -z "$1" ] || [ -z "$2" ]; then
usage
exit 0
fi
# Check to see if this script has access to all the commands it needs
for CMD in set echo printf grep sed ; do
type $CMD &> /dev/null
if [ $? -ne 0 ]; then
echo
echo "ERROR: The script cannot find the required command \"${CMD}\"."
echo
exit 1
fi
done
escape()
{
escaped=""
local temp="$(printf %q "$1")"
escaped="$(echo $temp | sed 's/\//\\\//g')"
}
# Assign variables once they are properly escaped
escape $1
variable=$escaped
escape $2
default=$escaped
# Set the path to ConfigData
if [ -n "$3" ]; then
configdata="$3/ConfigData.pm.in"
else
configdata="./scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in"
fi
# Check to make sure we can find ConfigData
if [ ! -e "$configdata" ]; then
echo "CONFIGDATA FILE NOT FOUND: $configdata"
exit 1
fi
# Now that we've found ConfidData, verify the supplied variable
# is defined inside the ConfigData file.
if [ -z "$(grep $variable $configdata)" ]; then
echo "ZONEMINDER VARIABLE NOT FOUND: $variable"
exit 1
fi
# Update the supplied variable with the new default value.
# Don't stare too closely. You will burn your eyes out.
sed -i '/.*'${variable}'.*/{
$!{ N
s/\(.*'${variable}'.*\n.*\)\"\(.*\)\"/\1\"'${default}'\"/
t yes
P
D
:yes
}
}' $configdata
if [ "$?" != "0" ]; then
echo "SED RETURNED FAILURE"
exit 1
fi