mirror of
https://git.FreeBSD.org/ports.git
synced 2024-11-23 00:43:28 +00:00
Update to 1.1: mkcatalog(.in) script update.
- Fix symbolic-link'ed ${CAT_DIR} problem. - Add -c option: specify top-level catalog file(default:${CAT_DIR}/catalog). - Add -v option: verbose mode. - Modify some messages. Obtained from: Hiroki Sato <hrs@FreeBSD.org>
This commit is contained in:
parent
ecc3153c77
commit
b36ae732b4
Notes:
svn2git
2021-03-31 03:12:20 +00:00
svn path=/head/; revision=35950
@ -8,7 +8,7 @@
|
||||
#
|
||||
|
||||
PORTNAME= mkcatalog
|
||||
PORTVERSION= 1.0
|
||||
PORTVERSION= 1.1
|
||||
CATEGORIES= textproc
|
||||
MASTER_SITES= # none
|
||||
DISTFILES= # none
|
||||
|
@ -7,123 +7,287 @@
|
||||
#
|
||||
# $FreeBSD$
|
||||
#
|
||||
sh_basename ()
|
||||
{
|
||||
l_value=$1
|
||||
IFS_old=${IFS}; IFS=" /"; set -- ${l_value}; IFS=${IFS_old}
|
||||
case $# in
|
||||
0) ;;
|
||||
*) echo `eval echo \\$$#` ;;
|
||||
esac
|
||||
}
|
||||
|
||||
sh_dirname ()
|
||||
{
|
||||
l_value=$1
|
||||
IFS_old=${IFS}; IFS=" /"; set -- ${l_value}; IFS=${IFS_old}
|
||||
l_dirname=$1; shift;
|
||||
while
|
||||
case $# in
|
||||
0) break ;;
|
||||
1) echo ${l_dirname}; break ;;
|
||||
*) ;;
|
||||
esac;
|
||||
do
|
||||
l_dirname="${l_dirname}/$1";
|
||||
shift;
|
||||
done
|
||||
}
|
||||
|
||||
norm_dir ()
|
||||
{
|
||||
[ -d "$1" ] && echo `exec 2>/dev/null; cd $1; echo ${PWD}`
|
||||
}
|
||||
|
||||
verbose_msg ()
|
||||
{
|
||||
case ${F_VERBOSE} in
|
||||
1) echo " ===> $*" ;;
|
||||
*) ;;
|
||||
esac
|
||||
}
|
||||
|
||||
PREFIX=@@PREFIX@@
|
||||
CAT_DIR=${PREFIX}/share/sgml
|
||||
TMPDIR=/tmp
|
||||
ARGV0=`sh_basename $0`
|
||||
|
||||
# default top-level catalog file
|
||||
CAT_DIR=${PREFIX}/share/sgml
|
||||
CAT_FILE=catalog
|
||||
|
||||
F_PRESERVE_OLD=""
|
||||
F_QUIET=""
|
||||
args=`getopt pq $*` ; set -- $args
|
||||
F_VERBOSE=""
|
||||
args=`getopt pqvc: $*` ; set -- $args
|
||||
for i
|
||||
do
|
||||
case "$i" in
|
||||
-p) F_PRESERVE_OLD=1; shift ;;
|
||||
-q) F_QUIET=1; shift ;;
|
||||
--) shift; break ;;
|
||||
-c) CAT_DIR=`sh_dirname $2`;
|
||||
CAT_FILE=`sh_basename $2`;
|
||||
shift; shift ;;
|
||||
-p) F_PRESERVE_OLD=1; shift ;;
|
||||
-q) exec 1> /dev/null 2>&1; shift ;;
|
||||
-v) F_VERBOSE=1; shift ;;
|
||||
--) shift; break ;;
|
||||
esac
|
||||
done
|
||||
|
||||
[ "x${F_QUIET}" != "x" ] && exec 1> /dev/null 2>&1
|
||||
|
||||
dtd_install=$1
|
||||
dtd_act=$1
|
||||
dtd_dir=$2
|
||||
[ x"$3" != "x" ] && dtd_catalog=`basename "$3"` || dtd_catalog=''
|
||||
dtd_catalog=`sh_basename "$3"`
|
||||
|
||||
### option check
|
||||
case "${dtd_install}" in
|
||||
install|deinstall)
|
||||
if [ -d "${CAT_DIR}/${dtd_dir}" -o -d "${dtd_dir}" ]; then
|
||||
dtd_dir=`exec 2>/dev/null; cd ${CAT_DIR}/${dtd_dir} || cd ${dtd_dir}; pwd`
|
||||
case "${dtd_dir}" in
|
||||
${CAT_DIR}/*) ;;
|
||||
*) echo "`basename $0`: DTD directory \"${dtd_dir}\" is invalid."
|
||||
exit 1 ;;
|
||||
esac
|
||||
else
|
||||
echo "`basename $0`: DTD directory \"${dtd_dir}\" not found."
|
||||
### option check and normalize ${dtd_dir}
|
||||
case "${dtd_act}" in
|
||||
add|install|delete|deinstall|enable|disable)
|
||||
if [ ! -d "${CAT_DIR}" ]; then
|
||||
echo "${ARGV0}: top-level catalog dir \"${CAT_DIR}\" not found."
|
||||
exit 1
|
||||
elif [ ! -n "${dtd_dir}" ]; then
|
||||
echo "${ARGV0}: DTD directory is not specified."
|
||||
exit 1
|
||||
elif [ ! -d "${CAT_DIR}/${dtd_dir}"\
|
||||
-a ! -d "${dtd_dir}" ]; then
|
||||
echo "${ARGV0}: DTD directory \"${dtd_dir}\" not found."
|
||||
exit 1
|
||||
elif [ ! -f "${CAT_DIR}/${dtd_dir}/${dtd_catalog:-catalog}"\
|
||||
-a ! -f "${dtd_dir}/${dtd_catalog:-catalog}" ]; then
|
||||
echo "${ARGV0}: DTD catalog \"${dtd_dir}/${dtd_catalog:-catalog}\" not found."
|
||||
exit 1
|
||||
fi
|
||||
### normalize dtd_dir
|
||||
verbose_msg "top-level catalog dir (specified): ${CAT_DIR}"
|
||||
CAT_DIR=`norm_dir ${CAT_DIR}`
|
||||
verbose_msg "top-level catalog dir (normalized): ${CAT_DIR}"
|
||||
verbose_msg "target catalog dir (specified): ${dtd_dir}"
|
||||
dtd_dir=`norm_dir ${CAT_DIR}/${dtd_dir} || norm_dir ${dtd_dir}`
|
||||
verbose_msg "target catalog dir (normalized): ${dtd_dir}"
|
||||
|
||||
case "${dtd_dir}" in
|
||||
${CAT_DIR}/*) ;;
|
||||
*) echo "${ARGV0}: DTD directory \"${dtd_dir}\" is invalid."
|
||||
exit 1 ;;
|
||||
esac
|
||||
### keep dtd_dir relative
|
||||
dtd_dir=${dtd_dir#"${CAT_DIR}/"}
|
||||
;;
|
||||
*)
|
||||
echo "`basename $0`: missig options."
|
||||
echo "usage: `basename $0` [-pq] [install|deinstall] dtd-directory-name [catalog-filename]."
|
||||
exit 1
|
||||
echo "${ARGV0}: missing options."
|
||||
cat <<EOF
|
||||
|
||||
Usage:
|
||||
${ARGV0} [-c toplv-catalog-filename] [-pqv] [install|add|deinstall|delete|enable|disable] dtd-directory-name [catalog-filename].
|
||||
|
||||
-c filename specifies top-level catalog file
|
||||
(default: ${PREFIX}/catalog)
|
||||
-p preseve old catalog file (as .old)
|
||||
-q quiet mode
|
||||
-v verbose mode (for debug)
|
||||
|
||||
ex.) mkcatalog install html/4.0
|
||||
mkcatalog -c /home/foo/sgml/catalog install html/4.0/my_ext html_catalog
|
||||
EOF
|
||||
exit 1 ;;
|
||||
esac
|
||||
|
||||
echo "${dtd_install} catalog for \"${dtd_dir}\""
|
||||
echo "* top-level catalog: ${CAT_DIR}/${CAT_FILE}"
|
||||
verbose_msg "action: ${dtd_act}"
|
||||
verbose_msg "target catalog dir: ${dtd_dir}"
|
||||
verbose_msg "target catalog file: ${dtd_catalog:-catalog}"
|
||||
|
||||
echo "* attempt to ${dtd_act} catalog in ${dtd_dir}"
|
||||
TMPCAT=/tmp/catalog.$$
|
||||
|
||||
proc_catalog () {
|
||||
catalog_high=${1:-${CAT_DIR}/catalog}
|
||||
catalog_low=${2:-${dtd_name}/catalog}
|
||||
cat_line="CATALOG \"${catalog_low}\""
|
||||
abs_path_head=${catalog_high%/catalog}
|
||||
proc_catalog ()
|
||||
{
|
||||
l_bottom_p=$1 # allow to delete upper catalog?
|
||||
l_upper=$2 # dirname of upper catalog
|
||||
l_lower=$3 # dirname of lower catalog
|
||||
|
||||
touch ${catalog_high} || exit 1
|
||||
grep -v "CATALOG \"\(${abs_path_head}/\)\?${catalog_low}\"" ${catalog_high} > ${TMPCAT}
|
||||
|
||||
### preserve old catalog
|
||||
if [ "x${F_PRESERVE_OLD}" != "x" ]; then
|
||||
cp ${catalog_high} ${catalog_high}.old || exit 1
|
||||
fi
|
||||
|
||||
case "${dtd_install}" in
|
||||
install)
|
||||
echo " * add ${cat_line} line to ${catalog_high}"
|
||||
echo "${cat_line}" >> ${TMPCAT}
|
||||
cp ${TMPCAT} ${catalog_high} || exit 1
|
||||
;;
|
||||
deinstall)
|
||||
echo " * delete ${cat_line} line from ${catalog_high}"
|
||||
if [ ! -s ${TMPCAT} ]; then
|
||||
echo " * delete empty catalog ${catalog_high}"
|
||||
rm -f ${catalog_high}
|
||||
else
|
||||
cp ${TMPCAT} ${catalog_high} || exit 1
|
||||
undelete_flag="YES"
|
||||
fi
|
||||
;;
|
||||
case ${first_p} in
|
||||
[Yy][Ee][Ss]) catalog=${dtd_catalog:-"catalog"} ;;
|
||||
*) catalog=${CAT_FILE} ;;
|
||||
esac
|
||||
|
||||
# l_upper_cat -> relative path from ${CAT_DIR}
|
||||
# l_lower_cat -> relative path from l_upper
|
||||
l_upper_cat=${l_upper}/${CAT_FILE}
|
||||
l_lower_cat=`sh_basename ${l_lower}`/${catalog}
|
||||
|
||||
# l_*_abs_* -> absolute path respectively
|
||||
l_upper_abs=${CAT_DIR}/${l_upper}
|
||||
l_lower_abs=${CAT_DIR}/${l_lower}
|
||||
l_upper_abs_cat=${CAT_DIR}/${l_upper}/${CAT_FILE}
|
||||
l_lower_abs_cat=${CAT_DIR}/${l_lower}/${catalog}
|
||||
|
||||
# for debug
|
||||
#echo ${l_bottom_p} ${l_upper_cat} ${l_lower_cat}
|
||||
|
||||
l_cat_line="CATALOG \"${l_lower_cat}\""
|
||||
l_abs_path_head=`cd ${l_upper_abs}; echo ${PWD}`
|
||||
|
||||
# for debug
|
||||
#echo ${l_cat_line}
|
||||
|
||||
# first, create temporary catalog from l_upper_cat
|
||||
# not including CATALOG line of l_lower_cat (if no catalog,
|
||||
# create empty one).
|
||||
#
|
||||
# NOTE: file manipulations require absolute path, but
|
||||
# CATALOG line do relative from upper's one.
|
||||
#
|
||||
touch ${l_upper_abs_cat} || exit 1
|
||||
grep -v "\( *-- *\)\?CATALOG *\"\(${l_abs_path_head}/\)\?${l_lower_cat}\"\( *-- *\)\?" ${l_upper_abs_cat} > ${TMPCAT}
|
||||
|
||||
# preserve old catalog as necessary
|
||||
if [ "x${F_PRESERVE_OLD}" != "x" ]; then
|
||||
cp ${l_upper_abs_cat} ${l_upper_abs_cat}.old || exit 1
|
||||
fi
|
||||
|
||||
case "${dtd_act}" in
|
||||
add|install|enable)
|
||||
#
|
||||
# if "install or add or enable",
|
||||
# create "the tamporary catalog + l_cat_line" and install it.
|
||||
#
|
||||
echo " - ${dtd_act} ${l_cat_line} line in ${l_upper_cat}"
|
||||
echo "${l_cat_line}" >> ${TMPCAT}
|
||||
cp ${TMPCAT} ${l_upper_abs_cat} || exit 1
|
||||
;;
|
||||
disable)
|
||||
#
|
||||
# if "disable", install the same above but l_cat_line is
|
||||
# commented out.
|
||||
#
|
||||
case ${first_p} in
|
||||
[Yy][Ee][Ss])
|
||||
echo " - ${dtd_act} ${l_cat_line} line in ${l_upper_cat}"
|
||||
echo "-- ${l_cat_line} --" >> ${TMPCAT}
|
||||
cp ${TMPCAT} ${l_upper_abs_cat} || exit 1
|
||||
;;
|
||||
*) rm -f ${TMPCAT};
|
||||
exit 0;
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
delete|deinstall)
|
||||
#
|
||||
# if "deinstall or delete" and the temporary catalog is
|
||||
# not empty, install the catalog itself (in the case of being
|
||||
# empty, delete it). ${l_bottom_p}=YES means that
|
||||
# ${l_upper_cat} can be deleted safely, otherwise not.
|
||||
#
|
||||
case ${l_bottom_p} in
|
||||
[Yy][Ee][Ss])
|
||||
echo " - ${dtd_act} ${l_cat_line} line from ${l_upper_cat}"
|
||||
if [ ! -s ${TMPCAT} ]; then
|
||||
echo " - delete empty catalog ${l_upper_cat}"
|
||||
rm -f ${l_upper_abs_cat}
|
||||
else
|
||||
cp ${TMPCAT} ${l_upper_abs_cat} || exit 1
|
||||
fi
|
||||
;;
|
||||
*) rm -f ${TMPCAT};
|
||||
exit 0;
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
|
||||
#
|
||||
# when flag "preserve old" is specified but
|
||||
# there is no difference between new file and old one,
|
||||
# preservation is silently denied.
|
||||
#
|
||||
if [ "x${F_PRESERVE_OLD}" != "x" ] && \
|
||||
cmp -s ${catalog_high}.old ${catalog_high}; then
|
||||
rm -f ${catalog_high}.old
|
||||
cmp -s ${l_upper_abs_cat}.old ${l_upper_abs_cat}; then
|
||||
rm -f ${l_upper_abs_cat}.old
|
||||
fi
|
||||
rm -f ${TMPCAT}
|
||||
}
|
||||
|
||||
IFS=" /"; set -- ${dtd_dir}
|
||||
dtd_name=$1
|
||||
dtd_list="$*"
|
||||
IFS=" "
|
||||
n_dtd_list=$#
|
||||
counter=${n_dtd_list}
|
||||
undelete_flag="NO"
|
||||
compose_dir_list ()
|
||||
{
|
||||
l_dir=$1
|
||||
#
|
||||
# Creates dirlist such as the following.
|
||||
# input: docbook/4.1/my_extension
|
||||
# return: docbook/4.1/my_extension docbook/4.1 docbook
|
||||
#
|
||||
IFS_old=${IFS}; IFS=" /"; set -- ${l_dir}
|
||||
l_dir_top=$1;
|
||||
shift;
|
||||
l_dir_rest=$*;
|
||||
IFS=${IFS_old}
|
||||
|
||||
while [ ${counter} -ne 0 ];
|
||||
l_dir_item=${l_dir_top}
|
||||
l_dir_list=${l_dir_top}
|
||||
|
||||
for i in ${l_dir_rest}
|
||||
do
|
||||
l_dir_item="${l_dir_item}/${i}"
|
||||
l_dir_list="${l_dir_item} ${l_dir_list}"
|
||||
done
|
||||
echo ${l_dir_list}
|
||||
}
|
||||
|
||||
bottom_p=YES
|
||||
first_p=YES
|
||||
|
||||
set -- `compose_dir_list ${dtd_dir}` .
|
||||
verbose_msg "process catalog (relative to top one): $*"
|
||||
while
|
||||
case $# in
|
||||
1) break ;;
|
||||
*) ;;
|
||||
esac;
|
||||
do
|
||||
lower_dtd_dir=`echo ${dtd_list} | sed 's/[^ ]* //g'`
|
||||
upper_dtd_list=`echo ${dtd_list} | sed "s/${lower_dtd_dir}$//"`
|
||||
lower=$1
|
||||
upper=$2
|
||||
proc_catalog "${bottom_p}" "${upper}" "${lower}"
|
||||
|
||||
cat_high_dir=${CAT_DIR}/`echo "${upper_dtd_list}" | sed 's; ;/;g'`
|
||||
cat_high_dir=`echo ${cat_high_dir} | sed 's;/$;;'`
|
||||
cat_low_dir=${lower_dtd_dir}
|
||||
|
||||
if [ ${undelete_flag} = "YES" ]; then
|
||||
exit 0;
|
||||
first_p=NO
|
||||
if [ -f ${CAT_DIR}/${upper}/${CAT_FILE} ]; then
|
||||
bottom_p=NO
|
||||
fi
|
||||
|
||||
if [ ${counter} -ne ${n_dtd_list} ]; then
|
||||
proc_catalog ${cat_high_dir}/catalog ${cat_low_dir}/catalog
|
||||
else
|
||||
proc_catalog ${cat_high_dir}/catalog ${cat_low_dir}/${dtd_catalog:-catalog}
|
||||
fi
|
||||
|
||||
counter=`expr ${counter} - 1`
|
||||
dtd_list=${upper_dtd_list}
|
||||
shift;
|
||||
done
|
||||
|
||||
exit 0;
|
||||
|
Loading…
Reference in New Issue
Block a user