-
Notifications
You must be signed in to change notification settings - Fork 22
/
install-fsck-service
executable file
·63 lines (59 loc) · 1.96 KB
/
install-fsck-service
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
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/sh
set -e
PWD=$(pwd)
install_systemd () {
local dir=~/.config/systemd/user
if SYSTEMCTL=$(which systemctl); then
if SYSTEMD_PATH=$(which systemd-path); then
dir=$("${SYSTEMD_PATH}" user-configuration)/systemd/user
fi
mkdir -p "${dir}"
file="${dir}/iabak-cronjob"
if [ ! -f "${file}.service" -o ! -f "${file}.timer" ]; then
cat <<-EOF >"${file}.service"
[Service]
Type=simple
WorkingDirectory=${PWD}
ExecStart=${PWD}/iabak-cronjob
EOF
cat <<-EOF >"${file}.timer"
[Timer]
OnCalendar=*-*-* 00:00:00
AccuracySec=6h
Persistent=true
[Install]
WantedBy=default.target
EOF
if ! ( "${SYSTEMCTL}" --user daemon-reload && "${SYSTEMCTL}" --user enable iabak-cronjob.timer ); then
echo "Your systemd doesn't appear to be configured to run user jobs."
echo "Falling back to an old-school cron job."
rm -f "${file}.service" "${file}.timer"
return 1
fi
echo "Systemd service iabak-cronjob installed and enabled."
echo "*** Note: you may need to run 'loginctl enable-linger $(whoami)' in order for this job to run while you are logged out."
else
echo "You've already got the iabak-cronjob service installed; I didn't need to do anything. Thanks!"
fi
else
echo "Your system doesn't use systemd; falling back to an old-school cron job."
return 1
fi
}
install_cron () {
if CRONTAB=$(which crontab); then
if ! "${CRONTAB}" -l 2>&- | grep "${PWD}/iabak-cronjob" -q; then
tmp=$(tempfile || echo install-fsck-service-tmp-$$)
crontab -l >${tmp} 2>&- || true
echo "02 02 * * * ${PWD}/iabak-cronjob >${PWD}/iabak-cronjob.log 2>&1" >>${tmp}
crontab ${tmp}
echo "Cron job installed."
else
echo "You've already got the cron job installed; I didn't need to do anything. Thanks!"
fi
else
echo "Your system doesn't have crontab(1), this is a pretty bad sign."
return 1
fi
}
install_systemd || install_cron || echo "Installation failed. Please install cron and rerun install-fsck-service."