aboutsummaryrefslogtreecommitdiffstats
path: root/bin/rollback-profile
blob: 81386b301660a6d4cc7ab8c1458626f2d8db7686 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
#
# Rollback a thunderbird or firefox profile backup from store location while gpg decrypting
#

# Checking if firefox and/ or thunderbird are running.
firefoxPID=`ps -C firefox -o pid=`
thunderbirdPID=`ps -C thunderbird -o pid=`

firefoxTMP=/tmp/firefox.tgz
thunderbirdTMP=/tmp/thunderbird.tgz
firefoxIF=~/.mozilla/firefox/
thunderbirdIF=~/.thunderbird/
profileName=dvzrv
backupEND=-rollback
OF=~/ownCloud/backup/web/
gpgEND=.gpg
tgzEND=.tgz

case $1 in
  "thunderbird")
    if [[ -z "$thunderbirdPID" ]]
    then
      echo "Thunderbird is not running."
      echo "Rolling back profile backup."
      echo "Copying backup to /tmp and moving old profile to rollback location."
      cp $OF$1$tgzEND$gpgEND $thunderbirdTMP$gpgEND
      mv $thunderbirdIF$profileName $thunderbirdIF$profileName$backupEND
      echo "Decrypting file."
      gpg -o $thunderbirdTMP -d $thunderbirdTMP$gpgEND
      echo "Extracting files from tar."
      tar xzvf $thunderbirdTMP -C $thunderbirdIF
      echo "Cleaning up."
      rm $thunderbirdTMP $thunderbirdTMP$gpgEND
      echo "Done."
    else
      echo "Thunderbird is still running."
      echo "Skipping rollback."
    fi
    ;;
  "firefox")
    if [[ -z "$firefoxPID" ]]
    then
      echo "Firefox is not running."
      psdStopped=`systemctl status psd |grep inactive`
      if [[ ! -z "$psdStopped" ]]; then
        echo "Psd daemon is inactive."
        echo "Rolling back profile backup."
        echo "Copying backup to /tmp and moving old profile to rollback location."
        cp $OF$1$tgzEND$gpgEND $firefoxTMP$gpgEND
        mv $firefoxIF$profileName $firefoxIF$profileName$backupEND
        echo "Decrypting file."
        gpg -o $firefoxTMP -d $firefoxTMP$gpgEND
        echo "Extracting files from tar."
        tar xzvf $firefoxTMP -C $firefoxIF
        echo "Cleaning up."
        rm $firefoxTMP $firefoxTMP$gpgEND
        echo "Done."
      else
        echo "Psd service is still running!"
        echo "Disable it using: 'systemctl stop psd'."
        echo "Skipping rollback."
      fi
    else
      echo "Firefox is still running."
      echo "Skipping rollback."
    fi
    ;;
esac