This script is probably a good starting point, I use it to cleanly shutdown devices if I need to store them - it's ripped off/adapted from the script used to put a device into shipping mode:
Code:
#!/bin/sh
# shutdown.sh
# Simple shutdown script based on /etc/upstart/shutdown_special
source /etc/upstart/functions
source /etc/upstart/upstart_functions
set_background() {
fbink -c -f
if [ -f /tmp/bg_shipping.png ]; then
bg_img=/tmp/bg_shipping.png
else
bg_img=/usr/share/blanket/shutdown/bg_shipping.png
fi
fbink -g file=$bg_img
}
shutdown_device() {
echo "shutdown" > /tmp/shutdown_in_progress
f_log I shutdown "closing password dialog"
killall -q -s KILL passwdlg || true
f_upstart_job_stop_timeout 60 "x wifid wifis lab126 framework sshd usbnetd testd" || \
f_log W shutdown "stop_failed" "type=services" "continuing"
# Shutdown the filesystems
f_upstart_job_stop_timeout 30 "filesystems" || f_log W shutdown "stop_failed" "type=filesystems" "continuing"
#
# Logging went down with filesystems, the following only prints to console
#
# Make sure rootfs is readonly (it should be already)
f_log I shutdown "mounting root filesystem read-only"
sync || true
mntroot ro || true
# Sync the filesystems
f_log I shutdown "syncing disks"
sync || true
echo 3 > /proc/sys/vm/drop_caches || true
f_log I shutdown "wait for additional 5 seconds to ensure all files have been written to disks"
sleep 5
poweroff -f
}
main() {
set_background
shutdown_device
}
main