chamesle

chamesle.org: the site of Chamesle, a small Linux distribution
git clone https://github.com/tortr-rs/chamesle
Log | Files | Refs | README

chamesle-auto-update (901B)


      1 #!/bin/sh
      2 # installs updates on its own, once a day, while the computer is plugged in. the snapshot hook takes a
      3 # snapshot first, as for any upgrade. auto=no in /etc/chamesle/updates.conf (the store's switch) turns it off
      4 conf=/etc/chamesle/updates.conf
      5 state=/var/lib/chamesle/auto-update
      6 log=/var/log/chamesle-auto-update.log
      7 grep -qs '^auto=no' $conf && exit 0
      8 [ -f $state ] && [ $(($(date +%s) - $(stat -c %Y $state))) -lt 82800 ] && exit 0
      9 # a laptop on battery waits for its charger. desktops have no power supply to ask
     10 for s in /sys/class/power_supply/*; do
     11     [ "$(cat $s/type 2>/dev/null)" = Mains ] && [ "$(cat $s/online 2>/dev/null)" = 0 ] && exit 0
     12 done
     13 n=$(apk list --upgradable 2>/dev/null | wc -l)
     14 {
     15     date
     16     [ "$n" -gt 0 ] && apk upgrade --no-interactive
     17     flatpak update --system --noninteractive --assumeyes
     18 } > $log 2>&1
     19 mkdir -p ${state%/*}
     20 echo "$(date +%s) $n" > $state