summaryrefslogtreecommitdiff
path: root/omnibus/package-scripts/chef/postrm
blob: 7789e7f221b38db9f9754846a47a10535d02c0f8 (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
#!/bin/sh
# WARNING: REQUIRES /bin/sh
#
# - must run on /bin/sh on solaris 9
# - must run on /bin/sh on AIX 6.x
# - if you think you are a bash wizard, you probably do not understand
#   this programming language.  do not touch.
# - if you are under 40, get peer review from your elders.

is_smartos() {
  uname -v | grep "^joyent" 2>&1 >/dev/null
}

is_darwin() {
  uname -v | grep "^Darwin" 2>&1 >/dev/null
}

is_suse() {
  if [ -f /etc/os-release ]; then
    source /etc/os-release
    [ $ID_LIKE == "sles" ] || [ $ID_LIKE == "suse" ]
  else
    [ -f /etc/SuSE-release ]
  fi
}

if is_smartos; then
    PREFIX="/opt/local"
elif is_darwin; then
    PREFIX="/usr/local"
else
    PREFIX="/usr"
fi

cleanup_symlinks() {
  binaries="chef-client chef-solo chef-apply chef-shell knife ohai"
  for binary in $binaries; do
    rm -f $PREFIX/bin/$binary
  done
}

# Clean up binary symlinks if they exist
# see: http://tickets.opscode.com/browse/CHEF-3022
if [ ! -f /etc/redhat-release -a ! -f /etc/fedora-release -a ! -f /etc/system-release -a ! is_suse ]; then
  # not a redhat-ish RPM-based system
  cleanup_symlinks
elif [ "x$1" = "x0" ]; then
  # RPM-based system and we're deinstalling rather than upgrading
  cleanup_symlinks
fi