summarylogtreecommitdiffstats
path: root/grav.install
blob: 9c65afc24afaaa3ed488475edae61d98d7b16b2b (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# Maintainer:  Markus Hansmair <archlinux at zendro dot de>
# Contributor: Dimitris Kiziridis <ragouel at outlook dot com>
# Contributor: Nils Czernia <nils at czserver dot de>

post_install() {
  GRAV_ROOT=/usr/share/webapps/grav

  mkdir -p /var/cache/grav/{assets,images,cache,sessions}
  ln -s /var/cache/grav/assets $GRAV_ROOT/assets
  ln -s /var/cache/grav/images $GRAV_ROOT/images

  mkdir -p /var/lib/grav/backup
  cp -r $GRAV_ROOT/user.upstream /var/lib/grav/user
  rm /var/lib/grav/user/README.md
  rm -rf /var/lib/grav/user/config
  ln -s /var/lib/grav/user $GRAV_ROOT/user
  _fix_permissions /var/lib/grav 640 750

  ln -s /etc/webapps/grav/config /var/lib/grav/user/config
  _fix_permissions /etc/webapps/grav 644 755
}

pre_upgrade() {
  if [ "$(vercmp "$2" '1.7')" -lt 0 ]; then
    GRAV_ROOT=/usr/share/webapps/grav

    rm -rf "$GRAV_ROOT/vendor"

    mkdir -p /etc/webapps/grav
    mv "$GRAV_ROOT/user/config" /etc/webapps/grav
  fi
}

post_upgrade() {
  if [ "$(vercmp "$2" '1.7')" -lt 0 ]; then
    echo "WARNING: Major changes introduced to the package"
    echo "         The application is now run with its own user (grav)."
    echo "         Your current installation is now probably broken. See"
    echo "         https://wiki.archlinux.org/title/Grav how to fix this."
    
    GRAV_ROOT=/usr/share/webapps/grav

    for DIR in assets images cache; do
      _move_or_create "$GRAV_ROOT/$DIR" "/var/cache/grav/$DIR"
      _fix_permissions "/var/cache/grav/$DIR" 640 750
    done
    ln -s /var/cache/grav/assets $GRAV_ROOT/assets
    ln -s /var/cache/grav/images $GRAV_ROOT/images

    _move_or_create "$GRAV_ROOT/tmp" /var/tmp/grav
    _fix_permissions /var/tmp/grav 640 750

    _move_or_create "$GRAV_ROOT/logs" /var/log/grav
    _fix_permissions /var/log/grav 644 755

    rm -rf $GRAV_ROOT/user/config
    ln -s /etc/webapps/grav/config $GRAV_ROOT/user/config
    _fix_permissions /etc/webapps/grav 644 755

    mkdir -p /var/lib/grav
    mv $GRAV_ROOT/user /var/lib/grav
    ln -s /var/lib/grav/user $GRAV_ROOT/user
    _move_or_create "$GRAV_ROOT/backup" /var/lib/grav/backup
  fi
  _fix_permissions /var/lib/grav 640 750
}

pre_remove() {
  rm -rf /usr/share/webapps/grav/{assets,images,user}
}

post_remove() {
  # this is not covered by any hook
  rm -rf /var/log/grav /var/tmp/grav /var/cache/grav

  echo "Grav user content and backups can still be found under /var/lib/grav"
}

_move_or_create() {
  if [ -d "$1" ]; then
    rm -rf "$2"
    mv "$1" "$2"
  else
    mkdir -p "$2"
  fi
}

_fix_permissions() {
  chmod -R "$2" "$1"
  find "$1" -type d -exec chmod "$3" {} \;
}