From e4a85a9cac9ba6d24776b90af6d31ce24e397019 Mon Sep 17 00:00:00 2001 From: nolash Date: Sun, 5 Dec 2021 07:54:44 +0100 Subject: [PATCH] Add pylocation script --- aux/pylocation/pylocation.sh | 46 ++++++++++++++++++++++++++++++++++++ setup.sh | 3 --- setup_systemd.sh | 3 +++ 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 aux/pylocation/pylocation.sh diff --git a/aux/pylocation/pylocation.sh b/aux/pylocation/pylocation.sh new file mode 100644 index 0000000..5534062 --- /dev/null +++ b/aux/pylocation/pylocation.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +if [ ! -z "$PYTHON_BIN_PATH" ]; then + >&2 echo "PYTHON_BIN_PATH already set to $PYTHON_BIN_PATH" + echo -n $PYTHON_BIN_PATH +else + set +a + set +e + + d=`mktemp -d` + u=`dd if=/dev/urandom bs=16 count=1 2> /dev/null | hexdump -v -n 16 -e '1/1 "%02x"'` + mkdir -p $d/$u + cat <> $d/setup.py +from setuptools import setup + +setup( + name="$u", + version="0.0.0", + packages=[ + "$u", + ], + entry_points={ + "console_scripts": [ + "$u.bin=$u:main", + ], + }, +) +EOF + + cat <> $d/$u/__init__.py +def main(): + pass +EOF + + pushd $d > /dev/null + python setup.py --quiet sdist + pip install -q dist/${u}-0.0.0.tar.gz + p=`which $u.bin` + pip uninstall -q -y $u + export PYTHON_BIN_PATH=$(dirname $p) + echo -n $PYTHON_BIN_PATH + popd > /dev/null + + set -e + set -a +fi diff --git a/setup.sh b/setup.sh index 17f484e..6a96e32 100644 --- a/setup.sh +++ b/setup.sh @@ -14,8 +14,6 @@ PIP_EXTRA_INDEX_URL=${PIP_EXTRA_INDEX_URL:-https://pip.grassrootseconomics.net:8 PIP_INDEX_URL=${PIP_INDEX_URL:-"https://pypi.org/simple"} CIC_SETUP_TRUSTED_FINGERPRINT=${CIC_SETUP_TRUSTED_FINGERPRINT:-0826EDA1702D1E87C6E2875121D2E7BB88C2A746} CIC_ROOT_URL=${CIC_ROOT_URL:-https://root.grassrootseconomics.net} -default_python_path=$(dirname $(which python)) -PYTHON_BIN_PATH=${PYTHON_BIN_PATH:-$default_python_path} if [ "$UID" -eq 0 ]; then dbg $dbg_error "This cannot be run as root" @@ -166,7 +164,6 @@ set +a . setup_systemd.sh -echo foo $INSTALL_EVM if [ ! -z $INSTALL_EVM ]; then . setup_${INSTALL_EVM}.sh fi diff --git a/setup_systemd.sh b/setup_systemd.sh index 30fe278..7a13e8f 100644 --- a/setup_systemd.sh +++ b/setup_systemd.sh @@ -9,6 +9,9 @@ _debug=1 cp -v systemd/cic-cache-server.service $HOME/.config/systemd/user/ cp -v systemd/bloxberg.service $HOME/.config/systemd/user/ dbg $dbg_debug "writing rendered services file $p" + +export PYTHON_BIN_PATH=`. aux/pylocation/pylocation.sh 2> /dev/null` +dbg $dbg_info "using python bin path $PYTHON_BIN_PATH for systemd executables" PYTHON_BIN_PATH=$PYTHON_BIN_PATH ./aux/bash-templater/templater.sh systemd/cic-cache-tracker.service > $HOME/.config/systemd/user/cic-cache-tracker.service for f in systemd/env/*.conf; do