github.com/crowdsecurity/crowdsec@v1.6.1/debian/preinst (about)

     1  #!/bin/bash
     2  
     3  set -e
     4  
     5  # Source debconf library.
     6  . /usr/share/debconf/confmodule
     7  
     8  
     9  OLD_MAJOR_VERSION=$(echo $2 | cut -d'.' -f1)
    10  OLD_MINOR_VERSION=$(echo $2 | cut -d'.' -f2)
    11  OLD_PATCH_VERSION=$(echo $2 | cut -d'.' -f3|cut -d'-' -f1)
    12  
    13  NEW_MAJOR_VERSION=$(echo $3 | cut -d'.' -f1)
    14  NEW_MINOR_VERSION=$(echo $3 | cut -d'.' -f2)
    15  NEW_PATCH_VERSION=$(echo $3 | cut -d'.' -f3|cut -d'-' -f1)
    16  
    17  
    18  
    19  if [ "$1" = upgrade ]; then
    20  
    21      OLD_MAJOR_VERSION=$(echo $2 | cut -d'.' -f1)
    22      OLD_MINOR_VERSION=$(echo $2 | cut -d'.' -f2)
    23      OLD_PATCH_VERSION=$(echo $2 | cut -d'.' -f3|cut -d'-' -f1)
    24  
    25      NEW_MAJOR_VERSION=$(echo $3 | cut -d'.' -f1)
    26      NEW_MINOR_VERSION=$(echo $3 | cut -d'.' -f2)
    27      NEW_PATCH_VERSION=$(echo $3 | cut -d'.' -f3|cut -d'-' -f1)
    28  
    29      
    30     if [[ $OLD_MAJOR_VERSION -eq "1" ]] && [[ $OLD_MINOR_VERSION -eq "0" ]] && [[ $OLD_PATCH_VERSION -lt "9" ]]; then
    31         if [[ -f /var/lib/crowdsec/data/crowdsec.db ]]; then
    32            cp /var/lib/crowdsec/data/crowdsec.db  /var/lib/crowdsec/data/crowdsec.db.backup
    33         fi
    34     fi
    35  
    36     if [[ $NEW_MAJOR_VERSION -gt  $OLD_MAJOR_VERSION ]]; then
    37        echo "Stopping crowdsec"
    38        systemctl stop crowdsec || true
    39        cscli config backup /var/lib/crowdsec/backup
    40     fi   
    41  fi
    42  
    43  echo "You can always run the configuration again interactively by using '/usr/share/crowdsec/wizard.sh -c'"