#!/bin/sh # Install the .deb files of a directory a few at a time, gently, so the Brain stays usable: # lex01-install-batches /opt/debs-games [batch size] # Libraries first, then data/common packages, then the rest. Progress: /var/log/lex01-batches.log DIR=${1:?directory}; N=${2:-6} LOG=/var/log/lex01-batches.log export DEBIAN_FRONTEND=noninteractive cd "$DIR" || exit 1 echo "$(date '+%F %T') START $DIR" >>"$LOG" list=$( (ls lib*.deb; ls *-data_*.deb *-common_*.deb fonts-*.deb 2>/dev/null; ls *.deb) 2>/dev/null | awk '!seen[$0]++') set -- $list total=$#; done_n=0 while [ $# -gt 0 ]; do batch=""; i=0 while [ $# -gt 0 ] && [ $i -lt "$N" ]; do batch="$batch $1"; shift; i=$((i + 1)); done # wait while memory is short or the system is already busy while [ "$(awk '/MemAvailable/{print int($2/1024)}' /proc/meminfo)" -lt 20 ] || \ [ "$(cut -d. -f1 /proc/loadavg)" -ge 4 ]; do sleep 20; done nice -n 19 ionice -c3 dpkg -i --force-unsafe-io --force-confdef --force-confold $batch >>"$LOG" 2>&1 sync done_n=$((done_n + i)) echo "$(date '+%F %T') PROGRESS $done_n/$total" >>"$LOG" sleep 8 done nice -n 19 dpkg --configure -a >>"$LOG" 2>&1 left=$(dpkg -l | grep -c '^i[UFH]') echo "$(date '+%F %T') FINISHED unconfigured=$left" >>"$LOG"