2 XCOMM $XConsortium: dtappintegrate.src /main/4 1996/04/21 19:27:37 drk $
4 XCOMM ###################################################################
8 XCOMM (c) Copyright 1996 Digital Equipment Corporation. #
9 XCOMM (c) Copyright 1993,1994,1996 Hewlett-Packard Company. #
10 XCOMM (c) Copyright 1993,1994,1996 International Business Machines Corp.#
11 XCOMM (c) Copyright 1993,1994,1996 Sun Microsystems, Inc. #
12 XCOMM (c) Copyright 1996 Novell, Inc. #
13 XCOMM (c) Copyright 1996 FUJITSU LIMITED. #
14 XCOMM (c) Copyright 1996 Hitachi. #
15 XCOMM (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of #
18 XCOMM This is the dt application integration script to assist #
19 XCOMM in integrating applications into COSE Desktop Environment. #
21 XCOMM syntax: dtappintegrate -s <source> [-t <target>] [-l <lang>] [-u]#
23 XCOMM -s indicates application's root location. #
24 XCOMM source the path name of the application's root. #
25 XCOMM -t indicates a new location for the #
26 XCOMM application's group files. #
27 XCOMM target the path name of the target location. #
28 XCOMM -l indicates the language for this application. #
29 XCOMM language the language name as used by $LANG #
30 XCOMM environment variable. #
31 XCOMM -u indicates to unintegrate the application. #
34 XCOMM ###################################################################
36 XCOMM ------------------------------------------------------------------#
39 XCOMM This routine is used to echo the command line syntax. #
47 XCOMM ------------------------------------------------------------------#
50 echo "Usage: $SCRIPT_NAME -s <source> [-t <target>] [-l <language>] [-u]" | tee -a "$LOGFILE"
53 XCOMM ------------------------------------------------------------------#
54 XCOMM GetAbsolutePath #
56 XCOMM This routine is to resolve a path to its actual path, #
57 XCOMM following links, etc. #
65 XCOMM ------------------------------------------------------------------#
66 function GetAbsolutePath
68 if [ "/" = "$1" ]; then
70 elif [ -L "$1" ]; then
71 GetAbsolutePath "$(find . -name "$1" | awk '{print $NF}')" "$2"
74 if [ "." = "$1" ] || [ ".." = "$1" ]; then
75 GetAbsolutePath / /"$(basename "$1")""$2"
77 GetAbsolutePath "$(dirname "$1")" /"$(basename "$1")""$2"
82 XCOMM ------------------------------------------------------------------#
83 XCOMM GetRelativePath #
85 XCOMM This routine is used to determine the relative path of #
86 XCOMM of the source path from the target path. #
89 XCOMM $1 = absolute source path #
90 XCOMM $2 = absolute target path #
96 XCOMM ------------------------------------------------------------------#
97 function GetRelativePath
102 a = split(src, A, "/");
103 b = split(dest, B, "/");
106 for (i = 2; i < a && i < b; i++) {
107 if (match(A[i],B[i])) {
113 for (i = 0 ; i <= (a - s - 2); i++) {
116 for (i = 2 + s; i <= b; i++) {
117 printf("%s%s", B[i], (i < b) ? "/":"\n");
121 XCOMM ------------------------------------------------------------------#
124 XCOMM This routine creates the actual links from the application's#
125 XCOMM root config files to the target location. #
129 XCOMM return codes: #
130 XCOMM n - number of files integrated or unintegrated #
132 XCOMM ------------------------------------------------------------------#
135 typeset source=$1 target=$2 torf=$3 spath="" tpath="" cfgfile="" rpath=""
136 typeset pattern="" files=""
139 if [[ -L $source || -L $(dirname "$source") ]]
141 spath=$(GetAbsolutePath "$source")
145 if [[ -L $target || -L $(dirname "$target") ]]
147 tpath=$(GetAbsolutePath "$target")
154 if [[ $pattern = "(*)" ]]
156 files=$(ls -d "$source"/COMMENT_STAR 2>/dev/null)
158 files=$(ls -d "$source"/"$pattern" 2>/dev/null)
162 count=$(echo "$files" | wc -w)
163 for cfgfile in $files
165 basecfg=$(basename "$cfgfile")
166 if [[ $torf = TRUE ]]
170 rpath=$(GetRelativePath "$spath" "$tpath")
172 rm -f "$tpath"/"$basecfg"
173 echo "ln -sf $rpath/$basecfg $tpath/$basecfg" >> "$LOGFILE"
174 ln -sf "$rpath/$basecfg" "$tpath/$basecfg" >> "$LOGFILE" 2>&1
176 if rm "$tpath"/"$basecfg" >/dev/null 2>&1
178 echo "rm $tpath/$basecfg" >> "$LOGFILE"
187 XCOMM ------------------------------------------------------------------#
188 XCOMM IntegrateUnintegrate #
190 XCOMM This routine integrates the files into the cose desktop #
191 XCOMM environment or unintegrates them depending on the boolean #
192 XCOMM input parameter. #
195 XCOMM $1 = Integrate or not. TRUE=integrate. FALSE=unintegrate. #
197 XCOMM return codes: #
198 XCOMM 0 - work was done #
199 XCOMM 1 - no work done #
201 XCOMM ------------------------------------------------------------------#
202 function IntegrateUnintegrate
204 typeset torf=$1 srcs="" trgs="" fpats="" tpath="" spath="" rpath="" languages="" lang=""
205 typeset srcabs="" trgabs=""
206 integer i=0 icons=0 types=1 help=2 appmgr=3
208 srcabs=$(GetAbsolutePath "$APP_ROOT")
209 trgabs=$(GetAbsolutePath "$APP_TARGET")
211 srcs[0]=$srcabs$ICONS$APP_LANG
212 srcs[1]=$srcabs$TYPES$APP_LANG
213 srcs[2]=$srcabs$HELP$APP_LANG
214 srcs[3]=$srcabs$APPMANAGER$APP_LANG
216 trgs[0]=$trgabs$ICONS$APP_LANG
217 trgs[1]=$trgabs$TYPES$APP_LANG
218 trgs[2]=$trgabs$HELP$APP_LANG
219 trgs[3]=$trgabs$APPMANAGER$APP_LANG
221 fpats[0]="$PIXMAP_FILES $BITMAP_FILES"
222 fpats[1]="$ACTIONDB_FILES"
223 fpats[2]="$HELPVOLUME_FILES_OLD $HELPVOLUME_FILES_NEW $HELPFAMILY_FILES"
224 fpats[3]="$APPMAN_FILES"
229 if [[ $APP_LANG = "" ]]
231 if languages=$(ls -d "${srcs[i]}"/COMMENT_STAR 2>/dev/null)
233 for lang in $languages
235 baselang=$(basename "$lang")
238 if [[ $torf = TRUE ]]
240 if [[ ! -d ${trgs[i]}/$baselang ]]
242 mkdir -p "${trgs[i]}"/"$baselang"
245 if ! LinkCfgs "${srcs[i]}/$baselang" "${trgs[i]}/$baselang" "$torf" "${fpats[i]}"
253 if ! LinkCfgs "${srcs[i]}" "${trgs[i]}" "$torf" "${fpats[i]}"
262 XCOMM ------------------------------------------------------------------#
265 XCOMM Exit the program. #
268 XCOMM $1 = return code #
270 XCOMM ------------------------------------------------------------------#
274 echo "<<<<<<< END OF APPLICATION INTEGRATION >>>>>>>" >> "$LOGFILE"
276 echo "See $LOGFILE file for more information"
279 XCOMM ----<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>-----
280 XCOMM ----<<<<<<<<<<<.-------------------------.>>>>>>>>>>>-----
281 XCOMM ----<<<<<<<<<<<| |>>>>>>>>>>>-----
282 XCOMM ----<<<<<<<<<<<| START OF MAIN ROUTINE |>>>>>>>>>>>>-----
283 XCOMM ----<<<<<<<<<<<|_________________________|>>>>>>>>>>>-----
284 XCOMM ----<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>-----
286 XCOMM -------------------------------------------------------------------
287 XCOMM Initialize variables
288 XCOMM -------------------------------------------------------------------
294 APPMANAGER=/appmanager
297 APPCONFIG=/dt/appconfig
298 CONFIG_TOP=CDE_CONFIGURATION_TOP
299 DT=$(basename $CONFIG_TOP)
300 APP_TARGET=${CONFIG_TOP%/$DT}$APPCONFIG
304 HELPVOLUME_FILES_OLD="*.hv"
305 HELPVOLUME_FILES_NEW="*.sdl"
306 HELPFAMILY_FILES="*.hf"
307 ACTIONDB_FILES="*.dt"
311 LOGFILE=$(mktemp /tmp/dtappint.logXXXXXXXXXXXXXXXX)
312 PATH=CDE_INSTALLATION_TOP/bin:/usr/bin:/bin
314 XCOMM -------------------------------------------------------------------
315 XCOMM Save application's name in variable.
316 XCOMM -------------------------------------------------------------------
319 XCOMM -------------------------------------------------------------------
320 XCOMM Check if root user. Exit if not.
321 XCOMM -------------------------------------------------------------------
327 echo "Error: Must be root user to run $0!" >&2
331 XCOMM -------------------------------------------------------------------
332 XCOMM Put prolog into log file.
333 XCOMM -------------------------------------------------------------------
334 echo "<<<<<<< START OF APPLICATION INTEGRATION >>>>>>>" > "$LOGFILE"
336 XCOMM -------------------------------------------------------------------
337 XCOMM Put the date of application integration into the log file.
338 XCOMM -------------------------------------------------------------------
341 XCOMM -------------------------------------------------------------------
342 XCOMM Put the command line into the log file.
343 XCOMM -------------------------------------------------------------------
344 echo "$SCRIPT_NAME $*" >> "$LOGFILE"
346 XCOMM -------------------------------------------------------------------
347 XCOMM Check if there are no command line arguments.
348 XCOMM If none, then display the command syntax.
349 XCOMM -------------------------------------------------------------------
356 XCOMM -------------------------------------------------------------------
357 XCOMM Parse the command line into flags and variables.
358 XCOMM -------------------------------------------------------------------
359 while getopts s:t:l:u flag
365 APP_TARGET="$OPTARG";;
366 l) APP_LANG="$OPTARG";;
374 XCOMM -------------------------------------------------------------------
375 XCOMM Check if application's root was specified and is valid.
376 XCOMM -------------------------------------------------------------------
379 echo "Error: Did not specify -s option!" >&2
382 if [[ ! -d $APP_ROOT ]]
385 echo "Error: $APP_PATH is not a directory!" >&2
388 if [[ ! -r $APP_ROOT ]] || [[ ! -x $APP_ROOT ]]
391 echo "Error: Can not read $APP_PATH directory!" >&2
396 if [[ ${APP_ROOT%%/COMMENT_STAR} != "" ]]
398 APP_ROOT=$(pwd)/$APP_ROOT
401 XCOMM -------------------------------------------------------------------
402 XCOMM If target is specified, do some sanity checks on this path.
403 XCOMM -------------------------------------------------------------------
406 if [[ ! -d $APP_TARGET ]]
409 echo "Error: $APP_PATH is not a directory!" >&2
412 if [[ ! -r $APP_TARGET ]] || [[ ! -x $APP_TARGET ]]
415 echo "Error: Can not read $APP_PATH directory!" >&2
419 if [[ ${APP_TARGET%%/COMMENT_STAR} != "" ]]
421 APP_TARGET=$(pwd)/$APP_TARGET
425 XCOMM -------------------------------------------------------------------
426 XCOMM Set up variables.
427 XCOMM -------------------------------------------------------------------
428 APP_ROOT=$APP_ROOT$APPCONFIG
430 if [[ $APP_LANG != "" ]]
435 XCOMM -------------------------------------------------------------------
436 XCOMM Unintegrate the application by un-doing the integration steps.
437 XCOMM -------------------------------------------------------------------
440 if IntegrateUnintegrate FALSE
442 echo "Unintegration Complete"
444 echo "No files to unintegrate"
449 XCOMM -------------------------------------------------------------------
450 XCOMM See if these directories exist. If they don't, then create them.
451 XCOMM -------------------------------------------------------------------
452 for i in $APP_TARGET$ICONS$APP_LANG $APP_TARGET$TYPES$APP_LANG $APP_TARGET$APPMANAGER$APP_LANG $APP_TARGET$HELP$APP_LANG
460 XCOMM -------------------------------------------------------------------
461 XCOMM Determine which awk to use.
462 XCOMM -------------------------------------------------------------------
463 if ! type nawk > /dev/null 2>&1
470 XCOMM -------------------------------------------------------------------
471 XCOMM Integrate the application.
472 XCOMM -------------------------------------------------------------------
473 if IntegrateUnintegrate TRUE
475 echo "Integration Complete"
477 echo "No files to integrate"
480 XCOMM -------------------------------------------------------------------
482 XCOMM -------------------------------------------------------------------