| 1 | 
jmc | 
1.1 | 
#! /usr/bin/env bash | 
| 2 | 
  | 
  | 
 | 
| 3 | 
jmc | 
1.11 | 
# $Header: /u/gcmpack/mitgcm.org/scripts/mk_git_tarfile,v 1.10 2018/05/05 16:27:10 jmc Exp $ | 
| 4 | 
jmc | 
1.1 | 
 | 
| 5 | 
  | 
  | 
# download the source code from github and make a tar file | 
| 6 | 
jmc | 
1.6 | 
  git_repo='MITgcm';  git_code='MITgcm' | 
| 7 | 
  | 
  | 
# git_repo='altMITgcm'; #git_code='MITgcm66h' | 
| 8 | 
jmc | 
1.4 | 
tmpFil="/tmp/"`basename $0`".$$" | 
| 9 | 
jmc | 
1.1 | 
 | 
| 10 | 
  | 
  | 
umask 0002 | 
| 11 | 
  | 
  | 
 | 
| 12 | 
jmc | 
1.4 | 
echo 'Changing dir. to /u/u0/httpd/html/download/git_snapshot' | 
| 13 | 
  | 
  | 
cd /u/u0/httpd/html/download/git_snapshot | 
| 14 | 
jmc | 
1.1 | 
outp=$? | 
| 15 | 
  | 
  | 
if test $outp != 0 ; then | 
| 16 | 
  | 
  | 
   echo " Error in cd : $outp" | 
| 17 | 
jmc | 
1.4 | 
   exit 1 | 
| 18 | 
jmc | 
1.1 | 
fi | 
| 19 | 
jmc | 
1.6 | 
test -e $git_code && rm -rf $git_code | 
| 20 | 
jmc | 
1.1 | 
 | 
| 21 | 
jmc | 
1.6 | 
echo "Make a clone of $git_code from repo: $git_repo ..." | 
| 22 | 
  | 
  | 
#git clone --depth 1 https://github.com/$git_repo/$git_code.git 2> $tmpFil | 
| 23 | 
  | 
  | 
 git clone https://github.com/$git_repo/$git_code.git 2> $tmpFil | 
| 24 | 
jmc | 
1.4 | 
outp=$? | 
| 25 | 
  | 
  | 
if test $outp = 0 ; then | 
| 26 | 
  | 
  | 
   echo ' --> done!' | 
| 27 | 
  | 
  | 
   rm -f $tmpFil | 
| 28 | 
  | 
  | 
else | 
| 29 | 
  | 
  | 
   echo " Error: 'git clone' returned: $outp" | 
| 30 | 
  | 
  | 
   cat $tmpFil | 
| 31 | 
  | 
  | 
   rm -f $tmpFil | 
| 32 | 
  | 
  | 
   exit 2 | 
| 33 | 
  | 
  | 
fi | 
| 34 | 
jmc | 
1.6 | 
#  chgrp gcmpack $git_code | 
| 35 | 
  | 
  | 
   chmod 775 $git_code | 
| 36 | 
jmc | 
1.1 | 
 | 
| 37 | 
  | 
  | 
arName='MITgcm_ss_'`date +%Y%m%d`'.tar' | 
| 38 | 
jmc | 
1.11 | 
fixName=MITgcm_today_snapshot.tar.gz | 
| 39 | 
  | 
  | 
rm -rf MITgcm_ss_* $fixName | 
| 40 | 
jmc | 
1.4 | 
 | 
| 41 | 
  | 
  | 
echo -n 'Creating the archive file ... ' | 
| 42 | 
jmc | 
1.6 | 
( cd $git_code ; git archive --prefix MITgcm/ -o ../$arName master ) | 
| 43 | 
jmc | 
1.11 | 
 gzip -9 $arName | 
| 44 | 
jmc | 
1.4 | 
#- should check if successful, it not -> exit 3 | 
| 45 | 
jmc | 
1.11 | 
if test -e ${arName}.gz ; then | 
| 46 | 
  | 
  | 
   echo 'Done!' | 
| 47 | 
  | 
  | 
  #chmod 664 ${arName}.gz | 
| 48 | 
  | 
  | 
   ls -l ${arName}* | tee -a $HOME/testing/logs/tar_file_list | 
| 49 | 
  | 
  | 
#- make a link to a fixed name: | 
| 50 | 
  | 
  | 
   ln -s ${arName}.gz $fixName | 
| 51 | 
  | 
  | 
   ls -l $fixName | 
| 52 | 
  | 
  | 
else | 
| 53 | 
  | 
  | 
   echo 'Fail: no gzip archive file!' | 
| 54 | 
  | 
  | 
   ls -l ${arName}* | 
| 55 | 
  | 
  | 
   exit 3 | 
| 56 | 
  | 
  | 
fi | 
| 57 | 
jmc | 
1.1 | 
 | 
| 58 | 
jmc | 
1.6 | 
#exit | 
| 59 | 
  | 
  | 
backupDir="other_checkpoints" | 
| 60 | 
jmc | 
1.7 | 
if test ! -d ../$backupDir ; then | 
| 61 | 
jmc | 
1.6 | 
  echo -n " make dir: $backupDir" | 
| 62 | 
  | 
  | 
  mkdir ../$backupDir | 
| 63 | 
  | 
  | 
  outp=$? | 
