Skip to content

Commit

Permalink
Avoid building as root with sudo make install
Browse files Browse the repository at this point in the history
When running `sudo make install`, we only want to run the actual install
as root, the building of the documentation and the distribution folder
should happen as the non-root user.

Related to #13728.
  • Loading branch information
lilyball committed Sep 5, 2014
1 parent 5248b11 commit 23c2661
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions mk/install.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,34 @@ else
MAYBE_DISABLE_VERIFY=
endif

install: dist-install-dir-$(CFG_BUILD) | tmp/empty_dir
install:
ifeq (root user, $(USER) $(patsubst %,user,$(SUDO_USER)))
# Build the dist as the original user
$(Q)sudo -u "$$SUDO_USER" $(MAKE) prepare_install
else
$(Q)$(MAKE) prepare_install
endif
$(Q)cd tmp/empty_dir && sh ../../tmp/dist/$(PKG_NAME)-$(CFG_BUILD)/install.sh --prefix="$(DESTDIR)$(CFG_PREFIX)" --libdir="$(DESTDIR)$(CFG_LIBDIR)" --mandir="$(DESTDIR)$(CFG_MANDIR)" "$(MAYBE_DISABLE_VERIFY)"
# Remove tmp files while we can because they may have been created under sudo
# Remove tmp files because it's a decent amount of disk space
$(Q)rm -R tmp/dist

uninstall: dist-install-dir-$(CFG_BUILD) | tmp/empty_dir
prepare_install: dist-install-dir-$(CFG_BUILD) | tmp/empty_dir

uninstall:
ifeq (root user, $(USER) $(patsubst %,user,$(SUDO_USER)))
# Build the dist as the original user
$(Q)sudo -u "$$SUDO_USER" $(MAKE) prepare_uninstall
else
$(Q)$(MAKE) prepare_uninstall
endif
$(Q)cd tmp/empty_dir && sh ../../tmp/dist/$(PKG_NAME)-$(CFG_BUILD)/install.sh --uninstall --prefix="$(DESTDIR)$(CFG_PREFIX)" --libdir="$(DESTDIR)$(CFG_LIBDIR)" --mandir="$(DESTDIR)$(CFG_MANDIR)"
# Remove tmp files while we can because they may have been created under sudo
# Remove tmp files because it's a decent amount of disk space
$(Q)rm -R tmp/dist

prepare_uninstall: dist-install-dir-$(CFG_BUILD) | tmp/empty_dir

.PHONY: install prepare_install uninstall prepare_uninstall

tmp/empty_dir:
mkdir -p $@

Expand Down

9 comments on commit 23c2661

@bors
Copy link
Contributor

@bors bors commented on 23c2661 Sep 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from pnkfelix
at lilyball@23c2661

@bors
Copy link
Contributor

@bors bors commented on 23c2661 Sep 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging kballard/rust/install_no_sudo = 23c2661 into auto

@bors
Copy link
Contributor

@bors bors commented on 23c2661 Sep 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kballard/rust/install_no_sudo = 23c2661 merged ok, testing candidate = 5406d5fa

@bors
Copy link
Contributor

@bors bors commented on 23c2661 Sep 22, 2014

@bors
Copy link
Contributor

@bors bors commented on 23c2661 Oct 17, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from pnkfelix
at lilyball@23c2661

@bors
Copy link
Contributor

@bors bors commented on 23c2661 Oct 17, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging kballard/rust/install_no_sudo = 23c2661 into auto

@bors
Copy link
Contributor

@bors bors commented on 23c2661 Oct 17, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kballard/rust/install_no_sudo = 23c2661 merged ok, testing candidate = 9b80efd

@bors
Copy link
Contributor

@bors bors commented on 23c2661 Oct 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 23c2661 Oct 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 9b80efd

Please sign in to comment.