VirtualBox

source: vbox/trunk/doc/manual/dita-ot-copy-exec.sh@ 99500

Last change on this file since 99500 was 99046, checked in by vboxsync, 21 months ago

manual/dita-ot-copy-exec.sh: Preserve executable bit when copying. bugref:10302

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 KB
Line 
1#!/usr/bin/env kmk_ash
2# $Id: dita-ot-copy-exec.sh 99046 2023-03-19 12:19:03Z vboxsync $
3## @file
4# Helper Script for copying the DITA-OT toolkit from $1 to $2,
5# run the following command line, nuke $2.
6#
7# DITA-OT-1.8.5 updates around 40 files everytime it is started in an manner
8# that will cause race conditions when starting multiple dost.jar instances
9# concurrently. So, we work around that by running each job of a unqiue and
10# temporary copy. Extra effort is taken to using hardlinking when possible
11# and to reduce the number of files and directory we copy.
12#
13
14#
15# Copyright (C) 2023 Oracle and/or its affiliates.
16#
17# This file is part of VirtualBox base platform packages, as
18# available from https://www.virtualbox.org.
19#
20# This program is free software; you can redistribute it and/or
21# modify it under the terms of the GNU General Public License
22# as published by the Free Software Foundation, in version 3 of the
23# License.
24#
25# This program is distributed in the hope that it will be useful, but
26# WITHOUT ANY WARRANTY; without even the implied warranty of
27# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28# General Public License for more details.
29#
30# You should have received a copy of the GNU General Public License
31# along with this program; if not, see <https://www.gnu.org/licenses>.
32#
33# SPDX-License-Identifier: GPL-3.0-only
34#
35
36#
37# Some constants.
38#
39MY_INSTALL="kmk_install"
40MY_MKDIR="kmk_mkdir"
41MY_RM="kmk_rm"
42MY_SED="kmk_sed"
43MY_CP="kmk_cp"
44
45# Debug
46MY_DEBUG_INSTALL="-v"
47MY_DEBUG_INSTALL=""
48
49MY_DEBUG_MKDIR="-v"
50MY_DEBUG_MKDIR=""
51
52MY_DEBUG_RM="-v"
53MY_DEBUG_RM=""
54
55#
56# Pop off the source and target directories from the input arguments.
57# We're not trying to be very userfriendly here, just reasonably safe.
58#
59if test $# -lt 5; then
60 echo "syntax error: too few arguments" 1>&2;
61 exit 2;
62fi
63MY_SRCDIR="$1"
64MY_DSTDIR="$2"
65if test "$3" != "--"; then
66 echo "syntax error: Expected '--' as the 3rd parameter, got: $3" 1>&2;
67 exit 2;
68fi
69shift 3
70if ! test -d "${MY_SRCDIR}"; then
71 echo "error: Source directory does not exists or is not a directory: ${MY_SRCDIR}" 1>&2;
72 exit 1;
73fi
74if test -e "${MY_DSTDIR}"; then
75 echo "error: Destination directory already exists: ${MY_DSTDIR}" 1>&2;
76 exit 1;
77fi
78
79#
80# Helper.
81#
82CopyTree()
83{
84 MY_SRCTREE="$1"
85 MY_DSTTREE="$2"
86
87 # Gather files and directories.
88 cd "${MY_SRCTREE}"
89 MY_DIRS=""
90 MY_DIRS_PAIRS=""
91 MY_FILES=""
92 MY_EXEC_FILES=""
93 for MY_FILE in *;
94 do
95 if test "${MY_FILE}" = "*"; then
96 # For empty directories we get '*' back. Ignore it.
97 elif test -d "${MY_SRCTREE}/${MY_FILE}"; then
98 case "${MY_SRCTREE}/${MY_FILE}" in
99 *\ *)
100 echo "Unexpected space in dir/subdir: ${MY_SRCTREE}/${MY_FILE}" 1>&2;
101 exit 1
102 ;;
103 esac
104 MY_DIRS="${MY_DIRS} ${MY_FILE}"
105 MY_DIRS_PAIRS="${MY_DIRS_PAIRS} ${MY_SRCTREE}/${MY_FILE} ${MY_DSTTREE}/${MY_FILE}"
106 elif test -f "${MY_SRCTREE}/${MY_FILE}"; then
107 case "${MY_SRCTREE}/${MY_FILE}" in
108 *\ *)
109 echo "Unexpected space in dir/filename: ${MY_SRCTREE}/${MY_FILE}" 1>&2;
110 exit 1
111 ;;
112
113 *org.dita.dost.platform/plugin.properties)
114 ;;
115 *_template.xml)
116 MY_FILES="${MY_FILES} ${MY_FILE}"
117 MY_TEMPLATED_FILES="${MY_TEMPLATED_FILES} ${MY_DSTTREE}/${MY_FILE%_template.xml}.xml"
118 ;;
119 *_template.xsl)
120 MY_FILES="${MY_FILES} ${MY_FILE}"
121 MY_TEMPLATED_FILES="${MY_TEMPLATED_FILES} ${MY_DSTTREE}/${MY_FILE%_template.xsl}.xsl"
122 ;;
123 *)
124 if test -x "${MY_SRCTREE}/${MY_FILE}"; then
125 MY_EXEC_FILES="${MY_EXEC_FILES} ${MY_FILE}"
126 else
127 MY_FILES="${MY_FILES} ${MY_FILE}"
128 fi
129 ;;
130 esac
131 else
132 echo "Unexpected file type: ${MY_SRCTREE}/${MY_FILE}" 1>&2;
133 exit 1
134 fi
135 done
136
137 # Install all the files in one go.
138 if test -n "${MY_FILES}"; then
139 "${MY_INSTALL}" ${MY_DEBUG_INSTALL} --hard-link-files-when-possible -m644 -- ${MY_FILES} "${MY_DSTTREE}/"
140 fi
141 if test -n "${MY_EXEC_FILES}"; then
142 "${MY_INSTALL}" ${MY_DEBUG_INSTALL} --hard-link-files-when-possible -m755 -- ${MY_EXEC_FILES} "${MY_DSTTREE}/"
143 fi
144
145 # Create all subdirs and recurse into each.
146 if test -n "${MY_DIRS}"; then
147 cd "${MY_DSTTREE}"
148 "${MY_MKDIR}" -p ${MY_DEBUG_MKDIR} -- ${MY_DIRS}
149
150 # Now transfer MY_DIRS_PAIRS to the argument list, so they're preseved across recursive calls.
151 # (the local command/keyword is busted in current binaries, though fixed in kBuild svn.)
152 set -- ${MY_DIRS_PAIRS};
153 while test "$#" -ge 2;
154 do
155 CopyTree "${1}" "${2}"
156 shift 2
157 done
158 fi
159}
160
161#
162# Copy the files over.
163#
164set -e
165MY_SAVED_CWD=`pwd`
166"${MY_MKDIR}" -p ${MY_DEBUG_MKDIR} -- "${MY_DSTDIR}"
167
168# Selected root files.
169"${MY_INSTALL}" ${MY_DEBUG_INSTALL} --hard-link-files-when-possible -m644 -- \
170 "${MY_SRCDIR}/build_template.xml" \
171 "${MY_SRCDIR}/catalog-dita.txt" \
172 "${MY_SRCDIR}/catalog-dita_template.xml" \
173 "${MY_SRCDIR}/integrator.properties" \
174 "${MY_SRCDIR}/integrator.xml" \
175 "${MY_DSTDIR}/"
176
177# Selected directory trees.
178MY_TEMPLATED_FILES=""
179for MY_SUBDIR in css dtd lib plugins resource schema tools xsl;
180do
181 "${MY_MKDIR}" -p ${MY_DEBUG_MKDIR} -- "${MY_DSTDIR}/${MY_SUBDIR}"
182 CopyTree "${MY_SRCDIR}/${MY_SUBDIR}" "${MY_DSTDIR}/${MY_SUBDIR}"
183done
184
185# Now remove all files that has a _template.xml/xsl variant, just to ensure
186# that if hardlinked the copy in the tree won't be modified.
187if test -n "${MY_TEMPLATED_FILES}"; then
188 "${MY_RM}" -f ${MY_DEBUG_RM} -- ${MY_TEMPLATED_FILES}
189fi
190
191cd "${MY_SAVED_CWD}"
192set +e
193
194#
195# Execute the command.
196#
197"$@"
198MY_EXITCODE=$?
199
200#
201# Cleanup and exit.
202#
203#"${MY_RM}" -Rf ${MY_DEBUG_RM} -- "${MY_DSTDIR}"
204exit ${MY_EXITCODE}
205
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette