安装
在 archlinux 上要安装 kgotobed
,首先需要安装 dkms
和 linux-headers
这两个包:
-
sudo pacman -S dkms linux-headers --noconfirm
然后去 github 上克隆它的源代码:
-
git clone https://github.com/nikital/kgotobed.git
最后我们对源代码进行手工编译:
-
cd kgotobed/
-
sudo make install
make install
命令会完成以下三件事情:
-
通过 DKMS 注册
kgotobed.ko
-
安装
gotobed
命令到/usr/local/bin
下 -
在 systemd 中注册、启用并运行
kgotobed.service
使用
直接运行 gotobed
就能看到设置的强行关机的时间:
-
[vagrant@archlinux kgotobed]$ gotobed 22:00
-
Current bedtime is 2018-04-13 01:00:00
-
Setting bedtime to 2018-04-12 22:00:00
-
Bedtime will be in 10 hours 32 minutes
不过你不能把时间调到更晚……
-
[vagrant@archlinux kgotobed]$ gotobed 2:00
-
Current bedtime is 2018-04-13 01:00:00
-
Error: Attempting to postpone bed time, it doesn't work like this...
要想调整默认时间,你需要修改 /etc/systemd/system/kgotobed.service
。
原始的 kgotobed.service
内容如下所示:
-
[Unit]
-
Description=kgotobed: Poweroff at bedtime
-
After=dkms.service
-
[Service]
-
Type=oneshot
-
ExecStartPre=/sbin/modprobe kgotobed
-
Environment=TIME=01:00
-
ExecStart=/usr/local/bin/gotobed -f ${TIME}
-
[Install]
-
WantedBy=multi-user.target
我们将其中的 TIME=01:00
改成 TIME=02:00
后重启系统,再次执行 gotobed
可以看到时间已经修改了:
-
[vagrant@archlinux ~]$ gotobed
-
Current bedtime is 2018-04-13 02:00:00
删除 kgotobed
要逃脱强制关机的命运,几乎唯一的办法就是卸载 kgotobed 了。
我们可以在源代码目录中执行 make uninstall
进行卸载:
-
[vagrant@archlinux ~]$ cd kgotobed/
-
[vagrant@archlinux kgotobed]$ sudo make uninstall
-
dkms remove kgotobed/1.0 --all
-
-------- Uninstall Beginning --------
-
Module: kgotobed
-
Version: 1.0
-
Kernel: 4.15.15-1-ARCH (x86_64)
-
-------------------------------------
-
Status: Before uninstall, this module version was ACTIVE on this kernel.
-
kgotobed.ko:
-
- Uninstallation
-
- Deleting from: /usr/lib/modules/4.15.15-1-ARCH/extra//
-
- Original module
-
- No original module was found for this module on this kernel.
-
- Use the dkms install command to reinstall any previous module version.
-
depmod...........
-
DKMS: uninstall completed.
-
------------------------------
-
Deleting module version: 1.0
-
completely from the DKMS tree.
-
------------------------------
-
Done.
-
rm -f /usr/local/bin/gotobed
-
rm -f /etc/systemd/system/kgotobed.service
-
systemctl daemon-reload
-
[vagrant@archlinux kgotobed]$