| 64 | 
  | 
  | 
  if test $outp != 0 ; then | 
| 65 | 
  | 
  | 
     echo " Error in mkdir command: $outp" | 
| 66 | 
  | 
  | 
     exit 4 | 
| 67 | 
  | 
  | 
  else | 
| 68 | 
  | 
  | 
     echo " Done" | 
| 69 | 
  | 
  | 
     ls -ld ../$backupDir | 
| 70 | 
  | 
  | 
  fi | 
| 71 | 
jmc | 
1.7 | 
#else | 
| 72 | 
  | 
  | 
# ls -ld ../$backupDir | 
| 73 | 
jmc | 
1.6 | 
fi | 
| 74 | 
  | 
  | 
 | 
| 75 | 
  | 
  | 
savRepo="${git_code}_git" | 
| 76 | 
  | 
  | 
echo -n 'Make a tar file of the full git repo ...' | 
| 77 | 
  | 
  | 
  test -e $savRepo.tar    && mv -f $savRepo.tar    ../$backupDir | 
| 78 | 
  | 
  | 
  test -e $savRepo.tar.gz && mv -f $savRepo.tar.gz ../$backupDir | 
| 79 | 
  | 
  | 
  tar -cf $savRepo.tar $git_code | 
| 80 | 
  | 
  | 
  gzip -9 $savRepo.tar | 
| 81 | 
  | 
  | 
#- should check if successful, it not -> exit 5 | 
| 82 | 
  | 
  | 
echo ' Done !' | 
| 83 | 
  | 
  | 
ls -l ${savRepo}* | 
| 84 | 
jmc | 
1.1 | 
 | 
| 85 | 
  | 
  | 
#-- test for new checkpoint | 
| 86 | 
jmc | 
1.10 | 
 version_file="$git_code/doc/tag-index" | 
| 87 | 
  | 
  | 
#version_file="$git_code/.git/config" | 
| 88 | 
jmc | 
1.1 | 
if test -f $version_file ; then | 
| 89 | 
jmc | 
1.6 | 
  thischkpt=`awk '/^checkpoint/{print $1; exit}' $version_file` | 
| 90 | 
jmc | 
1.10 | 
 #- better way to get latest tag ( but only works with git version 2 ) | 
| 91 | 
  | 
  | 
 #thischkpt=`(cd $git_code ; git tag -l --sort=-authordate | head -n 1 )` | 
| 92 | 
jmc | 
1.6 | 
  short=`echo $thischkpt | sed 's/checkpoint/c/'` | 
| 93 | 
jmc | 
1.8 | 
  chkptar="MITgcm_${short}.tar" | 
| 94 | 
  | 
  | 
  if test -f ../$chkptar.gz ; then | 
| 95 | 
jmc | 
1.6 | 
    echo "tar file ($chkptar) exist for current tag: $thischkpt" | 
| 96 | 
  | 
  | 
  else | 
| 97 | 
jmc | 
1.8 | 
    echo -n 'Creating the checkpoint archive file ... ' | 
| 98 | 
jmc | 
1.6 | 
    ( cd $git_code ; git archive --prefix MITgcm/ -o ../$chkptar $thischkpt ) | 
| 99 | 
  | 
  | 
    outp=$? | 
| 100 | 
  | 
  | 
    if test $outp != 0 ; then | 
| 101 | 
  | 
  | 
       echo " Error in 'git archive' command: $outp" | 
| 102 | 
  | 
  | 
       exit 5 | 
| 103 | 
jmc | 
1.1 | 
    else | 
| 104 | 
jmc | 
1.6 | 
       echo " Done" | 
| 105 | 
  | 
  | 
    fi | 
| 106 | 
jmc | 
1.8 | 
    gzip -9 $chkptar | 
| 107 | 
  | 
  | 
    ls -l ${chkptar}* | 
| 108 | 
  | 
  | 
    mv $chkptar.gz .. | 
| 109 | 
  | 
  | 
  #-- move previous tar file to backupDir | 
| 110 | 
jmc | 
1.6 | 
    cd .. | 
| 111 | 
  | 
  | 
    listTar=`ls MITgcm_c*.tar.gz` | 
| 112 | 
  | 
  | 
    for xx in $listTar ; do | 
| 113 | 
jmc | 
1.8 | 
      if test $xx != $chkptar.gz ; then | 
| 114 | 
jmc | 
1.6 | 
        if test -f other_checkpoints/$xx ; then | 
| 115 | 
  | 
  | 
          echo "error: $backupDir/$xx already exist" | 
| 116 | 
  | 
  | 
        else | 
| 117 | 
  | 
  | 
          echo " mv $xx $backupDir" | 
| 118 | 
  | 
  | 
          mv $xx $backupDir | 
| 119 | 
  | 
  | 
        # echo " Remove $xx" | 
| 120 | 
  | 
  | 
        # /bin/rm -f $xx | 
| 121 | 
  | 
  | 
        fi | 
| 122 | 
jmc | 
1.1 | 
      fi | 
| 123 | 
jmc | 
1.6 | 
    done | 
| 124 | 
  | 
  | 
  fi | 
| 125 | 
  | 
  | 
else | 
| 126 | 
  | 
  | 
  echo "missing file '$version_file' !" | 
| 127 | 
jmc | 
1.1 | 
fi |