
-- set up environment -- key directories:

   o  PDSDIR  -- dir with scripts, templates, additional files (MKs, docs), etc

   o  OPSDIR  -- dir with OPS kernels
  
   o  STAGING -- dir where everything is assembled and labels, etc are made

   o  FINAL   -- dir where clean copy of the archive is assembled

   o  FTPDIR  -- dir where archive visible to public resides  

      set PDSDIR  = "/home/bsemenov/maven/pds"
      set OPSDIR  = "/ftp/pub/naif/MAVEN/kernels"
      set STAGING = "/usr1/maven/pds4/staging/maven/maven_spice" 
      set FINAL   = "/usr1/maven/pds4/final/$STAGING:h:t/$STAGING:t"
      set FTPDIR  = "/ftp/pub/naif/pds/pds4/$FINAL:h:t/$FINAL:t"


-- prepare/check all kernels, including

   o  APP rel CKs (mvn_app_rel_??????_??????_v??.bc)

   o  IUVS rem CKs (mvn_iuvs_rem_??????_??????_v??.bc)

   o  SC rel CKs (mvn_sc_rel_??????_??????_v??.bc)

   o  SC pred CKs, if ever decide that they are good enough

   o  SWEA nom CK, if updated

   o  any other kinds of CKs, if present

   o  FKs, if new FKs or new versions are available

   o  IKs, if new IKs or new versions are available

   o  LSK, if new version is available

   o  PCK, if new version is available

   o  SCLK, all new versions since last release

   o  DE or PE SPKs, if new versions are available

   o  SC SPK (next 3 month chunk) 

   o  STRUCT SPK, if new version is available


-- use loops from useful_loops.txt to make plan/list and check kernels


-- make release plan (e.g. $PDSDIR/maven_release_04.plan) 


-- make kernel list w/o MKs (e.g. $PDSDIR/maven_release_04.kernel_list)

   o  use default start/stop tags for all kernels that have unset times in label


-- prepare all MKs under $PDSDIR/spice_kernels/mk

   o   MKs must be loadable from spice_kernels/mk 

   o   kernels listed in MKs must paths in the form ../dir/name


-- add MKs to the plan and kernel list


-- set LIST variable

      set LIST = $PDSDIR/maven_release_13.kernel_list

      echo $LIST


