summaryrefslogtreecommitdiff
path: root/include/lib.sh
diff options
context:
space:
mode:
Diffstat (limited to 'include/lib.sh')
-rw-r--r--include/lib.sh43
1 files changed, 29 insertions, 14 deletions
diff --git a/include/lib.sh b/include/lib.sh
index 857857d2..b43d83f3 100644
--- a/include/lib.sh
+++ b/include/lib.sh
@@ -15,16 +15,6 @@ tmpgit="$PWD/tmp/gitclone"
grubdata="config/data/grub"
err="err_"
-pyver="2"
-python="python3"
-command -v python3 1>/dev/null || python="python"
-command -v $python 1>/dev/null || pyver=""
-[ -n "$pyver" ] && pyver="$($python --version | awk '{print $2}')"
-if [ "${pyver%%.*}" != "3" ]; then
- printf "Wrong python version, or python missing. Must be v 3.x.\n" 1>&2
- exit 1
-fi
-
err_()
{
printf "ERROR %s: %s\n" "$0" "$1" 1>&2; exit 1
@@ -88,6 +78,22 @@ if [ $# -gt 0 ] && [ "$1" = "dependencies" ]; then
exit 0
fi
+pyver="2"
+python="python3"
+command -v python3 1>/dev/null || python="python"
+command -v $python 1>/dev/null || pyver=""
+[ -z "$pyver" ] || \
+ python -c 'import sys; print(sys.version_info[:])' 1>/dev/null \
+ 2>/dev/null || $err "Cannot determine which Python version."
+[ -n "$pyver" ] && \
+ pyver="`python -c 'import sys; print(sys.version_info[:])' | \
+ awk '{print $1}'`" && \
+ pyver="${pyver#(}" && pyver="${pyver%,}"
+if [ "${pyver%%.*}" != "3" ]; then
+ printf "Wrong python version, or python missing. Must be v 3.x.\n" 1>&2
+ exit 1
+fi
+
id -u 1>/dev/null 2>/dev/null || $err "suid check failed (id -u)"
[ "$(id -u)" != "0" ] || $err "this command as root is not permitted"
@@ -107,10 +113,19 @@ if [ -z "${TMPDIR+x}" ]; then
export TMPDIR="/tmp"
export TMPDIR="$(mktemp -d -t xbmk_XXXXXXXX)"
touch lock || $err "cannot create 'lock' file"
- rm -Rf "$XBMK_CACHE/xbmkpath" || $err "cannot remove xbmkpath"
- mkdir -p "$XBMK_CACHE/xbmkpath" || $err "cannot create xbmkpath"
- export PATH="$XBMK_CACHE/xbmkpath:$PATH" || \
- $err "Can't create xbmkpath"
+ rm -Rf "$XBMK_CACHE/xbmkpath" "$XBMK_CACHE/gnupath" || \
+ $err "cannot remove xbmkpath"
+ mkdir -p "$XBMK_CACHE/gnupath" "$XBMK_CACHE/xbmkpath" || \
+ $err "cannot create gnupath"
+ export PATH="$XBMK_CACHE/xbmkpath:$XBMK_CACHE/gnupath:$PATH" || \
+ $err "Can't create gnupath/xbmkpath"
+ (
+ # set up python v3.x in PATH, in case it's not set up correctly.
+ # see code above that detected the correct python3 command.
+ cd "$XBMK_CACHE/xbmkpath" || $err "can't cd $XBMK_CACHE/xbmkpath"
+ ln -s "`command -v "$python"`" python || \
+ $err "Can't set up python symlink in $XBMK_CACHE/xbmkpath"
+ ) || $err "Can't set up python symlink in $XBMK_CACHE/xbmkpath"
xbmk_parent="y"
fi