summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2018-12-13 17:05:28 -0800
committerGitHub <noreply@github.com>2018-12-13 17:05:28 -0800
commiteaffc7b17140e163b096fda87169c27501290d94 (patch)
tree83c867743265a2edbb002a0ee826fb0de9b7cbc2
parent87e0d8ae8babd9c38b5b3c440cb774fd3b558e38 (diff)
parentcfa45b928007e5b9b90a31ad79cd5cbf2b03c9f4 (diff)
downloadchef-eaffc7b17140e163b096fda87169c27501290d94.tar.gz
Merge pull request #8046 from chef/lcg/fix-omnibus-rm-rf
fix EBUSY errors in preinst script
-rwxr-xr-xomnibus/package-scripts/angrychef/preinst11
-rwxr-xr-xomnibus/package-scripts/chef-fips/preinst11
-rwxr-xr-xomnibus/package-scripts/chef/preinst11
3 files changed, 30 insertions, 3 deletions
diff --git a/omnibus/package-scripts/angrychef/preinst b/omnibus/package-scripts/angrychef/preinst
index b3038a10c6..870bd5fc37 100755
--- a/omnibus/package-scripts/angrychef/preinst
+++ b/omnibus/package-scripts/angrychef/preinst
@@ -9,4 +9,13 @@
INSTALLER_DIR=/opt/angrychef
echo "removing $INSTALLER_DIR..."
-rm -rf $INSTALLER_DIR
+
+# 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
diff --git a/omnibus/package-scripts/chef-fips/preinst b/omnibus/package-scripts/chef-fips/preinst
index 834c29544b..69909262c9 100755
--- a/omnibus/package-scripts/chef-fips/preinst
+++ b/omnibus/package-scripts/chef-fips/preinst
@@ -9,4 +9,13 @@
INSTALLER_DIR=/opt/chef-fips
echo "removing $INSTALLER_DIR..."
-rm -rf $INSTALLER_DIR
+
+# 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
diff --git a/omnibus/package-scripts/chef/preinst b/omnibus/package-scripts/chef/preinst
index 1880275e99..b3f48258c7 100755
--- a/omnibus/package-scripts/chef/preinst
+++ b/omnibus/package-scripts/chef/preinst
@@ -9,4 +9,13 @@
INSTALLER_DIR=/opt/chef
echo "removing $INSTALLER_DIR..."
-rm -rf $INSTALLER_DIR
+
+# 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