From 63eab39255b833c09dd764d37b7e2570a057755d Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Tue, 31 Aug 2021 13:26:26 +0100 Subject: [PATCH] do not use external unauthorised uncontrolled servers. do not run external scripts from completely uncontrolled servers that could be hacked (or terminated, or go offline) --- pia-install | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/pia-install b/pia-install index 5e8ee78..c800176 100755 --- a/pia-install +++ b/pia-install @@ -1,12 +1,52 @@ #!/bin/bash set -e if ! command -v rustup &> /dev/null; then - echo "Rustup could not be found, it can be installed by running the following command: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh" >& 2 + 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 -git clone https://salsa.debian.org/Kazan-team/power-instruction-analyzer.git pia + +# 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 -exec ./libre-soc-install.sh + +# do not use external scripts. + +function fail() +{ + echo "error: $@" >&2 + exit 1 +} + +if [[ "$VIRTUAL_ENV" == "" ]]; then + user=( "--user" ) +else + user=() +fi +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 -- 2.30.2