Skip to content

Commit

Permalink
Merge pull request #430 from m-1-k-3/limit
Browse files Browse the repository at this point in the history
Exit of add_partition in L10
  • Loading branch information
m-1-k-3 authored Dec 12, 2022
2 parents 74fdf92 + ac89f03 commit 7c48e8c
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions modules/L10_system_emulation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ create_emulation_filesystem() {

print_output "[*] Identify Qemu Image device for $ORANGE$LOG_PATH_MODULE/$IMAGE_NAME$NC"
DEVICE="$(add_partition_emulation "$LOG_PATH_MODULE/$IMAGE_NAME")"
if [[ "$DEVICE" == "NA" ]]; then
DEVICE="$(add_partition_emulation "$LOG_PATH_MODULE/$IMAGE_NAME")"
fi
if [[ "$DEVICE" == "NA" ]]; then
print_output "[-] No Qemu Image device identified"
return
fi
print_output "[*] Qemu Image device: $ORANGE$DEVICE$NC"
sleep 1
print_output "[*] Device mapper created at $ORANGE${DEVICE}$NC"
Expand Down Expand Up @@ -336,6 +343,13 @@ main_emulation() {
print_output "[*] Processing init file $ORANGE$INIT_FILE$NC ($INDEX/${#INIT_FILES[@]})"
if ! mount | grep -q "$MNT_POINT"; then
DEVICE="$(add_partition_emulation "$LOG_PATH_MODULE/$IMAGE_NAME")"
if [[ "$DEVICE" == "NA" ]]; then
DEVICE="$(add_partition_emulation "$LOG_PATH_MODULE/$IMAGE_NAME")"
fi
if [[ "$DEVICE" == "NA" ]]; then
print_output "[-] No Qemu Image device identified"
break
fi
sleep 1
print_output "[*] Device mapper created at $ORANGE${DEVICE}$NC"
print_output "[*] Mounting QEMU Image Partition 1 to $ORANGE$MNT_POINT$NC"
Expand Down Expand Up @@ -1408,6 +1422,13 @@ write_network_config_to_filesystem() {
#mount filesystem again for network config:
print_output "[*] Identify Qemu Image device for $ORANGE$LOG_PATH_MODULE/$IMAGE_NAME$NC"
DEVICE="$(add_partition_emulation "$LOG_PATH_MODULE/$IMAGE_NAME")"
if [[ "$DEVICE" == "NA" ]]; then
DEVICE="$(add_partition_emulation "$LOG_PATH_MODULE/$IMAGE_NAME")"
fi
if [[ "$DEVICE" == "NA" ]]; then
print_output "[-] No Qemu Image device identified"
return
fi
sleep 1
print_output "[*] Device mapper created at $ORANGE${DEVICE}$NC"
print_output "[*] Mounting QEMU Image Partition 1 to $ORANGE$MNT_POINT$NC"
Expand All @@ -1433,6 +1454,13 @@ nvram_check() {
#mount filesystem again for network config:
print_output "[*] Identify Qemu Image device for $ORANGE$LOG_PATH_MODULE/$IMAGE_NAME$NC"
DEVICE="$(add_partition_emulation "$LOG_PATH_MODULE/$IMAGE_NAME")"
if [[ "$DEVICE" == "NA" ]]; then
DEVICE="$(add_partition_emulation "$LOG_PATH_MODULE/$IMAGE_NAME")"
fi
if [[ "$DEVICE" == "NA" ]]; then
print_output "[-] No Qemu Image device identified"
return
fi
sleep 1

print_output "[*] Device mapper created at $ORANGE${DEVICE}$NC"
Expand Down Expand Up @@ -1928,27 +1956,39 @@ get_binary() {

add_partition_emulation() {
local IMAGE_PATH
local DEV_PATH=""
local DEV_PATH="NA"
local FOUND=false
local CNT=0

losetup -Pf "${1}"
while (! "${FOUND}"); do
sleep 1
((CNT+=1))
local LOSETUP_OUT=()
mapfile -t LOSETUP_OUT < <(losetup | grep -v "BACK-FILE")
for LINE in "${LOSETUP_OUT[@]}"; do
IMAGE_PATH=$(echo "${LINE}" | awk '{print $6}')
if [[ "${IMAGE_PATH}" = "${1}" ]]; then
if [[ "${IMAGE_PATH}" == "${1}" ]]; then
DEV_PATH=$(echo "${LINE}" | awk '{print $1}')p1
if [[ -b "${DEV_PATH}" ]]; then
FOUND=true
fi
fi
done
if [[ "$CNT" -gt 600 ]]; then
# get an exit if nothing happens
break
fi
done

local CNT=0
while (! find "${DEV_PATH}" -ls | grep -q "disk"); do
sleep 1
((CNT+=1))
if [[ "$CNT" -gt 600 ]]; then
# get an exit if nothing happens
break
fi
done
echo "${DEV_PATH}"
}
Expand Down

0 comments on commit 7c48e8c

Please sign in to comment.