xref: /OK3568_Linux_fs/buildroot/package/pm-utils/00pm-utils (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun#!/bin/sh
2*4882a593Smuzhiyun# vim: noexpandtab
3*4882a593Smuzhiyun#
4*4882a593Smuzhiyun# Copyright (C) 2022, Rockchip Electronics Co., Ltd
5*4882a593Smuzhiyun#
6*4882a593Smuzhiyun# Based on pm-utils-1.4.1's pm-action.
7*4882a593Smuzhiyun#
8*4882a593Smuzhiyun# This program is free software; you can redistribute it and/or modify
9*4882a593Smuzhiyun# it under the terms of version 2 of the GNU General Public License as
10*4882a593Smuzhiyun# published by the Free Software Foundation.
11*4882a593Smuzhiyun#
12*4882a593Smuzhiyun# This program is distributed in the hope that it will be useful,
13*4882a593Smuzhiyun# but WITHOUT ANY WARRANTY; without even the implied warranty of
14*4882a593Smuzhiyun# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*4882a593Smuzhiyun# GNU General Public License for more details.
16*4882a593Smuzhiyun#
17*4882a593Smuzhiyun# You should have received a copy of the GNU General Public License
18*4882a593Smuzhiyun# along with this program; if not, write to the Free Software
19*4882a593Smuzhiyun# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20*4882a593Smuzhiyun#
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun[ -d "/usr/lib/pm-utils/" ] || exit 0
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun# The rule here? Simplicity.
25*4882a593Smuzhiyunexport STASHNAME=pm-suspend
26*4882a593Smuzhiyunexport STAGE="${1:-pre}"
27*4882a593Smuzhiyunexport METHOD="${2:-suspend}"
28*4882a593Smuzhiyun. "/usr/lib/pm-utils/pm-functions"
29*4882a593Smuzhiyun
30*4882a593Smuzhiyuncase "$METHOD" in
31*4882a593Smuzhiyun	suspend*)	ACTION=suspend;   REVERSE=resume ;;
32*4882a593Smuzhiyun	hibernate) 	ACTION=hibernate; REVERSE=thaw ;;
33*4882a593Smuzhiyun	*)		exit 1 ;;
34*4882a593Smuzhiyunesac
35*4882a593Smuzhiyun
36*4882a593Smuzhiyunremove_suspend_lock()
37*4882a593Smuzhiyun{
38*4882a593Smuzhiyun	release_lock "${STASHNAME}.lock"
39*4882a593Smuzhiyun}
40*4882a593Smuzhiyun
41*4882a593Smuzhiyuntry_lock "${STASHNAME}.lock" || exit 1
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun# make sure we release the lock no matter how we exit
44*4882a593Smuzhiyuntrap remove_suspend_lock 0
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun# clean up from the last run
47*4882a593Smuzhiyunrm -rf "${STORAGEDIR}"
48*4882a593Smuzhiyunmkdir -p "${STORAGEDIR}"
49*4882a593Smuzhiyun# save our parameter list.
50*4882a593Smuzhiyun[ -f "$PARAMETERS" ] || echo '' >"$PARAMETERS"
51*4882a593Smuzhiyunadd_parameters $PM_CMDLINE
52*4882a593Smuzhiyunupdate_parameters
53*4882a593Smuzhiyun
54*4882a593Smuzhiyuninit_logfile "${PM_LOGFILE}"
55*4882a593Smuzhiyunlog "Initial commandline parameters: $PM_CMDLINE"
56*4882a593Smuzhiyunload_hook_blacklist
57*4882a593Smuzhiyunload_hook_parameters
58*4882a593Smuzhiyun
59*4882a593Smuzhiyuncase "$STAGE" in
60*4882a593Smuzhiyun	pre)
61*4882a593Smuzhiyun		log "$(date): Running hooks for $ACTION."
62*4882a593Smuzhiyun		run_hooks sleep "$ACTION $METHOD"
63*4882a593Smuzhiyun		log "$(date): performing $METHOD"
64*4882a593Smuzhiyun		;;
65*4882a593Smuzhiyun	post)
66*4882a593Smuzhiyun		log "$(date): Running hooks for $REVERSE"
67*4882a593Smuzhiyun		run_hooks sleep "$REVERSE $METHOD" reverse
68*4882a593Smuzhiyun		log "$(date): Finished."
69*4882a593Smuzhiyun		;;
70*4882a593Smuzhiyunesac
71