#!/bin/sh -e

export PATH=/sbin:/bin

mount -t proc proc /proc

if [ ! -d /proc ]; then
  echo E: /proc is not available. >&2
  echo E: this calls for suicide, but I will try to continue... >&2
  exit 0
fi

# we need this in case the keyboard is available as a module, and we want to
# warn about existing suspend partitions during a normal boot.
modprobe i8042 2>/dev/null || true

# load all normal modules
. /loadmodules

# now load suspend2 modules (deprecated)
modprobe suspend_core 2>/dev/null || true
modprobe suspend_block_io 2>/dev/null || true
modprobe suspend_text 2>/dev/null || true
modprobe lzf 2>/dev/null || true
modprobe suspend_lzf 2>/dev/null || true
modprobe suspend_swap 2>/dev/null || true

if [ ! -d /proc/software_suspend ]; then
  echo W: software suspend2 is not available, yet I was asked to set it up. >&2
  echo W: something fishy is going on... >&2
  echo W: trying to skip suspend2 initialisation. >&2
  exit 0
fi

if [ -w /proc/software_suspend/resume2 ]; then
  echo swap:/dev/hda2 > /proc/software_suspend/resume2
fi

if [ -w /proc/software_suspend/do_resume ]; then
  /bin/echo > /proc/software_suspend/do_resume || true
fi

umount /proc 2>/dev/null || true
