aboutsummaryrefslogtreecommitdiffstats
path: root/openbsd-image/scripts/setup.sh
blob: 3ad9a936776ae6b8d71281f622125baca81af70f (plain) (blame)
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
#!/bin/sh
set -e

: "${ADMIN_USER:?ADMIN_USER must be set}"

main() {
  update_pkgs
  pkg_add python # Needed for Ansible.
  install_system_maintenance_cron_jobs "$ADMIN_USER"
  allow_user_non_root_shutdown "$ADMIN_USER"
}

update_pkgs() {
  # Ensure the time is in sync. If it is not, things like upgrading the system
  # packages via pkg_add -u fail.
  rdate -n pool.ntp.org
  pkg_add -u
  fw_update
}

install_system_maintenance_cron_jobs() {
  (
    echo "MAILTO=$1"                         # Send mail about root cron jobs to the admin user.
    crontab -l 2>/dev/null                   # Print existing cron file; redirect stderr if empty cron file error.
    echo "10 12 * * * /usr/sbin/syspatch -c" # Generate a mail report for any outstanding patches everyday at 12:10
  ) | crontab -
}

allow_user_non_root_shutdown() {
  usermod -G _shutdown "$1"
}

main "$@"