mirror of
https://github.com/motioneye-project/motioneyeos.git
synced 2025-07-29 14:16:31 +00:00
writeimage.sh: cosmetic changes
This commit is contained in:
parent
cf35f56719
commit
3a6e99b664
@ -1,5 +1,6 @@
|
|||||||
#!/bin/bash -e
|
#!/bin/bash -e
|
||||||
|
|
||||||
|
|
||||||
function usage() {
|
function usage() {
|
||||||
echo "Usage: $0 [options...]" 1>&2
|
echo "Usage: $0 [options...]" 1>&2
|
||||||
echo ""
|
echo ""
|
||||||
@ -16,40 +17,33 @@ function msg() {
|
|||||||
echo "$(date) $1"
|
echo "$(date) $1"
|
||||||
}
|
}
|
||||||
|
|
||||||
# use this function to unmount regardless of MAC OS or not
|
function smart_unmount() {
|
||||||
function smartUnmount() {
|
msg "Unmounting $1"
|
||||||
msg "Unmounting $1"
|
|
||||||
|
|
||||||
# if MAC OS
|
if [ `uname` == "Darwin" ]; then # if macOS
|
||||||
if [ `uname` == "Darwin" ]; then
|
diskutil unmountDisk $1
|
||||||
diskutil unmountDisk $1
|
else # assuming Linux
|
||||||
else # assuming Linux
|
umount $1* >/dev/null 2>&1
|
||||||
# unmount sdcard
|
fi
|
||||||
umount $1* >/dev/null 2>&1
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# use this function to mount regardless of MAC OS or not
|
function smart_mount() {
|
||||||
function smartMount() {
|
msg "Mounting $1"
|
||||||
msg "Mounting $1"
|
|
||||||
|
|
||||||
# if MAC OS
|
if [ `uname` == "Darwin" ]; then # if macOS
|
||||||
if [ `uname` == "Darwin" ]; then
|
diskutil mountDisk $1
|
||||||
diskutil mountDisk $1
|
else # assuming Linux
|
||||||
else # assuming Linux
|
mount $1* >/dev/null 2>&1
|
||||||
# unmount sdcard
|
fi
|
||||||
umount $1* >/dev/null 2>&1
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# This function will be ran upon script EXIT (using trap)
|
# this function will be run upon script exit (using trap)
|
||||||
function cleanup {
|
function cleanup {
|
||||||
msg "Performing cleanup"
|
msg "Performing cleanup"
|
||||||
|
|
||||||
set +e
|
set +e
|
||||||
|
|
||||||
# unmount sdcard
|
smart_unmount ${SDCARD_DEV}
|
||||||
smartUnmount ${SDCARD_DEV}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ -z "$1" ]; then
|
if [ -z "$1" ]; then
|
||||||
@ -112,7 +106,7 @@ if [[ $DISK_IMG == *.gz ]]; then
|
|||||||
DISK_IMG=${DISK_IMG::-3}
|
DISK_IMG=${DISK_IMG::-3}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
smartUnmount ${SDCARD_DEV}
|
smart_unmount ${SDCARD_DEV}
|
||||||
msg "writing disk image to sdcard"
|
msg "writing disk image to sdcard"
|
||||||
dd if=$DISK_IMG of=$SDCARD_DEV bs=1048576
|
dd if=$DISK_IMG of=$SDCARD_DEV bs=1048576
|
||||||
sync
|
sync
|
||||||
@ -124,19 +118,15 @@ fi
|
|||||||
|
|
||||||
mkdir -p $BOOT
|
mkdir -p $BOOT
|
||||||
|
|
||||||
if [ `uname` == "Darwin" ]; then
|
if [ `uname` == "Darwin" ]; then # if macOS
|
||||||
BOOT_DEV=${SDCARD_DEV}s1 # e.g. /dev/disk4s1
|
BOOT_DEV=${SDCARD_DEV}s1 # e.g. /dev/disk4s1
|
||||||
|
|
||||||
# mount the disk
|
# mount the disk
|
||||||
hdiutil attach ${BOOT_DEV}
|
hdiutil attach ${BOOT_DEV}
|
||||||
|
else # assuming Linux
|
||||||
BOOT=$(pwd)/.boot
|
BOOT_DEV=${SDCARD_DEV}p1 # e.g. /dev/mmcblk0p1
|
||||||
|
|
||||||
echo "set BOOT for MAC to $BOOT"
|
|
||||||
else # assuming Linux
|
|
||||||
BOOT_DEV=${SDCARD_DEV}p1 # e.g. /dev/mmcblk0p1
|
|
||||||
if ! [ -e ${SDCARD_DEV}p1 ]; then
|
if ! [ -e ${SDCARD_DEV}p1 ]; then
|
||||||
BOOT_DEV=${SDCARD_DEV}1 # e.g. /dev/sdc1
|
BOOT_DEV=${SDCARD_DEV}1 # e.g. /dev/sdc1
|
||||||
fi
|
fi
|
||||||
mount $BOOT_DEV $BOOT
|
mount $BOOT_DEV $BOOT
|
||||||
fi
|
fi
|
||||||
@ -184,22 +174,22 @@ if [ -n "$IP" ] && [ -n "$GW" ] && [ -n "$DNS" ]; then
|
|||||||
echo "static_dns=\"$DNS\"" >> $conf
|
echo "static_dns=\"$DNS\"" >> $conf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ `uname` == "Darwin" ]; then
|
if [ `uname` == "Darwin" ]; then # if macOS
|
||||||
# copy created files over to the disk
|
# copy created files over to the disk
|
||||||
DISK_PARTITION=`diskutil info $BOOT_DEV | grep "Mount Point:" | sed 's/^[^/]*//' | sed 's/ /\\ /g'`
|
DISK_PARTITION=`diskutil info $BOOT_DEV | grep "Mount Point:" | sed 's/^[^/]*//' | sed 's/ /\\ /g'`
|
||||||
|
|
||||||
echo "moving $BOOT/* to $DISK_PARTITION"
|
echo "moving $BOOT/* to $DISK_PARTITION"
|
||||||
|
mv -v "$BOOT"/* "$DISK_PARTITION"
|
||||||
|
|
||||||
mv -v "$BOOT"/* "$DISK_PARTITION"
|
sync
|
||||||
|
smart_unmount ${SDCARD_DEV}
|
||||||
|
rmdir $BOOT
|
||||||
|
diskutil eject ${SDCARD_DEV}
|
||||||
|
|
||||||
sync
|
else # assuming Linux
|
||||||
smartUnmount ${SDCARD_DEV}
|
sync
|
||||||
rmdir $BOOT
|
smart_unmount $BOOT
|
||||||
diskutil eject ${SDCARD_DEV}
|
rmdir $BOOT
|
||||||
else
|
|
||||||
sync
|
|
||||||
smartUnmount $BOOT
|
|
||||||
rmdir $BOOT
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
msg "***you can now remove the sdcard***"
|
msg "***you can now remove the sdcard***"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user