Skip to content

Commit

Permalink
update base.img with raspbian-lite
Browse files Browse the repository at this point in the history
  • Loading branch information
VertexC committed Jun 1, 2019
1 parent ae5d2b3 commit 3e741c2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
16 changes: 9 additions & 7 deletions bin/create_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# - wlan config (optional)
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
LOG="${DIR}/${1}_$(date +%d-%m-%Y-%H-%M-%S)_output.txt"
PROGRESS="${DIR}/${1}_progress.txt"
PROGRESS="${DIR}/${1}_$(date +%d-%m-%Y-%H-%M-%S)_progress.txt"
IMAGE_DIR="${DIR}/../honeypot_images"
echo "0" > "${PROGRESS}"
echo "" > "${LOG}"
Expand All @@ -26,8 +26,8 @@ if [ -a "${IMAGE_DIR}/${2}" ]; then
rm "${IMAGE_DIR}/${2}" >> "${LOG}" 2>&1
fi
# Copy base to new name
echo "Creating 1.5GB image in ${IMAGE_DIR}/${2}" >> "${LOG}" 2>&1
dd bs=1M count=1536 if=/dev/zero of="${IMAGE_DIR}/${2}" >> "${LOG}" 2>&1
echo "Creating 3GB image in ${IMAGE_DIR}/${2}" >> "${LOG}" 2>&1
dd bs=1M count=3072 if=/dev/zero of="${IMAGE_DIR}/${2}" >> "${LOG}" 2>&1
echo "5" > "${PROGRESS}"
echo "Finished creation, creating loop devices" >> "${LOG}" 2>&1
losetup -f "${IMAGE_DIR}/base.img" >> "${LOG}" 2>&1
Expand All @@ -41,8 +41,10 @@ echo "Parted partition reorganisation" >> "${LOG}" 2>&1
parted -s "${NEW_LD}" rm 2 >> "${LOG}" 2>&1
parted -s "${NEW_LD}" mkpart primary 64 1611 >> "${LOG}" 2>&1
echo "20" > "${PROGRESS}"
echo "Creating loopback device for root partition" >> "${LOG}" 2>&1
losetup -f -o 64028672 "${IMAGE_DIR}/${2}" >> "${LOG}" 2>&1
echo "Get the image size" >> "${LOG}" 2>&1
imageSize=$(python ${DIR}/getImageSize.py ${IMAGE_DIR}/base.img)
echo "Creating loopback device for root partition with offset ${imageSize}" >> "${LOG}" 2>&1
losetup -f -o ${imageSize} "${IMAGE_DIR}/${2}" >> "${LOG}" 2>&1
ROOT_LD=$(losetup -a | grep "${2}" | grep "offset" | sed 's/\(.*\): .*/\1/')
echo "Checking partition ${ROOT_LD}" >> "${LOG}" 2>&1
e2fsck -f -y "${ROOT_LD}" >> "${LOG}" 2>&1
Expand All @@ -58,7 +60,7 @@ if [ ! -d /mnt/tmp/ ]; then
fi
echo "Mounting image" >> "${LOG}" 2>&1
# Mount image on temp folder
mount -o loop,offset=64028672 "${IMAGE_DIR}/${2}" /mnt/tmp/ >> "${LOG}" 2>&1
mount -o loop,offset=${imageSize} "${IMAGE_DIR}/${2}" /mnt/tmp/ >> "${LOG}" 2>&1
echo "Mounting proc & sys" >> "${LOG}" 2>&1
# Assign proc & sysfs
mount proc /mnt/tmp/proc -t proc >> "${LOG}" 2>&1
Expand Down Expand Up @@ -94,4 +96,4 @@ echo "Unmount /mnt/tmp" >> "${LOG}" 2>&1
umount /mnt/tmp >> "${LOG}" 2>&1
echo "Unmounted, created image should be ready now" >> "${LOG}" 2>&1
echo "100" > "${PROGRESS}"
echo "Total runtime: ${SECONDS}" >> "${LOG}" 2>&1
echo "Total runtime: ${SECONDS}" >> "${LOG}" 2>&1
13 changes: 13 additions & 0 deletions bin/getImageSize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import sys
import subprocess
import os

def getImageSize(image):
info = subprocess.check_output(["fdisk", "-lu", image]).decode("utf-8")
size = info.split('\n')[-2].split()[1]
return int(size) * 512

if __name__ == "__main__":
args = sys.argv[1:]
image = args[0]
sys.stdout.write("%s\n" % getImageSize(image))
13 changes: 9 additions & 4 deletions install/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,15 @@ ln -s /etc/nginx/sites-available/pipot /etc/nginx/sites-enabled/pipot >> "$insta
echo "* Reloading nginx"
service nginx reload >> "$install_log" 2>&1
echo "* Downloading base image"
wget https://sourceforge.net/projects/minibian/files/2016-03-12-jessie-minibian.tar.gz >> "$install_log" 2>&1
tar -xvf 2016-03-12-jessie-minibian.tar.gz >> "$install_log" 2>&1
rm 2016-03-12-jessie-minibian.tar.gz >> "$install_log" 2>&1
mv 2016-03-12-jessie-minibian.img "${dir}/../honeypot_images/base.img" >> "$install_log" 2>&1
# wget https://sourceforge.net/projects/minibian/files/2016-03-12-jessie-minibian.tar.gz >> "$install_log" 2>&1
# tar -xvf 2016-03-12-jessie-minibian.tar.gz >> "$install_log" 2>&1
# rm 2016-03-12-jessie-minibian.tar.gz >> "$install_log" 2>&1
# mv 2016-03-12-jessie-minibian.img "${dir}/../honeypot_images/base.img" >> "$install_log" 2>&1
wget https://downloads.raspberrypi.org/raspbian_lite_latest >> "$install_log" 2>&1
mv raspbian_lite_latest raspbian_lite_latest.zip
unzip -o raspbian_lite_latest.zip >> "$install_log" 2>&1
rm raspbian_lite_latest.zip >> "$install_log" 2>&1
mv *raspbian-stretch-lite.img "${dir}/../honeypot_images/base.img" >> "$install_log" 2>&1
echo ""
echo "* Starting PiPot..."
service pipot start
Expand Down

0 comments on commit 3e741c2

Please sign in to comment.