From 2c004c9e716c24bce16ba0c9feef34c18136a350 Mon Sep 17 00:00:00 2001
From: Martin Pietsch <martin.pietsch@tu-dresden.de>
Date: Wed, 13 Nov 2019 14:01:36 +0100
Subject: [PATCH] refactored functions

---
 files/functions.sh | 79 ++++++++++++++++++++++++++++++++++++----------
 1 file changed, 63 insertions(+), 16 deletions(-)

diff --git a/files/functions.sh b/files/functions.sh
index c62a51b..18342d1 100755
--- a/files/functions.sh
+++ b/files/functions.sh
@@ -1,29 +1,76 @@
 # installTcPackages - install tiny core packages
 # parameter:
-#  space seperated list of package names
+#  $@ - list of package names
 # return:
 #  0 is installed
 #  1 something went wrong
-
 installTcPackages(){
-while [ $# -ne 0 ]
+  while [ $# -gt 0 ];
   do
-    sudo -u tc tce-load -w -i $1
+    su tc -c "tce-load -s -w -i $1" 2>&1 >/dev/null
     shift
   done
+} 
+
+# beginLogEntry - starts a new log entry
+# parameter:
+#  $1 - log message
+# return:
+#  none
+# hint:
+#  The log entries are saved in file /var/log/installer.log by default.
+#  The location can be changed with the variable $LOGFILE_PATH
+beginLogEntry(){
+  echo -n "$1... " | tee -a ${LOGFILE_PATH:-/var/log/installer.log}
+}
+
+# finishLogEntry - finishs a started log entry
+# parameter:
+#  $1 - result of log content
+# return:
+#  none
+# hint:
+#  The log entries are saved in file /var/log/installer.log by default.
+#  The location can be changed with the variable $LOGFILE_PATH
+finishLogEntry(){
+  echo "$1" | tee -a ${LOGFILE_PATH:-/var/log/installer.log}
 }
 
-start_chroot(){
-    sudo mkdir -p /mnt/debinst/{dev/pts,proc,sys}
-    sudo mount /dev /mnt/debinst/dev --bind
-    sudo mount devpts /mnt/debinst/dev/pts -t devpts
-    sudo mount none /mnt/debinst/proc -t proc
-    sudo mount none /mnt/debinst/sys -t sysfs
+# getAnswerfile - downloads Answerfile
+# parameter:
+#  $1 - remote answerfile path 
+#  $2 - local path answerfile path 
+# return:
+#  0 - no error 
+#  1 - error occurred
+getAnswerfile() {
+  local retval=1
+ 
+  if [ $# -eq 2 ];
+  then
+    wget -q -O $2 $1
+    retval=$?
+  fi
+
+  return ${retval} 
+}
+
+# runChroot - prepare and run a chroot environment for second stage installer
+# parameter:
+#  $1 - path of second stage installer script inside the chroot environment
+# return:
+#  none
+runChroot(){
+  mkdir -p /target/{dev/pts,proc,sys}
+  mount /dev /target/dev --bind
+  mount devpts /target/dev/pts -t devpts
+  mount none /target/proc -t proc
+  mount none /target/sys -t sysfs
     
-    sudo LANG=C.UTF-8 chroot /mnt/debinst $1
+  LANG=C.UTF-8 chroot /target $1
     
-    sudo umount /mnt/debinst/sys
-    sudo umount /mnt/debinst/proc
-    sudo umount /mnt/debinst/dev/pts
-    sudo umount /dev /mnt/debinst/dev
-}
\ No newline at end of file
+  umount /target/sys
+  umount /target/proc
+  umount /target/dev/pts
+  umount /dev /target/dev
+}
-- 
GitLab