-- copy kernels to staging spice_kernels/*/ subdirectories (see useful_loops)


-- set LSK, SCLK, and FK variables

      set LSK  = `ls -1 $STAGING/spice_kernels/lsk/naif????.tls | tail -1`
      set SCLK = `ls -1 $STAGING/spice_kernels/sclk/mvn_sclkscet_?????.tsc | tail -1`
      set FK   = `ls -1 $STAGING/spice_kernels/fk/maven_v??.tf  | tail -1`

      echo $LSK
      echo $SCLK
      echo $FK


-- check MKs -- since staging area contain complete set of kernels from the current
   archive plus all new ones, all MKs must be loadable (NOTE: check_loaded is a 
   simple exe that loads an MK or a kernel and print KDATA stuff for all loaded 
   kernels to the screen)

      cd $STAGING/spice_kernels/mk 

      foreach FF ( `find . -mtime -10 -name '*.tm' -print` )
         check_loaded $FF | head -10 
      end


-- change to scripts and setups directory (or do this in separate terminal)

      cd $PDSDIR


-- make/update MAKLABEL template, if needed

   o  template must include tags for default start and stop times  

      set TEMPLATE = $PDSDIR/maven_mission_template_pds.1.0

      echo $TEMPLATE


-- make combined FK+LSK for labelling (needed for structures SPK)

      set LSKFK = $PDSDIR/maven_fk_lsk.tf

      cat $LSK $FK  > $LSKFK

      dir $LSKFK


-- change to staging

      cd $STAGING
 
      pwd


-- generate PDS3 labels for this release

      $PDSDIR/label_them_all.pl $TEMPLATE $LSKFK $SCLK $LIST

      dir `find spice_kernels -name '*.lbl' -mtime -1 -print`



-- generate PDS4 labels

      $PDSDIR/make_pds4_prod_labels.csh $LIST $PDSDIR/maven_pds4_values.1.0 $PDSDIR/template_product_spice_kernel.xml -202000 -202


-- visually check MK labels

      dir `find spice_kernels -name '*.xml' -mtime -1 -print`

      foreach FF ( `find spice_kernels/mk -name 'maven_????_v??.tm' -mtime -10 -print` )
         set MKVER = `echo $FF | sed 's/^.*maven_...._v//' | sed 's/\.tm$//' | awk '{printf "%d", $1}'`
         if (  $MKVER > 1 ) then
	    set OLDVER = `echo $MKVER | awk '{printf "%02d", $1-1}'`
            set OLDMK  = `echo $FF | sed 's/_v..\.tm$/_v'$OLDVER'.tm/'`
	    if ( -e $FF:r.xml && -e $OLDMK:r.xml ) then
               echo comparing $FF:r.xml and $OLDMK:r.xml
               tkdiff $FF:r.xml $OLDMK:r.xml
	    else
               echo $FF:r.xml or $OLDMK:r.xml does not exist.
            endif
	    
         endif
      end


-- check that there is a XML label for each file under spice_kernels

      foreach FF ( `ls -1 spice_kernels/*/*.* | grep -vi '\.xml$'` )
         if ( ! -e $FF:r.xml && ! -e $FF:r.XML ) then
            echo NO XML label for $FF
         endif 
      end


-- make complete kernel list file and check it for duplicates

      cat $PDSDIR/maven_release_??.kernel_list > $PDSDIR/maven_complete.kernel_list

      $PDSDIR/check_list_for_dups.csh $PDSDIR/maven_complete.kernel_list


-- make kernels collection label and inventory, visually check against previous 

      $PDSDIR/make_pds4_prod_coll_label.csh $PDSDIR/maven_complete.kernel_list $PDSDIR/maven_pds4_values.1.0 $PDSDIR/template_collection_spice_kernel.xml

      dir -tr spice_kernels/collection_spice_kernels_inventory_v???.csv
      tkdiff `ls -1 spice_kernels/collection_spice_kernels_inventory_v???.csv | tail -2`

      dir -tr spice_kernels/collection_spice_kernels_v???.xml
      tkdiff `ls -1 spice_kernels/collection_spice_kernels_v???.xml | tail -2`


-- make PDS3 index files, keep dsindex and its label and move them one 
   level up -- these are not needed for PDS4 bundle, of course, but might
   eventually be used by the archive subsetter

      $PDSDIR/xfer_index.pl $PDSDIR/maven_complete.kernel_list

      diff dsindex.lbl index.lbl
          
      rm index.tab index.lbl

      add_crs dsindex.tab 
      add_crs dsindex.lbl

      tkdiff dsindex.tab ../dsindex.tab
      tkdiff dsindex.lbl ../dsindex.lbl

      mv dsindex.tab dsindex.lbl ..


-- if needed, make and edit the next version of spiceds_v???.html


-- if needed, add CRs to new spiceds_v???.html

      dir -tr document/spiceds_v???.html
      tkdiff `ls -1 document/spiceds_v???.html | tail -2`


-- if needed, make label for spiceds_v???.html

      $PDSDIR/make_pds4_doc_spiceds_label.csh $PDSDIR/maven_pds4_values.1.0 $PDSDIR/template_product_html_document.xml

      dir -tr document/spiceds_v???.xml
      tkdiff `ls -1 document/spiceds_v???.xml | tail -2`
      

-- if needed, make document collection label and inventory 

      $PDSDIR/make_pds4_doc_coll_label.csh $PDSDIR/maven_pds4_values.1.0 $PDSDIR/template_collection_document.xml

      dir -tr document/collection_document_inventory_v???.csv
      tkdiff `ls -1 document/collection_document_inventory_v???.csv | tail -2`

      dir -tr document/collection_document_v???.xml
      tkdiff `ls -1 document/collection_document_v???.xml | tail -2`


-- if needed, make/update readme.txt


-- if needed, add CRs to readme.txt


-- make bundle label 

      $PDSDIR/make_pds4_bundle_label.csh $PDSDIR/maven_pds4_values.1.0 $PDSDIR/template_bundle.xml

      dir -tr ./bundle_maven_spice_v???.xml
      tkdiff `ls -1 ./bundle_maven_spice_v???.xml | tail -2`


-- DEPLOYMENT STEPS FOR RELEASES AFTER INITIAL RELEASE:

-- overlay new stuff onto bundle in the "final" area 

      set MTIME = "-10"

      dir \
	 `find .               -name '*.xml'  -mtime $MTIME -type f` \
	 `find .               -name '*.txt'  -mtime $MTIME -type f` \
         `find .               -name '*.html' -mtime $MTIME -type f` \
         `find .               -name '*.csv'  -mtime $MTIME -type f` \
         `find ./spice_kernels -name '*.t?'   -mtime $MTIME -type f` \
         `find ./spice_kernels -name '*.t??'  -mtime $MTIME -type f` \
         `find ./spice_kernels -name '*.b?'   -mtime $MTIME -type f` \
         `find ./spice_kernels -name '*.b??'  -mtime $MTIME -type f` \

      tar cBf - \
	 `find .               -name '*.xml'  -mtime $MTIME -type f` \
	 `find .               -name '*.txt'  -mtime $MTIME -type f` \
         `find .               -name '*.html' -mtime $MTIME -type f` \
         `find .               -name '*.csv'  -mtime $MTIME -type f` \
         `find ./spice_kernels -name '*.t?'   -mtime $MTIME -type f` \
         `find ./spice_kernels -name '*.t??'  -mtime $MTIME -type f` \
         `find ./spice_kernels -name '*.b?'   -mtime $MTIME -type f` \
         `find ./spice_kernels -name '*.b??'  -mtime $MTIME -type f` \
            | (cd $FINAL; tar xBf -)

      cp -p ../dsindex.* $FINAL/..


-- in "final" area, add CRs to all new XML labels and check all files for bad chars 

      dir `find $FINAL -name '*.xml' -mtime $MTIME -print | sort`

      foreach FF ( `find $FINAL -name '*.xml' -mtime $MTIME -print | sort` )
         echo adding CRs to $FF ...
         add_crs $FF
      end

      badchar `find $FINAL/.. -type f -print | sort` | grep ' 0$'


-- in "final area", generate checksum table and label 

      cd $FINAL/..

      $PDSDIR/mkpdssum.pl -p $FINAL

      add_crs checksum.tab

      tkdiff checksum.tab $FTPDIR:h/checksum.tab

      cd $STAGING


-- push archive increment to PDS4 area on NAIF:

      rm -fr /ftp/pub/naif/misc/tmp/pds/pds4/$FTPDIR:h:t >& /dev/null

      cp -Rp $FTPDIR:h /ftp/pub/naif/misc/tmp/pds/pds4/

      cd $FINAL

      dir `find . -type f -mtime $MTIME -print | sort`

      tar cBf - \
         `find . -type f -mtime $MTIME -print | sort` \
            | (cd $FTPDIR; tar xBf -)

      cp -p $FINAL/../dsindex.lbl $FINAL/../dsindex.tab $FINAL/../checksum.tab $FTPDIR/..


-- check PDS4 area checksum

      $PDSDIR/chkpdssum.pl -f $FTPDIR/../checksum.tab $FTPDIR

      find $FTPDIR/ -mtime $MTIME -print | sort 


-- run validation tool

      cd $PDSDIR

      source ~/pds/misc/en_tools/set_environment.csh

      validate $FTPDIR -i -r $LIST:r.validate_report

      validate $FTPDIR -i -M $FTPDIR/../checksum.tab -r $LIST:r.validate_report


-- send notification to EN




=========================================================================

-- DEPLOYMENT STEPS FOR INITIAL RELEASE ONLY:

-- overlay stuff onto existing bundle 

      tar cBf - \
         bundle_*_spice_v???.xml \
         readme.txt \
         document/collection_document_inventory_v???.csv \
         document/collection_document_v???.xml \
         document/spiceds_v???.html \
         document/spiceds_v???.xml \
         spice_kernels/collection_spice_kernels_inventory_v???.csv \
         spice_kernels/collection_spice_kernels_v???.xml \
         spice_kernels/*/*.t* \
         spice_kernels/*/*.b* \
         spice_kernels/*/*.xml \
            | (cd $FINAL; tar xBf -)

      cp -p ../dsindex.* $FINAL/..


-- add CRs to all XML labels and check all files for bad chars 

      foreach FF ( `find $FINAL -name '*.xml' -print` )
         echo adding CRs to $FF ...
         add_crs $FF
      end

      badchar `find $FINAL/.. -type f -print` | grep ' 0$'

-- generate checksum table and label for the final

      cd $FINAL/..

      $PDSDIR/mkpdssum.pl -p $FINAL

      cd $STAGING


-- push archive to PDS4 area on NAIF:

      cd $FINAL

      mkdir -p $FTPDIR

      tar cBf - \
         `find . -type f -mtime -1 -print | sort` \
            | (cd $FTPDIR; tar xBf -)

      cp -p $FINAL/../dsindex.lbl $FINAL/../dsindex.tab $FINAL/../checksum.tab $FTPDIR/..


-- check checksums

       $PDSDIR/chkpdssum.pl -f $FTPDIR/../checksum.tab $FTPDIR


End.
