-
Notifications
You must be signed in to change notification settings - Fork 2
/
mksuspend.sh
executable file
·51 lines (42 loc) · 1.59 KB
/
mksuspend.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#! /bin/bash
BUILD_DIR="./suspend"
SUSPEND_DIR="/boot/"
CHROOTTARGET=$(readlink -f $SUSPEND_DIR$BUILD_DIR)
if [[ $# -ne 1 ]]; then
echo "Usage: $0 <crypt_device>"
echo "- <crypt_device> should be the root LUKS-encrypted device"
exit 1
fi
if [[ $EUID -ne 0 ]]; then
echo "This utility must be run as root"
exit 2
fi
# Clear the build and destination interface
rm -Rf $BUILD_DIR
rm -Rf $CHROOTTARGET
# Populate the source folder
mkdir -p $BUILD_DIR/{dev,proc,sys,bin,var,usr,run,lib,lib64}
cp /bin/bash $BUILD_DIR/bin/
cp /bin/sync $BUILD_DIR/bin/
cp /bin/sleep $BUILD_DIR/bin/
cp /sbin/cryptsetup $BUILD_DIR/bin/
./functions/cplib.sh /bin/bash $BUILD_DIR
./functions/cplib.sh /bin/sync $BUILD_DIR
./functions/cplib.sh /bin/sleep $BUILD_DIR
./functions/cplib.sh /sbin/cryptsetup $BUILD_DIR
# Copy/Edit the Functions
cat ./functions/luksSuspend.sh | sed "s|LUKSDEVICE|$1|g" > $BUILD_DIR/luksSuspend.sh
cat ./functions/suspend.sh | sed "s|CHROOTTARGET|$CHROOTTARGET|g" > $BUILD_DIR/suspend.sh
cat ./lm/lid_change.sh | sed "s|CHROOTTARGET|$CHROOTTARGET|g" > /etc/acpi/lid_change.sh
cat ./lm/lm_lid > /etc/acpi/events/lm_lid
# Move the BUILD_DIR to the SUSPEND_DIR
mv $BUILD_DIR $SUSPEND_DIR
chmod +x $CHROOTTARGET/*.sh
chmod +x /etc/acpi/lid_change.sh
# Alter default behaviors to avoid redundant suspend (my regex-foo is weak)
sed -i 's/^#HandleLidSwitch=.*$/HandleLidSwitch=ignore/' /etc/systemd/logind.conf
sed -i 's/^HandleLidSwitch=.*$/HandleLidSwitch=ignore/' /etc/systemd/logind.conf
echo "Default lid behavior supressed"
# Reload ACPId to pick up the changes
service acpid restart
echo "ACPId restarted"