bootstrap: Do not require sudo when running as root

This commit is contained in:
2020-12-08 23:09:09 +01:00
parent 1f0ea0e7be
commit 1a6239e928
2 changed files with 16 additions and 4 deletions

View File

@@ -16,7 +16,11 @@ if [[ "$(readlink "${_SCRIPT_DIR}")" != "${DOTDIR}" ]] ; then
exit 1
fi
printf "Moving directory to $DOTDIR ...\n"
sudo mv --no-target-directory "${_SCRIPT_DIR}" "${DOTDIR}"
sudo=""
if (( $(id -u ) != 0 )) ; then
sudo=sudo
fi
$sudo mv --no-target-directory "${_SCRIPT_DIR}" "${DOTDIR}"
printf "Done\n"
else
printf "Already working in ${DOTDIR}, nothing to do\n"

View File

@@ -18,14 +18,22 @@ source /etc/os-release
_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
sudowrap() {
if (( $(id -u ) != 0 )) ; then
sudo "${@}"
else
"${@}"
fi
}
_install() {
_package="$1" ; shift
if [[ $NAME == "Fedora" ]] ; then
sudo dnf install --assumeyes "${_package}"
sudowrap dnf install --assumeyes "${_package}"
elif [[ $NAME == "Ubuntu" ]] ; then
sudo apt-get install --assume-yes "${_package}"
sudowrap apt-get install --assume-yes "${_package}"
elif [[ $NAME == "Arch Linux" ]] ; then
sudo pacman -S --noconfirm "${_package}"
sudowrap pacman -S --noconfirm "${_package}"
else
2>&1 printf "Unsupported distro $NAME, exiting"
exit 1