Skip to content

Commit

Permalink
convert setup_container and setup_postgres to bash scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewQuijano committed Jul 11, 2024
1 parent b53b906 commit 7d030c6
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 598 deletions.
13 changes: 4 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
ARG BASE_IMAGE="ubuntu:20.04"
ARG BASE_IMAGE="ubuntu:22.04"

### BASE IMAGE
FROM $BASE_IMAGE as base
ARG BASE_IMAGE

ENV DEBIAN_FRONTEND=noninteractive
ENV LLVM_DIR=/usr/lib/llvm-11
ENV PATH="/scripts:${PATH}"

# Copy dependencies lists into container. We copy them all and then do a mv because
# we need to transform base_image into a windows compatible filename which we can't
Expand Down Expand Up @@ -38,13 +39,7 @@ RUN [ -e /tmp/build_dep.txt ] && \
FROM builder as developer

COPY ./tools/ /tools
COPY setup_container.py /
COPY ./scripts /scripts
COPY setup_container.py /setup_container.py

RUN python3 setup_container.py

# RUN cd /tools && \
# cmake -Bbuild -H. -DLLVM_DIR=$LLVM_DIR/lib/cmake/llvm -DClang_DIR=$LLVM_DIR/lib/cmake/clang -DCMAKE_INSTALL_PREFIX=/tools/install

# RUN cd /tools/build && \
# make && \
# make install V=1
49 changes: 0 additions & 49 deletions SETUP.md

This file was deleted.

43 changes: 0 additions & 43 deletions docker/Dockerfile

This file was deleted.

13 changes: 0 additions & 13 deletions docker/requirements.txt

This file was deleted.

34 changes: 5 additions & 29 deletions init-host.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
from colorama import Fore
from colorama import Style

QCOW_URL = "http://panda.moyix.net/~moyix/wheezy_panda2.qcow2"
# if moyix server is down, this image will also work
# QCOW_URL = "https://panda.re/qcows/linux/debian/7.3/x86/debian_7.3_x86.qcow"
QCOW_URL = "https://panda.re/qcows/linux/debian/7.3/x86/debian_7.3_x86.qcow"
QCOW_FILE_NAME = "wheezy_panda2.qcow2"
TAR_URL = "ftp://ftp.astron.com/pub/file/file-5.22.tar.gz"
LAVA_DIR = dirname(abspath(sys.argv[0]))
os.chdir(LAVA_DIR)


def progress(msg):
Expand Down Expand Up @@ -57,20 +55,7 @@ def run(cmd):


def main():
# try to import lava.mak as a config file if not exit
try:
def_lines = (line.strip() for line in open("lava.mak", "r")
if not line.strip().startswith("#")
and line.strip() != "")
def_lines = (line.split(":=") for line in def_lines)
def_lines = ((line[0].strip(), line[1].strip()) for line in def_lines)
LAVA_CONFS = dict(def_lines)
PANDA_BUILD_DIR = LAVA_CONFS["PANDA_BUILD_DIR"]
PANDA_BUILD_DIR = expandvars(PANDA_BUILD_DIR)
print("PANDA_BUILD_DIR Used {}".format(PANDA_BUILD_DIR))
except Exception:
error("Make sure to have properly configured lava.mak \
generated by setup.py")

# parser = argparse.ArgumentParser(description='Setup LAVA')
# parser.add_argument('-s', '--skip_docker_build', action='store_true',
# default = False,
Expand All @@ -93,7 +78,7 @@ def main():
else:
progress("Found existing target_bins/{}".format(basename(TAR_URL)))

if not isfile(join(LAVA_DIR, basename(QCOW_URL))):
if not isfile(join(LAVA_DIR, basename(QCOW_FILE_NAME))):
progress("Downloading {}".format(basename(QCOW_URL)))
run(["wget", "--no-check-certificate", QCOW_URL, "-O", QCOW_FILE_NAME])
else:
Expand All @@ -103,8 +88,7 @@ def main():
progress("Building host.json")
# Build host.json
json_configs = {}
json_configs["qemu"] = join(join(PANDA_BUILD_DIR, "i386-softmmu"),
"qemu-system-i386")
json_configs["qemu"] = "panda-system-i386"
json_configs["qcow_dir"] = LAVA_DIR
json_configs["output_dir"] = join(LAVA_DIR, "target_injections")
json_configs["config_dir"] = join(LAVA_DIR, "target_configs")
Expand All @@ -119,15 +103,7 @@ def main():
else:
progress("Found existing host.json")

# progress("(re)building the fbi")
# os.chdir(join(LAVA_DIR, "tools", "build", "fbi"))
# run(["make", "install", "-j4"])

# progress("(re)building lavaTool")
# os.chdir(join(LAVA_DIR, "tools", "build", "lavaTool"))
# run(["./compile-on-docker.sh"])

progress("Sucessful! Now run:\n $ scripts/lava.sh -ak file")
progress("Successful! Now run:\n $ scripts/lava.sh -ak file")
return 0


Expand Down
4 changes: 2 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ progress "Installed build dependencies"
$SUDO pip3 install --upgrade pip

# This seems to be the better replacement to have all python packages
$SUDO pip3 install -r docker/requirements.txt
$SUDO pip3 install -r requirements.txt
progress "Installed Python requirements"

$SUDO python3 setup_container.py
./setup_container.sh

progress "Installed LAVA"
9 changes: 9 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
colorama
db
ipython
lockfile
numpy
pandare
PyYAML
SQLAlchemy
tabulate
6 changes: 0 additions & 6 deletions scripts/manual_lava.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import re
import sys
import random
import subprocess as sp
import sys

# ok this is gross
sys.path.append("/home/tleek/git/panda-leet/panda/scripts")

from pandare.plog_reader import PLogReader

#
Expand Down
24 changes: 24 additions & 0 deletions scripts/setup_postgres.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
set -ex

PGPASS="${HOME}/.pgpass"

if [ ! -f "${PGPASS}" ]; then
postgres_depends=$(dpkg-query -W -f='${depends}' 'postgresql')
postgres_pkg=$(echo "${postgres_depends}" | grep -oP 'postgresql-[0-9]+.?[0-9]+')
postgres_version=${postgres_pkg/postgresql-/}
pg_hba="/etc/postgresql/${postgres_version}/main/pg_hba.conf"
postgres_password='postgrespostgres'

sudo sed -i.bak -E 's/^(local\s+all\s+postgres\s+)md5$/\1peer/' "${pg_hba}"
sudo service postgresql reload

password_sql="ALTER USER postgres WITH PASSWORD '${postgres_password}';"
sudo -u postgres psql -c "${password_sql}"

echo "*:*:*:postgres:${postgres_password}" > "${PGPASS}"
chmod 600 "${PGPASS}"

sudo sed -i.bak -E 's/^(local\s+all\s+postgres\s+)peer$/\1md5/' "${pg_hba}"
sudo service postgresql reload
fi
Loading

0 comments on commit 7d030c6

Please sign in to comment.