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
|
#!/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.
# This whole file exists because on some versions of RPM, during upgrades, the postrm script
# runs AFTER the installation of the upgraded RPM. Oops. See https://github.com/chef/chef/pull/7964
INSTALLER_DIR=/opt/chef
if [ -e $INSTALLER_DIR ]; then
echo "removing $INSTALLER_DIR..."
rm -rf $INSTALLER_DIR || true
fi
# Sometimes, on some platforms, we get an EBUSY error trying to delete this, which will cause issues
# with the upgrades. So we move it so it won't interfere with the upgrade, then delete it, which will
# cause the OS to free the space once it's no longer used (when the current chef run ends, or whatever
# else is using those libs). See: https://github.com/chef/chef/pull/8046
if [ -e $INSTALLER_DIR ]; then
echo "Some files failed to delete, moving them so we don't interfere with upgrades, and then removing them"
# have to do this dance of moving /opt/chef to a tmp dir since files may be in use
tmp_dir="/opt/.chef.$$"
# if we can't create the tmp_dir then fail hard to prevent any possible security hole
(umask 077 && mkdir $tmp_dir) || exit 1
# now we can clean up the tmp_dir we created safely
mv $INSTALLER_DIR $tmp_dir
# ignore errors which must be EBUSY issues, this may crate some litter, which may
# be unavoidable
rm -rf $tmp_dir || true
fi
|