about summary refs log tree commit diff
path: root/nyx_mode/build_nyx_support.sh
blob: fda4ec12b27e8519ec3db35c3b29c1a66f3e271b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash

set -e

echo "================================================="
echo "           Nyx build script"
echo "================================================="
echo

echo "[*] Performing basic sanity checks..."

if [ "$CI" = "true" ]; then

  echo "[-] Error: nyx_mode cannot be tested in the Github CI, skipping ..."
  exit 0

fi


if [ -n "$NO_NYX" ]; then

  echo "[-] Error: the NO_NYX environment variable is set, please unset."
  exit 0

fi

if [ ! "$(uname -s)" = "Linux" ]; then

  echo "[-] Error: Nyx mode is only available on Linux."
  exit 0

fi

if [ ! "$(uname -m)" = "x86_64" ]; then

  echo "[-] Error: Nyx mode is only available on x86_64 (yet)."
  exit 0

fi

cargo help > /dev/null 2>&1 || {
   echo "[-] Error: Rust is not installed."
   exit 0
}

echo "[*] Making sure all Nyx is checked out"


if git status 1>/dev/null 2>&1; then

  set +e
  git submodule init
  echo "[*] initializing QEMU-Nyx submodule"
  git submodule update ./QEMU-Nyx 2>/dev/null # ignore errors
  echo "[*] initializing packer submodule"
  git submodule update ./packer 2>/dev/null # ignore errors
  echo "[*] initializing libnyx submodule"
  git submodule update ./libnyx 2>/dev/null # ignore errors
  set -e

else

  test -d QEMU-Nyx/.git || git clone https://github.com/nyx-fuzz/qemu-nyx QEMU-Nyx
  test -d packer/.git || git clone https://github.com/nyx-fuzz/packer
  test -d libnyx/.git || git clone https://github.com/nyx-fuzz/libnyx

fi

test -e packer/.git || { echo "[-] packer not checked out, please install git or check your internet connection." ; exit 1 ; }
test -e libnyx/.git || { echo "[-] libnyx not checked out, please install git or check your internet connection." ; exit 1 ; }
test -e QEMU-Nyx/.git || { echo "[-] QEMU-Nyx not checked out, please install git or check your internet connection." ; exit 1 ; }


QEMU_NYX_VERSION="$(cat ./QEMU_NYX_VERSION)"
cd "./QEMU-Nyx" || exit 1
if [ -n "$NO_CHECKOUT" ]; then
  echo "[*] Skipping checkout to $QEMU_NYX_VERSION"
else
  echo "[*] Checking out $QEMU_NYX_VERSION"
  set +e
  sh -c 'git stash' 1>/dev/null 2>/dev/null
  git pull 1>/dev/null 2>/dev/null
  git checkout "$QEMU_NYX_VERSION" || echo Warning: could not check out to commit $QEMU_NYX_VERSION
  set -e
fi
cd - > /dev/null

PACKER_VERSION="$(cat ./PACKER_VERSION)"
cd "./packer" || exit 1
if [ -n "$NO_CHECKOUT" ]; then
  echo "[*] Skipping checkout to $PACKER_VERSION"
else
  echo "[*] Checking out $PACKER_VERSION"
  set +e
  sh -c 'git stash' 1>/dev/null 2>/dev/null
  git pull 1>/dev/null 2>/dev/null
  git checkout "$PACKER_VERSION" || echo Warning: could not check out to commit $PACKER_VERSION
  set -e
fi
cd - > /dev/null

LIBNYX_VERSION="$(cat ./LIBNYX_VERSION)"
cd "./libnyx/" || exit 1
if [ -n "$NO_CHECKOUT" ]; then
  echo "[*] Skipping checkout to $LIBNYX_VERSION"
else
  echo "[*] Checking out $LIBNYX_VERSION"
  set +e
  sh -c 'git stash' 1>/dev/null 2>/dev/null
  git pull 1>/dev/null 2>/dev/null
  git checkout "$LIBNYX_VERSION" || echo Warning: could not check out to commit $LIBNYX_VERSION
  set -e
fi
cd - > /dev/null

echo "[*] checking packer init.cpio.gz ..."
(cd packer/linux_initramfs/ && sh pack.sh)

echo "[*] Checking libnyx ..."
(cd libnyx/libnyx && cargo build --release)

echo "[*] Checking QEMU-Nyx ..."
(cd QEMU-Nyx && ./compile_qemu_nyx.sh static )

echo "[*] Checking libnyx.so ..."
cp libnyx/libnyx/target/release/liblibnyx.so ../libnyx.so

echo "[+] All done for nyx_mode, enjoy!"

exit 0