home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1999 March B / SCO_CASTOR4RRT.iso / TEDdesk / reloc.8 / $TED_DIR / bin / dtappintegrate next >
Text File  |  1998-08-19  |  17KB  |  466 lines

  1. #!/usr/dt/bin/dtksh
  2.  
  3. #####################################################################
  4. #                                                                   #
  5. #  dtappintegrate                                                   #
  6. #                                                                   #
  7. #  TriTeal Enterprise Desktop (TED)                                 #
  8. #                                                                   #
  9. #  This is the TED application integration script to assist         #
  10. #  in integrating applications into the TriTeal Desktop.            #
  11. #                                                                   #
  12. #  (c) Copyright 1994  TriTeal Corporation                 #
  13. #  (c) Copyright 1993, 1994 Hewlett-Packard Company                 #
  14. #  (c) Copyright 1993, 1994 International Business Machines Corp.   #
  15. #  (c) Copyright 1993, 1994 Sun Microsystems, Inc.                  #
  16. #  (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of #
  17. #      Novell, Inc.                                                 #
  18. #                                                                   #
  19. #  syntax: dtappintegrate -s <source> [-t <target>] [-l <lang>] [-u]#
  20. #  where                                                            #
  21. #        -s           indicates application's root location.        #
  22. #        source       the path name of the application's root.      #
  23. #        -t           indicates a new location for the              #
  24. #                       application's group files.                  #
  25. #        target       the path name of the target location.         #
  26. #        -l           indicates the language for this application.  #
  27. #        language     the language name as used by $LANG            #
  28. #                       environment variable.                       #
  29. #        -u           indicates to unintegrate the application.     #
  30. #                                                                   #
  31. #                                                                   #
  32. #####################################################################
  33.  
  34. #-------------------------------------------------------------------#
  35. #  ShowSyntax                                                       #
  36. #                                                                   #
  37. #       This routine is used to echo the command line syntax.       #
  38. #                                                                   #
  39. #       input:                                                      #
  40. #         none                                                      #
  41. #                                                                   #
  42. #       return codes:                                               #
  43. #         0   - success                                             #
  44. #                                                                   #
  45. #-------------------------------------------------------------------#
  46. function ShowSyntax
  47. {
  48.   echo "Usage: $SCRIPT_NAME -s <source> [-t <target>] [-l <language>] [-u]" | tee -a $LOGFILE
  49.   return 0
  50. }
  51. #-------------------------------------------------------------------#
  52. #  GetAbsolutePath                                                  #
  53. #                                                                   #
  54. #       This routine is to resolve a path to its actual path,       #
  55. #       following links, etc.                                       #
  56. #                                                                   #
  57. #       input:                                                      #
  58. #         $1 = path                                                 #
  59. #                                                                   #
  60. #       output:                                                     #
  61. #         absolute path                                             #
  62. #                                                                   #
  63. #-------------------------------------------------------------------#
  64. function GetAbsolutePath
  65. {
  66.   if [ "/" = "$1" ]; then
  67.      echo $2
  68.   elif [ -L $1 ]; then
  69.      GetAbsolutePath `ls -l $1 | awk '{print $NF}'` $2
  70.   else
  71.   {
  72.      if [ "." = "$1" -o ".." = "$1" ]; then
  73.         GetAbsolutePath / /`basename $1`$2
  74.      else
  75.         GetAbsolutePath `dirname $1` /`basename $1`$2
  76.      fi
  77.   }
  78.   fi
  79. }
  80. #-------------------------------------------------------------------#
  81. #  GetRelativePath                                                  #
  82. #                                                                   #
  83. #       This routine is used to determine the relative path of      #
  84. #       of the source path from the target path.                    #
  85. #                                                                   #
  86. #       input:                                                      #
  87. #         $1 = absolute source path                                 #
  88. #         $2 = absolute target path                                 #
  89. #                                                                   #
  90. #       return codes:                                               #
  91. #         0   - success                                             #
  92. #         1   - error                                               #
  93. #                                                                   #
  94. #-------------------------------------------------------------------#
  95. function GetRelativePath
  96. {
  97.   $AWK 'BEGIN {
  98.           src = ARGV[1]
  99.           dest = ARGV[2]
  100.           a = split(src, A, "/");
  101.           b = split(dest, B, "/");
  102.  
  103.           s = 0;
  104.            for (i = 2; i < a && i < b; i++) {
  105.  
  106.              if (A[i] == B[i]) {
  107.  
  108.                 ++s;
  109.              } else {
  110.                 break;
  111.              }
  112.            }
  113.           for (i = 0 ; i <= (a - s - 2); i++) {
  114.              printf("../")
  115.           }
  116.           for (i = 2 + s; i <= b; i++) {
  117.              printf("%s%s", B[i], (i < b) ? "/":"\n");
  118.           }
  119.   }' $2 $1
  120. }
  121. #-------------------------------------------------------------------#
  122. #  LinkCfgs                                                         #
  123. #                                                                   #
  124. #       This routine creates the actual links from the application's#
  125. #       root config files to the target location.                   #
  126. #                                                                   #
  127. #       input:                                                      #
  128. #                                                                   #
  129. #       return codes:                                               #
  130. #         n   - number of files integrated or unintegrated          #
  131. #                                                                   #
  132. #-------------------------------------------------------------------#
  133. function LinkCfgs
  134. {
  135.   typeset source=$1 target=$2 torf=$3 spath="" tpath="" cfgfile="" rpath=""
  136.   typeset pattern="" files=""
  137.  
  138.   shift;shift;shift
  139.   if [[ -L $source || -L $(dirname $source) ]] then
  140.     spath=$(GetAbsolutePath $source)
  141.   else
  142.     spath=$source
  143.   fi
  144.   if [[ -L $target || -L $(dirname $target) ]] then
  145.     tpath=$(GetAbsolutePath $target)
  146.   else
  147.     tpath=$target
  148.   fi
  149.   rpath=""
  150.   for pattern in "$@"
  151.   do
  152.     if [[ $pattern = "ALLFILES" ]] then
  153.       files=$(find $source -name "*" -type f  -print)
  154.     else
  155.       files=$(find $source -name "*.$pattern" -type f -print)
  156.     fi
  157.     if [[ $? = 0 ]] then
  158.       count=$(echo $files | wc -w)
  159.       for cfgfile in $files
  160.       do
  161.         basecfg=$(basename $cfgfile)
  162.         if [[ $torf = TRUE ]] then
  163.           if [[ $rpath = "" ]] then
  164.             rpath=$(GetRelativePath $spath $tpath)
  165.           fi
  166.           rm -f $tpath/$basecfg
  167.           echo "ln -sf $rpath/$basecfg $tpath/$basecfg" >> $LOGFILE
  168.           ln -sf $rpath/$basecfg $tpath/$basecfg >> $LOGFILE 2>&1
  169.         else
  170.           rm $tpath/$basecfg >/dev/null 2>&1
  171.           if [[ $? = 0 ]] then
  172.             echo "rm $tpath/$basecfg" >> $LOGFILE
  173.           fi
  174.         fi
  175.       done
  176.     fi
  177.   done
  178.   return $count
  179. }
  180.  
  181. #-------------------------------------------------------------------#
  182. #  IntegrateUnintegrate                                             #
  183. #                                                                   #
  184. #       This routine integrates the files into the cose desktop     #
  185. #       environment or unintegrates them depending on the boolean   #
  186. #       input parameter.                                            #
  187. #                                                                   #
  188. #       input:                                                      #
  189. #         $1 = Integrate or not. TRUE=integrate. FALSE=unintegrate. #
  190. #                                                                   #
  191. #       return codes:                                               #
  192. #         0   - work was done                                       #
  193. #         1   - no work done                                        #
  194. #                                                                   #
  195. #-------------------------------------------------------------------#
  196. function IntegrateUnintegrate
  197. {
  198.   typeset torf=$1 srcs="" trgs="" fpats="" langs="" tpath="" spath="" rpath="" k="" languages="" lang=""
  199.   typeset cfgs="" srcabs="" trgabs=""
  200.   integer i=0 icons=0 types=1 help=2 appmgr=3
  201.  
  202.   srcabs=$(GetAbsolutePath $APP_ROOT)
  203.   trgabs=$(GetAbsolutePath $APP_TARGET)
  204.  
  205.   srcs[0]=$srcabs$ICONS$APP_LANG
  206.   srcs[1]=$srcabs$TYPES$APP_LANG
  207.   srcs[2]=$srcabs$HELP$APP_LANG
  208.   srcs[3]=$srcabs$APPMANAGER$APP_LANG
  209.  
  210.   trgs[0]=$trgabs$ICONS$APP_LANG
  211.   trgs[1]=$trgabs$TYPES$APP_LANG
  212.   trgs[2]=$trgabs$HELP$APP_LANG
  213.   trgs[3]=$trgabs$APPMANAGER$APP_LANG
  214.  
  215.   fpats[0]="$PIXMAP_FILES $BITMAP_FILES"
  216.   fpats[1]="$ACTIONDB_FILES"
  217.   fpats[2]="$HELPVOLUME_FILES_OLD $HELPVOLUME_FILES_NEW $HELPFAMILY_FILES"
  218.   fpats[3]="$APPMAN_FILES"
  219.  
  220.   rc=1
  221.   while (( i < 4 ))
  222.   do
  223.     if [[ $APP_LANG = "" ]] then
  224.       languages=$(ls -d ${srcs[i]}/* 2>/dev/null)
  225.       if [[ $? = 0 ]] then
  226.         for lang in $languages
  227.         do
  228.           baselang=$(basename $lang)
  229.           if [[ -d $lang ]] then
  230.             if [[ $torf = TRUE ]] then
  231.               if [[ ! -d ${trgs[i]}/$baselang ]] then
  232.                 mkdir -p ${trgs[i]}/$baselang
  233.               fi
  234.             fi
  235.             LinkCfgs ${srcs[i]}/$baselang ${trgs[i]}/$baselang $torf ${fpats[i]}
  236.             if [[ $? != 0 ]] then
  237.               rc=0
  238.             fi
  239.           fi
  240.         done
  241.       fi
  242.     else
  243.       LinkCfgs ${srcs[i]} ${trgs[i]} $torf ${fpats[i]}
  244.       if [[ $? != 0 ]] then
  245.         rc=0
  246.       fi
  247.     fi
  248.     i=i+1
  249.   done
  250.   return $rc
  251. }
  252. #-------------------------------------------------------------------#
  253. #  ExitOut                                                          #
  254. #                                                                   #
  255. #       Exit the program.                                           #
  256. #                                                                   #
  257. #       input:                                                      #
  258. #         $1 = return code                                          #
  259. #                                                                   #
  260. #-------------------------------------------------------------------#
  261. function ExitOut
  262. {
  263.   typeset retcode=$1
  264.   echo "<<<<<<< END  OF  APPLICATION INTEGRATION >>>>>>>" >> $LOGFILE
  265.  
  266.   echo "See $LOGFILE file for more information"
  267.   exit $retcode
  268. }
  269. #  ----<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>-----
  270. #  ----<<<<<<<<<<<.-------------------------.>>>>>>>>>>>-----
  271. #  ----<<<<<<<<<<<|                         |>>>>>>>>>>>-----
  272. #  ----<<<<<<<<<<<|  START OF MAIN ROUTINE  |>>>>>>>>>>>>-----
  273. #  ----<<<<<<<<<<<|_________________________|>>>>>>>>>>>-----
  274. #  ----<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>-----
  275.  
  276. #--------------------------------------------------------------------
  277. #  Initialize variables
  278. #--------------------------------------------------------------------
  279. sFLAG=0
  280. tFLAG=0
  281. lFLAG=0
  282. uFLAG=0
  283.  
  284. TYPES=/types
  285. APPMANAGER=/appmanager
  286. ICONS=/icons
  287. HELP=/help
  288. APPCONFIG=/dt/appconfig
  289. CONFIG_TOP=/etc/dt
  290. DT=`basename $CONFIG_TOP`
  291. APP_TARGET=${CONFIG_TOP%/$DT}$APPCONFIG
  292.  
  293. PIXMAP_FILES=pm
  294. BITMAP_FILES=bm
  295. HELPVOLUME_FILES_OLD=hv
  296. HELPVOLUME_FILES_NEW=sdl
  297. HELPFAMILY_FILES=hf
  298. ACTIONDB_FILES=dt
  299. FRONTPANEL_FILES=fp
  300. APPMAN_FILES=ALLFILES
  301.  
  302. ID=$(id)
  303. LOGFILE=/tmp/dtappint.log
  304.  
  305. PATH=/usr/dt/bin:$PATH
  306.  
  307.  
  308. #--------------------------------------------------------------------
  309. #  Save application's name in variable.
  310. #--------------------------------------------------------------------
  311. SCRIPT_NAME=$0
  312.  
  313. #--------------------------------------------------------------------
  314. #  Check if root user.  Exit if not.
  315. #--------------------------------------------------------------------
  316. ID=${ID##*uid=}
  317. ID=${ID#*\(}
  318. ID=${ID%%\)*}
  319. if [[ $ID != root ]] then
  320.    echo "Error: Must be root user to run $0!" >&2
  321.    exit 3
  322. fi
  323.  
  324. #--------------------------------------------------------------------
  325. #  Put prolog into log file.
  326. #--------------------------------------------------------------------
  327. echo "<<<<<<< START OF APPLICATION INTEGRATION >>>>>>>" > $LOGFILE
  328.  
  329. #--------------------------------------------------------------------
  330. #  Put the date of application integration into the log file.
  331. #--------------------------------------------------------------------
  332. echo $(date) >> $LOGFILE
  333.  
  334. #--------------------------------------------------------------------
  335. #  Put the command line into the log file.
  336. #--------------------------------------------------------------------
  337. echo "$SCRIPT_NAME $*" >> $LOGFILE
  338.  
  339. #--------------------------------------------------------------------
  340. #  Check if there are no command line arguments.
  341. #  If none, then display the command syntax.
  342. #--------------------------------------------------------------------
  343. if [[ $# = 0 ]] then
  344.   ShowSyntax
  345.   ExitOut 0
  346. fi
  347.  
  348. #--------------------------------------------------------------------
  349. #  Parse the command line into flags and variables.
  350. #--------------------------------------------------------------------
  351. while getopts s:t:l:u  flag
  352. do
  353.   case $flag in
  354.      s)   sFLAG=1
  355.           APP_ROOT="$OPTARG";;
  356.      t)   tFLAG=1
  357.           APP_TARGET="$OPTARG";;
  358.      l)   lFLAG=1
  359.           APP_LANG="$OPTARG";;
  360.      u)   uFLAG=1;;
  361.      ?)   echo " "
  362.           ShowSyntax
  363.           ExitOut 2;;
  364.   esac
  365. done
  366.  
  367. #--------------------------------------------------------------------
  368. #  Check if application's root was specified and is valid.
  369. #--------------------------------------------------------------------
  370. if [[ $sFLAG = 0 ]] then
  371.   echo "Error: Did not specify -s option!" >&2
  372.   ExitOut 4
  373. else
  374.   if [[ ! -d $APP_ROOT ]] then
  375.     APP_PATH=$APP_ROOT
  376.     echo "Error: $APP_PATH is not a directory!" >&2
  377.     ExitOut 4
  378.   fi
  379.   if [[ ! -r $APP_ROOT ]] || [[ ! -x $APP_ROOT ]] then
  380.     APP_PATH=$APP_ROOT
  381.     echo "Error: Can not read $APP_PATH directory!" >&2
  382.     ExitOut 4
  383.   fi
  384. fi
  385.  
  386. if [[ ${APP_ROOT%%/*} != "" ]] then
  387.   APP_ROOT=$(pwd)/$APP_ROOT
  388. fi
  389.  
  390. #--------------------------------------------------------------------
  391. #  If target is specified, do some sanity checks on this path.
  392. #--------------------------------------------------------------------
  393. if [[ $tFLAG = 1 ]] then
  394.   if [[ ! -d $APP_TARGET ]] then
  395.     APP_PATH=$APP_TARGET
  396.     echo "Error: $APP_PATH is not a directory!" >&2
  397.     ExitOut 4
  398.   fi
  399.   if [[ ! -r $APP_TARGET ]] || [[ ! -x $APP_TARGET ]] then
  400.     APP_PATH=$APP_TARGET
  401.     echo "Error: Can not read $APP_PATH directory!" >&2
  402.     ExitOut 4
  403.   fi
  404.  
  405.   if [[ ${APP_TARGET%%/*} != "" ]] then
  406.     APP_TARGET=$(pwd)/$APP_TARGET
  407.   fi
  408. fi
  409.  
  410. #--------------------------------------------------------------------
  411. #  Set up variables.
  412. #--------------------------------------------------------------------
  413. APP_ROOT=$APP_ROOT$APPCONFIG
  414.  
  415. if [[ $APP_LANG != "" ]] then
  416.   APP_LANG=/$APP_LANG
  417. fi
  418.  
  419. #--------------------------------------------------------------------
  420. #  Unintegrate the application by un-doing the integration steps.
  421. #--------------------------------------------------------------------
  422. if [[ $uFLAG = 1 ]] then
  423.   IntegrateUnintegrate FALSE
  424.   if [[ $? = 0 ]] then
  425.     echo "Unintegration Complete"
  426.   else
  427.     echo "No files to unintegrate"
  428.   fi
  429.   ExitOut 0
  430. fi
  431.  
  432. #--------------------------------------------------------------------
  433. #  See if these directories exist.  If they don't, then create them.
  434. #--------------------------------------------------------------------
  435. for i in $APP_TARGET$ICONS$APP_LANG $APP_TARGET$TYPES$APP_LANG $APP_TARGET$APPMANAGER$APP_LANG $APP_TARGET$HELP$APP_LANG
  436.  do
  437.   if [[ ! -d $i ]] then
  438.     mkdir -p $i
  439.   fi
  440.  done
  441.  
  442. #--------------------------------------------------------------------
  443. #  Determine which awk to use.
  444. #--------------------------------------------------------------------
  445. $(type nawk > /dev/null 2>&1)
  446. if [[ $? != 0 ]] then
  447.   AWK="awk"
  448. else
  449.   AWK="nawk"
  450. fi
  451.  
  452. #--------------------------------------------------------------------
  453. #  Integrate the application.
  454. #--------------------------------------------------------------------
  455. IntegrateUnintegrate TRUE
  456. if [[ $? = 0 ]] then
  457.   echo "Integration Complete"
  458. else
  459.   echo "No files to integrate"
  460. fi
  461.  
  462. #--------------------------------------------------------------------
  463. #  Exit
  464. #--------------------------------------------------------------------
  465. ExitOut 0
  466.