#!/usr/bin/haserl
<%in p/common.cgi %>
<% page_title="SDcard" %>
<%in p/header.cgi %>
<% if [ ! -e /dev/mmcblk0 ]; then %>
SDcard is not available.
Make sure the card is correctly inserted.
<% else %>
<%
card_device="/dev/mmcblk0"
card_partition="${card_device}p1"
mount_point="${card_partition//dev/mnt}"
error=""
_o=""
%>
<% if [ -n "$POST_doFormatCard" ]; then %>
SDcard formatting takes time.
Please do not refresh this page. Wait until partition formatting is finished!
<%
if [ "$(grep $card_partition /etc/mtab)" ]; then
_c="umount $card_partition"
_o="${_o}\n${_c}\n$($_c 2>&1)"
[ $? -ne 0 ] && error="Cannot unmount SDcard partition."
fi
if [ -z "$error" ]; then
_c="mkfs.vfat $card_partition"
_o="${_o}\n${_c}\n$($_c 2>&1)"
[ $? -ne 0 ] && error="Cannot format SDcard partition."
fi
if [ -z "$error" ] && [ ! -d "$mount_point" ]; then
_c="mkdir -p $mount_point"
_o="${_o}\n${_c}\n$($_c 2>&1)"
[ $? -ne 0 ] && error="Cannot create SDcard mount point."
fi
if [ -z "$error" ]; then
_c="mount -t vfat $card_partition $mount_point"
_o="${_o}\n${_c}\n$($_c 2>&1)"
[ $? -ne 0 ] && error="Cannot remount SDcard partition."
fi
if [ -n "$error" ]; then
report_error "$error"
[ -n "$_c" ] && report_command "$_c" "$_o"
else
report_log "$_o"
fi
%>
Return
<% else %>
SDcard partitions
<%
partitions=$(df -h | grep 'dev/mmc')
echo "${partitions}"
%>
<% if [ -n "$partitions" ]; then %>
Browse files on these partitions
<%
IFS=$'\n'
for i in $partitions; do
_mount=$(echo $i | awk '{print $6}')
echo "
${_mount}"
unset _mount
done
IFS=$IFS_ORIG
unset _partitions
%>
<% fi %>
Format SDcard
ATTENTION! Formatting will destroy all data on the SDcard.
Make sure you have a backup copy if you are going to use the data in the future.
<% fi %>
<% fi %>
<%in p/footer.cgi %>