From d408ca51ff075ba6adeee17b858d28780aef8f37 Mon Sep 17 00:00:00 2001
From: sickcodes <65906298+sickcodes@users.noreply.github.com>
Date: Mon, 10 Jan 2022 22:37:32 +0000
Subject: [PATCH] Add dumpifs-folderized.sh
Creates folderized IFS dumps keeping directory structure when using dumpifs
---
dumpifs-folderized.sh | 49 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
create mode 100644 dumpifs-folderized.sh
diff --git a/dumpifs-folderized.sh b/dumpifs-folderized.sh
new file mode 100644
index 0000000..2b57958
--- /dev/null
+++ b/dumpifs-folderized.sh
@@ -0,0 +1,49 @@
+#!/bin/bash
+# Author: bertelsmann
+# Original: https://turbo-quattro.com/showthread.php?15648-How-to-extract-a-IFS-file
+# Link: https://turbo-quattro.com/showthread.php?15648-How-to-extract-a-IFS-file&p=367809&viewfull=1#post367809
+# Modified by: @sickcodes
+
+ELEVATED="${ELEVATED:=false}"
+IFSDUMP=dumpifs
+TMPDIR="${PWD}"
+CURDIR="${PWD}"
+IMAGE="${1}"
+
+if ! [ -e "${IMAGE}" ]; then
+ echo "Usage ./script.sh "
+ exit 1
+fi
+
+echo "Dumping contents of ${IMAGE}..."
+${IFSDUMP} -z "${IMAGE}" | awk '{print $3}' > "${TMPDIR}"/ifscont.txt
+${IFSDUMP} -z "${IMAGE}" | grep "\->" | awk '{print $3" -> "$5}' > "${TMPDIR}"/ifslinks.txt
+
+while read -r i; do
+ dirname "${i}"
+done < ifscont.txt > "${TMPDIR}"/dirlist.txt
+
+sort -o "${TMPDIR}"/dirlist.txt "${TMPDIR}"/dirlist.txt
+
+while read -r i; do
+ #create symlinks
+ mkdir -p ./"${i}"
+done < dirlist.txt
+
+while read -r i; do
+ SRC="$(echo -e "$i" | awk '{print $3}')"
+ LNK="$(echo -e "$i" | awk '{print $1}')"
+ LNKDIR="$(dirname "${LNK}")"
+ LNKBASE="$(basename "${LNK}")"
+ cd "${LNKDIR}" || exit
+ ln -s "${SRC}" "${LNKBASE}"
+ cd "${CURDIR}" || exit
+done < "${TMPDIR}"/ifslinks.txt
+
+if [ "${ELEVATED}" == true ]; then
+ sudo ${IFSDUMP} -zx "${IMAGE}"
+else
+ ${IFSDUMP} -zx "${IMAGE}"
+fi
+
+echo "Folder tree created."
\ No newline at end of file