|
#!/usr/bin/ksh93.att
################################################################
####
#### Description: Script to change the time zone variable (TZ) in
#### the /etc/environment file. The TZ variable is modified to
#### reflect the new DST changes.
####
#### Central US TZ=CST6CDT,M3.2.0,M11.1.0
####
################################################################
function mkversion {
typeset FNAME
typeset F
FNAME="${1:?ERROR: Syntax \"${0} fileName\"}"
[[ ! -f ${FNAME} ]] && echo "ERROR: ${FNAME} does not exist" && return 1
for F in $( ls -1r ${FNAME}.+([0-9]) 2>/dev/null )
do
[[ ! -w ${F} ]] && echo "ERROR: ${F} is not writeable" && return 2
[[ ! -r ${F} ]] && echo "ERROR: ${F} is not readable" && return 3
[[ ! -w ${F%/*} ]] && echo "ERROR: . is not writeable" && return 4
done
for F in $( ls -1r ${FNAME}.+([0-9]) 2>/dev/null )
do
cp -f ${F} ${FNAME}.$(( ${F#${FNAME}.} + 1 )) || return 5
done
cp -f "${FNAME}" "${FNAME}.0"
}
################################################################
function chenv {
typeset ENVFILE="/etc/environment"
typeset ENVFILE="./environment"
typeset TMPFILE="/tmp/environment.${$}.tmp"
typeset VARNAME="TZ"
typeset OLDVAL="CST6CDT"
typeset NEWVAL="${OLDVAL},M3.2.0,M11.1.0"
if [[ ! -w "${ENVFILE}" ]]
then
print -u 2 -- "# ERROR: ${ENVFILE} is not writable by this user"
exit 1
fi
print -- "# current ${ENVFILE} ${VARNAME} variable is defined as follows:"
grep "^${VARNAME}=" "${ENVFILE}"
mkversion "${ENVFILE}"
exec 3<"${ENVFILE}"
exec 4>"${TMPFILE}"
while IFS="" read -u 3 -r -- LINE
do
if [[ "_${LINE}" == _${VARNAME}=${OLDVAL}* ]]
then
print -u 4 -- "${VARNAME}=${NEWVAL}"
else
print -u 4 -r -- "${LINE}"
fi
done
exec 3<&-
exec 4>&-
if cp -f "${TMPFILE}" "${ENVFILE}"
then
print -- "# successfully modified ${ENVFILE} ${VARNAME} variable as follows:"
grep "^${VARNAME}=" "${ENVFILE}"
else
print -- "# ERROR: unable to modify ${ENVFILE}"
fi
rm -f "${TMPFILE}"
return 0
}
################################################################
chenv "${@}"
|
|
|