shellcheck: fix lint of scripts in tests

This commit is contained in:
Otto Sabart
2022-08-16 21:00:00 +02:00
committed by Erik Arvstedt
parent a59c3b4b8a
commit f184bb34e6
14 changed files with 82 additions and 59 deletions

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env bash
set -euo pipefail
if [[ ! -v NIX_BITCOIN_EXAMPLES_DIR ]]; then
echo "Running script in nix shell env..."
@@ -9,16 +10,16 @@ else
fi
tmpDir=$(mktemp -d /tmp/nix-bitcoin-minimal-container.XXX)
trap "rm -rf $tmpDir" EXIT
trap 'rm -rf $tmpDir' EXIT
# Modify importable-configuration.nix to use the local <nix-bitcoin>
# source instead of fetchTarball
<importable-configuration.nix sed '
s|nix-bitcoin = .*|nix-bitcoin = toString <nix-bitcoin>;|;
s|system.extraDependencies = .*||
' > $tmpDir/importable-configuration.nix
' > "$tmpDir/importable-configuration.nix"
cat > $tmpDir/configuration.nix <<EOF
cat > "$tmpDir/configuration.nix" <<EOF
{
imports = [ $tmpDir/importable-configuration.nix ];
users.users.main = {
@@ -30,4 +31,4 @@ cat > $tmpDir/configuration.nix <<EOF
}
EOF
"${BASH_SOURCE[0]%/*}/deploy-container.sh" $tmpDir/configuration.nix "$@"
"${BASH_SOURCE[0]%/*}/deploy-container.sh" "$tmpDir/configuration.nix" "$@"

View File

@@ -75,7 +75,7 @@ fi
# Build container.
# Learn more: https://github.com/erikarvstedt/extra-container
#
read -d '' src <<EOF || true
read -rd '' src <<EOF || true
{ pkgs, lib, ... }: {
containers.demo-node = {
extra.addressPrefix = "10.250.0";

View File

@@ -24,7 +24,7 @@ source qemu-vm/run-vm.sh
echo "Building the target VM"
# Build the initial VM to which the nix-bitcoin node is deployed via krops
nix-build --out-link $tmpDir/vm - <<'EOF'
nix-build --out-link "$tmpDir/vm" - <<'EOF'
(import <nixpkgs/nixos> {
configuration = { config, lib, ... }: {
imports = [ <qemu-vm/vm-config.nix> ];
@@ -43,11 +43,11 @@ vmNumCPUs=4
vmMemoryMiB=2048
sshPort=60734
# Start the VM in the background
runVM $tmpDir/vm $vmNumCPUs $vmMemoryMiB $sshPort
runVM "$tmpDir/vm" "$vmNumCPUs" "$vmMemoryMiB" "$sshPort"
# Build the krops deploy script
export sshPort
nix-build --out-link $tmpDir/krops-deploy - <<'EOF'
nix-build --out-link "$tmpDir/krops-deploy" - <<'EOF'
let
krops = (import <nix-bitcoin> {}).krops;
@@ -85,7 +85,7 @@ EOF
echo "Building the nix-bitcoin node"
# Pre-build the nix-bitcoin node outside of the VM to save some time
nix-build --out-link $tmpDir/store-paths -E '
nix-build --out-link "$tmpDir/store-paths" -E '
let
system = (import <nixpkgs/nixos> { configuration = <krops-vm-configuration.nix>; }).system;
pkgsUnstable = (import <nix-bitcoin/pkgs/nixpkgs-pinned.nix>).nixpkgs-unstable;
@@ -98,7 +98,7 @@ vmWaitForSSH
# Add the store paths that include the nix-bitcoin node
# to the nix store db in the VM
c "nix-store --load-db < $(realpath $tmpDir/store-paths)/registration"
c "nix-store --load-db < $(realpath "$tmpDir/store-paths")/registration"
echo
echo "Generate secrets"
@@ -106,7 +106,7 @@ nix-shell --run generate-secrets
echo
echo "Deploy with krops"
$tmpDir/krops-deploy
"$tmpDir/krops-deploy"
echo
echo "Bitcoind service:"

View File

@@ -22,7 +22,7 @@ fi
source qemu-vm/run-vm.sh
echo "Building VM"
nix-build --out-link $tmpDir/vm - <<'EOF'
nix-build --out-link "$tmpDir/vm" - <<'EOF'
(import <nixpkgs/nixos> {
configuration = {
imports = [
@@ -37,7 +37,7 @@ EOF
vmNumCPUs=4
vmMemoryMiB=2048
sshPort=60734
runVM $tmpDir/vm $vmNumCPUs $vmMemoryMiB $sshPort
runVM "$tmpDir/vm" "$vmNumCPUs" "$vmMemoryMiB" "$sshPort"
vmWaitForSSH
printf "Waiting until services are ready"

View File

@@ -1,22 +1,23 @@
qemuDir=$(cd "${BASH_SOURCE[0]%/*}" && pwd)
# shellcheck disable=SC1091
source "$qemuDir/wait-until.sh"
tmpDir=/tmp/nix-bitcoin-qemu-vm
mkdir -p $tmpDir
mkdir -p "$tmpDir"
# Cleanup on exit
cleanup() {
set +eu
if [[ $qemuPID ]]; then
kill -9 $qemuPID
kill -9 "$qemuPID"
fi
rm -rf $tmpDir
rm -rf "$tmpDir"
}
trap "cleanup" EXIT
identityFile=$qemuDir/id-vm
chmod 0600 $identityFile
chmod 0600 "$identityFile"
runVM() {
vm=$1
@@ -24,9 +25,10 @@ runVM() {
vmMemoryMiB=$3
sshPort=$4
export NIX_DISK_IMAGE=$tmpDir/img
export QEMU_NET_OPTS=hostfwd=tcp::$sshPort-:22
</dev/null $vm/bin/run-*-vm -m $vmMemoryMiB -smp $vmNumCPUs &>/dev/null &
export NIX_DISK_IMAGE="$tmpDir/img"
export QEMU_NET_OPTS="hostfwd=tcp::${sshPort}-:22"
# shellcheck disable=SC2211
</dev/null "$vm"/bin/run-*-vm -m "$vmMemoryMiB" -smp "$vmNumCPUs" &>/dev/null &
qemuPID=$!
}
@@ -39,7 +41,7 @@ vmWaitForSSH() {
# Run command in VM
c() {
ssh -p $sshPort -i $identityFile -o ConnectTimeout=1 \
ssh -p "$sshPort" -i "$identityFile" -o ConnectTimeout=1 \
-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR \
-o ControlMaster=auto -o ControlPath=$tmpDir/ssh-connection -o ControlPersist=60 \
root@127.0.0.1 "$@"

View File

@@ -11,6 +11,8 @@ c systemctl status bitcoind
# BASH_ENVIRONMENT contains definitions of read-only variables like 'BASHOPTS' that
# cause warnings on evaluation. Suppress these warnings while sourcing.
#
# shellcheck disable=SC2016
BASH_ENVIRONMENT=<(declare -p; declare -pf) \
USAGE_INFO="$USAGE_INFO" \
bash --rcfile <(echo '