Narzędzia użytkownika

Narzędzia witryny


wiki:zzzver

Bardzo Podstawowy System Kontroli Wersji.

Wymagania:

  • bash
  • tee
  • diff
  • gzip
  • md5sum
#!/usr/bin/bash
# very basic version control system

# let's check current directory
PWD=$(pwd)

# check flags and do stuff
if [ "$1" = "init" ] ; then
  # initialize repository
  mkdir $PWD/stable
  mkdir $PWD/test
  mkdir $PWD/archive
  touch $PWD/zzzrepo
  echo "$(date): repository initialized" | tee -a $PWD/zzzrepo

# compare stable, test and archives  
elif [ "$1" = "diff" ] ; then
  if [ -z $2 ] ; then
    # diff test and stable directories
    diff -d -r $PWD/test/ $PWD/stable/
  else
    # diff test and stable directories with the content of specified archive
    mkdir $PWD/archive/difftemp
    tar -zxvf $PWD/$2 -C $PWD/archive/difftemp
    echo "------ Test ------"
    diff -d -r $PWD/test $PWD/archive/difftemp/test
    echo " "
    echo " ----- Stable ------"
    diff -d -r $PWD/stable $PWD/archive/difftemp/stable
    rm -fr $PWD/archive/difftemp
    echo " "
  fi

# copy test to stable
elif [ "$1" = "merge" ] ; then
  # overwrite stable with test
  rm -fr $PWD/stable/*
  cp --recursive $PWD/test/* $PWD/stable/
  echo "$(date): merged test into stable" | tee -a $PWD/zzzrepo

# save stable and test as archive
elif [ "$1" = "save" ] ; then
  # save test and stable as an archive under a name of date and time
  # also make md5 hashes
  timestamp=$(date +%F_%T)
  echo "Making md5 hashes of files in test..."
  find $PWD/test -type f -print0 | xargs -0 md5sum > $PWD/test/zzztest.md5
  echo "Making md5 hashes of files in stable..."
  find $PWD/stable -type f -print0 | xargs -0 md5sum > $PWD/stable/zzzstable.md5
  tar -zcf $PWD/archive/$timestamp.tar.gz test/ stable/
  echo "$(date): repository archived" | tee -a $PWD/zzzrepo

# restore stable and / or test from archive  
elif [ "$1" = "load" ] ; then
  if [ -z $3 ] ; then
    # overwrite test and stable with content of the specified archive
    rm -fr $PWD/test
    rm -fr $PWD/stable
    tar -zxf $2 -C $PWD
    echo "$(date): restored backup from $2 archive" | tee -a $PWD/zzzrepo
  elif [ "$3" = "test" ] ; then
    # overwite just test with content of specified archive
    rm -fr $PWD/test 
    tar -k -zxf $2 -C $PWD &> /dev/null
    echo "$(date): restored test repo backup from $2 archive" | tee -a $PWD/zzzrepo
  elif [ "$3" = "stable" ] ; then
    # overwrite just stable with content of specified archive
    rm -fr $PWD/stable
    tar -k -zxf $2 -C $PWD &> /dev/null
    echo "$(date): restored stable repo backup from $2 archive" | tee -a $PWD/zzzrepo
  fi

# create md5 sums of files from stabkle and test
if [ "$1" = "md5" ] ; then
  # create md5 of each file in test and stable
  find $PWD/test/ -type f -print0 | xargs -0 md5sum > $PWD/test/zzztest.md5
  find $PWD/stable/ -f type -f -print0 | xargs -0 md5dum > $PWD/stable/zzzstable.md5
  echo "$(date): sums written into test/zzztest.md5 and stable/zzzstable.md5 files." | tee -a $PWD/zzzrepo
fi

# help 
elif [ -z $1 ] ; then
  # echo some instructions
  echo " "
  echo -e "Please specify:\r
   zzzver init - to create new repository,\r
   zzzver diff - to compare test and stable repo,\r
   zzzver diff archive/name.tar.gz - to compare test and stable with specified archive,\r
   zzzver merge - to copy test into stable,\r
   zzzver save - to archive test and stable as date_time.tar.gz,\r
   zzzver load archive/name.tar.gz - to replace test and stable with content of specified archive,\r
   zzzver load archive/name.tar.gz test - to replace test with content of specified archive,\r
   zzzver load archive/name.tar.gz stable - to replace stable with content of specified archive.\r
   zzzver md5 - to make md5 hashes of files from testing and stable."
   echo " "

# catch wrong parameters
else
  echo "I give up, you wrote something wrong. :("
  echo "Run zzzver without parameters to get some help."
  echo " "
fi
wiki/zzzver.txt · ostatnio zmienione: 2020/03/03 05:08 przez lukasz