@@ -34,8 +34,10 @@ function logit {
3434 # Writes message to /etc/sdm/history
3535 #
3636 # $1="message string"
37+ # $2=/path/to/log [/etc/sdm/history]
3738 #
38- [ -f $SDMPT /etc/sdm/history ] && echo " $( thisdate) $1 " >> $SDMPT /etc/sdm/history
39+ msg=" $1 " logf=${2:-/ etc/ sdm/ history}
40+ [ -f $SDMPT /$logf ] && echo " $( thisdate) $msg " >> $SDMPT /$logf
3941}
4042
4143function logtoboth() {
@@ -44,18 +46,19 @@ function logtoboth() {
4446 #
4547 # $1="message string" which will be split up across multiple lines if needed
4648 # $2="nosplit" if lines should not be split up
49+ # $3=/path/to/logfile for alternate log
4750 #
48- local msg=" $1 "
51+ local msg=" $1 " mods= $2 logf= ${3 :-/ etc / sdm / history}
4952 local str=() i spc=" "
50- if [[ ${# msg} -le $logwidth ]] || [[ " $2 " == " nosplit" ]]
53+ if [[ ${# msg} -le $logwidth ]] || [[ " $mods " == " nosplit" ]]
5154 then
52- logit " $msg "
55+ logit " $msg " $logf
5356 echo " $msg "
5457 else
5558 readarray -t str <<< $( fold -s -w$logwidth <<< $( echo " $msg " ))
5659 for (( i= 0 ; i < ${# str[@]} ; i++ ))
5760 do
58- logit " ${spc}${str[$i]} "
61+ logit " ${spc}${str[$i]} " $logf
5962 echo " ${spc}${str[$i]} "
6063 spc=" "
6164 done
@@ -195,6 +198,8 @@ function doapt() {
195198 else
196199 # Technique from https://unix.stackexchange.com/questions/14270/get-exit-status-of-process-thats-piped-to-another/73180#73180
197200 { { { { DEBIAN_FRONTEND=noninteractive $aptcmd -o=Dpkg::Use-Pty=0 $options $1 2>&1 ; echo $? >&3 ; } | pline >&4 ; } 3>&1 ; } | { read xs; exit $xs ; } } 4>&1
201+ # This V doesn't work when passed as argument ;(
202+ # runcaptureout "DEBIAN_FRONTEND=noninteractive $aptcmd -o=Dpkg::Use-Pty=0 $options $1"
198203 sts=$?
199204 fi
200205 fi
@@ -217,13 +222,13 @@ function runcaptureout() {
217222 #
218223 # Run command, capturing output via logtoboth
219224 #
220- local cmd=" $1 "
225+ local cmd=" $1 " outlog= " $2 "
221226
222227 function pline() {
223228 local line
224229 while read line
225230 do
226- logtoboth " $line "
231+ logtoboth " $line " $outlog
227232 done
228233 }
229234
@@ -309,13 +314,6 @@ function getpipver() {
309314}
310315
311316function installviapip() {
312- function pline() {
313- local line
314- while read line
315- do
316- echo " $( thisdate) $line " >> /etc/sdm/apt.log
317- done
318- }
319317 # $1: package name
320318 # $2: /path/to/pip3 in the venv
321319 # $3: pip install options
@@ -331,11 +329,10 @@ function installviapip() {
331329 $vpip3 install --ignore-installed $options $pkg 2>&1 | tee -a /etc/sdm/apt.log
332330 sts=$?
333331 else
334- # Technique from https://unix.stackexchange.com/questions/14270/get-exit-status-of-process-thats-piped-to-another/73180#73180
335- { { { { $vpip3 install --ignore-installed $options $pkg 2>&1 ; echo $? >&3 ; } | pline >&4 ; } 3>&1 ; } | { read xs; exit $xs ; } } 4>&1
332+ runcaptureout " $vpip3 install --ignore-installed $options $pkg "
336333 sts=$?
337334 fi
338- [[ " $poptions " =~ " nologdates" ]] && td=" " || td=" $( thisdate) "
335+ # [[ "$poptions" =~ "nologdates" ]] && td="" || td="$(thisdate) "
339336 echo " ${td} [Done] [$sts ]" >> /etc/sdm/apt.log
340337 return $sts
341338}
0 commit comments