Fix correct commit hash for release 0.7.0 of openXC7
[dev-env-setup.git] / pia-install
index 57f627ee02152f6ee95ee7825d40b988459d1087..c800176cadf9e1483d1adfe2158fc1697ea9c0f9 100755 (executable)
@@ -1,23 +1,52 @@
 #!/bin/bash
-if [ "$EUID" -ne 0 ]
-  then echo "Please run as root"
-  exit
+set -e
+if ! command -v rustup &> /dev/null; then
+    echo "Rustup could not be found, it can be installed by"
+    echo "running the following command: "
+    echo "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh" >& 2
+    exit 1
 fi
+cd ~/src
+rustup default stable
+rustup update
 
-export MYNAME=`id 1000 | awk '{print $1}' | sed 's/.*(\(.*\))/\1/'`
+# use the authorised copy controlled under the Libre-SOC git server,
+# not unauthorised uncontrolled servers (debian salsa)
+git clone https://git.libre-soc.org/git/power-instruction-analyzer.git pia
+cd pia
+
+# do not use external scripts.
+
+function fail()
+{
+    echo "error: $@" >&2
+    exit 1
+}
 
-runuser $MYNAME --preserve-environment -c '/bin/bash << EOF
-export PATH=/home/$MYNAME/.cargo/bin:$PATH
-export HOME=/home/$MYNAME
-if ! command -v rustup &> /dev/null
-then
-    echo -e "Rustup could not be found, it can be installed by running the following command: curl --proto \047=https\047 --tlsv1.2 -sSf https://sh.rustup.rs | sh"
-    exit
+if [[ "$VIRTUAL_ENV" == "" ]]; then
+    user=( "--user" )
+else
+    user=()
 fi
-cd /home/$MYNAME/src
-git clone https://salsa.debian.org/Kazan-team/power-instruction-analyzer.git pia
-cd pia
-maturin build --cargo-extra-args=--features=python-extension
-EOF'
-cd /home/$MYNAME/src/pia
-python3 -m pip install target/wheels/*.whl
+cargo_version="$(cargo --version)" || \
+            fail "can't find cargo, install it from https://rustup.rs/"
+[[ "$cargo_version" =~ ^'cargo 1.'([0-9]+)'.'[0-9]+' ' ]] || \
+            fail "can't parse cargo's version string"
+(( "${BASH_REMATCH[1]}" >= 53 )) || \
+            fail 'your rust version is not recent enough, update your rust version using `rustup update`'
+python3 -m pip install "${user[@]}" 'maturin>=0.11,<0.12'
+if [[ "$VIRTUAL_ENV" == "" ]]; then
+    scripts="$(python3 -m sysconfig | \
+            sed 's@^\tuserbase = "\([^"]\+\)"$@\1/bin@p; d')"
+else
+    scripts="$(python3 -m sysconfig | \
+            sed 's/^\tscripts = "\([^"]\+\)"$/\1/p; d')"
+fi
+echo "$scripts"
+[[ -d "$scripts" ]] || fail "can't find python's \`scripts\` directory"
+rm -f target/wheels/power_instruction_analyzer-*.whl
+"$scripts"/maturin build --compatibility linux \
+                         --cargo-extra-args=--features=python-extension \
+                         -i python3 --release --no-sdist
+python3 -m pip install --force "${user[@]}" \
+                         target/wheels/power_instruction_analyzer-*.whl