etc.git


etc

~ scripts and random things
git clone https://github.com/djnnvx/etc.git
log | files | refs | archive

cleanup.sh (1424B)

      1 #!/bin/bash
      2 # cleanup.sh - kill fuzzers and remove artifacts.
      3 # Usage: bash cleanup.sh [--keep-corpus] [--keep-builds] [--keep-source] [--crashes-only]
      4 set -uo pipefail
      5 
      6 SCRIPT_DIR="$(cd "$(dirname "${0}")" && pwd)"
      7 cd "${SCRIPT_DIR}"
      8 
      9 SESSION="libnfs-fuzz"
     10 KEEP_CORPUS=0 KEEP_BUILDS=0 KEEP_SOURCE=0 CRASHES_ONLY=0
     11 
     12 for arg in "$@"; do
     13     case "${arg}" in
     14         --keep-corpus)  KEEP_CORPUS=1  ;;
     15         --keep-builds)  KEEP_BUILDS=1  ;;
     16         --keep-source)  KEEP_SOURCE=1  ;;
     17         --crashes-only) CRASHES_ONLY=1 ;;
     18         *) echo "[!] Unknown option: ${arg}" >&2 ;;
     19     esac
     20 done
     21 
     22 log() { echo "[*] $*"; }
     23 ok()  { echo "[+] $*"; }
     24 
     25 tmux kill-session -t "${SESSION}" 2>/dev/null || true
     26 
     27 pkill -u "$(id -un)" -f "afl-fuzz.*fuzz_" 2>/dev/null || true
     28 for h in fuzz_nfs3 fuzz_nfs4 fuzz_mount fuzz_pdu; do
     29     pkill -u "$(id -un)" -f "${h}" 2>/dev/null || true
     30 done
     31 
     32 [[ "${CRASHES_ONLY}" -eq 1 ]] && { ok "Processes killed."; exit 0; }
     33 
     34 if [[ "${KEEP_BUILDS}" -eq 0 ]]; then
     35     for h in fuzz_nfs3 fuzz_nfs4 fuzz_mount fuzz_pdu; do
     36         rm -f "${h}" "${h}.cmplog" "${h}.repro"
     37     done
     38     rm -rf build-cls build-cmplog build-plain
     39     ok "Binaries and build dirs removed."
     40 fi
     41 
     42 if [[ "${KEEP_CORPUS}" -eq 0 ]]; then
     43     rm -rf corpus/ output/
     44     ok "Corpus and output removed."
     45 fi
     46 
     47 if [[ "${KEEP_SOURCE}" -eq 0 ]]; then
     48     rm -rf libnfs-src/ AFLplusplus/ afl-build/
     49     ok "Source trees removed."
     50 fi
     51 
     52 ok "Done."