mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
Adding in root check to install commands with fallback to sudo. Splitting install logic out based on host OS
This commit is contained in:
parent
b0ac5024a4
commit
e7d6d096a8
1 changed files with 53 additions and 9 deletions
|
@ -30,7 +30,7 @@ make_tempdir() {
|
||||||
local template
|
local template
|
||||||
local tempdir
|
local tempdir
|
||||||
|
|
||||||
template="${1}"
|
template="${1}.XXXXXX"
|
||||||
|
|
||||||
if command -v mktemp >/dev/null 2>&1; then
|
if command -v mktemp >/dev/null 2>&1; then
|
||||||
tempdir="$(mktemp -d -t "${template}")"
|
tempdir="$(mktemp -d -t "${template}")"
|
||||||
|
@ -228,17 +228,17 @@ extract_file() {
|
||||||
return "${rcode}"
|
return "${rcode}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#--- FUNCTION ----------------------------------------------------------------
|
#--- FUNCTION ----------------------------------------------------------------
|
||||||
# NAME: install_file
|
# NAME: install_file_freebsd
|
||||||
# DESCRIPTION: Installs a file into a location using 'install'
|
# DESCRIPTION: Installs a file into a location using 'install'. If EUID not
|
||||||
|
# 0, then attempt to use sudo.
|
||||||
# PARAMETERS: $1 = file to install
|
# PARAMETERS: $1 = file to install
|
||||||
# $2 = location to install file into
|
# $2 = location to install file into
|
||||||
# RETURNS: 0 = File Installed
|
# RETURNS: 0 = File Installed
|
||||||
# 1 = File not installed
|
# 1 = File not installed
|
||||||
# 2 = Could not find install command
|
# 2 = Could not find install command
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
install_file() {
|
install_file_freebsd() {
|
||||||
local file
|
local file
|
||||||
local prefix
|
local prefix
|
||||||
local rcode
|
local rcode
|
||||||
|
@ -247,8 +247,47 @@ install_file() {
|
||||||
prefix="${2}"
|
prefix="${2}"
|
||||||
|
|
||||||
if command -v install >/dev/null 2>&1; then
|
if command -v install >/dev/null 2>&1; then
|
||||||
sudo install -C -b -S '_old' -m 755 -t "${prefix}" "${file}"
|
if [[ "${EUID}" == "0" ]]; then
|
||||||
rcode="${?}"
|
install -C -b -B '_old' -m 755 "${file}" "${prefix}"
|
||||||
|
rcode="${?}"
|
||||||
|
else
|
||||||
|
sudo install -C -b -B '_old' -m 755 "${file}" "${prefix}"
|
||||||
|
rcode="${?}"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
rcode="2"
|
||||||
|
fi
|
||||||
|
|
||||||
|
return "${rcode}"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#--- FUNCTION ----------------------------------------------------------------
|
||||||
|
# NAME: install_file_linux
|
||||||
|
# DESCRIPTION: Installs a file into a location using 'install'. If EUID not
|
||||||
|
# 0, then attempt to use sudo.
|
||||||
|
# PARAMETERS: $1 = file to install
|
||||||
|
# $2 = location to install file into
|
||||||
|
# RETURNS: 0 = File Installed
|
||||||
|
# 1 = File not installed
|
||||||
|
# 2 = Could not find install command
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
install_file_linux() {
|
||||||
|
local file
|
||||||
|
local prefix
|
||||||
|
local rcode
|
||||||
|
|
||||||
|
file="${1}"
|
||||||
|
prefix="${2}"
|
||||||
|
|
||||||
|
if command -v install >/dev/null 2>&1; then
|
||||||
|
if [[ "${EUID}" == "0" ]]; then
|
||||||
|
install -C -b -S '_old' -m 755 -t "${prefix}" "${file}"
|
||||||
|
rcode="${?}"
|
||||||
|
else
|
||||||
|
sudo install -C -b -S '_old' -m 755 -t "${prefix}" "${file}"
|
||||||
|
rcode="${?}"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
rcode="2"
|
rcode="2"
|
||||||
fi
|
fi
|
||||||
|
@ -407,8 +446,12 @@ main() {
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
install_file "${tmpdir}/${croc_bin_name}" "${prefix}/"
|
case "${croc_os}" in
|
||||||
install_file_rcode="${?}"
|
"Linux" ) install_file_linux "${tmpdir}/${croc_bin_name}" "${prefix}/";
|
||||||
|
install_file_rcode="${?}";;
|
||||||
|
"FreeBSD" ) install_file_freebsd "${tmpdir}/${croc_bin_name}" "${prefix}/";
|
||||||
|
install_file_rcode="${?}";;
|
||||||
|
esac
|
||||||
if [[ "${install_file_rcode}" == "0" ]]; then
|
if [[ "${install_file_rcode}" == "0" ]]; then
|
||||||
echo "== Installed ${croc_bin_name} to ${prefix}/"
|
echo "== Installed ${croc_bin_name} to ${prefix}/"
|
||||||
elif [[ "${install_file_rcode}" == "1" ]]; then
|
elif [[ "${install_file_rcode}" == "1" ]]; then
|
||||||
|
@ -419,6 +462,7 @@ main() {
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
echo "== Return code of 'install' returned an unexpected value of ${install_file_rcode}"
|
echo "== Return code of 'install' returned an unexpected value of ${install_file_rcode}"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "== Cleaning up ${tmpdir}"
|
echo "== Cleaning up ${tmpdir}"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue