Bootstrap with python-configparser from apt
authorPhil Howard <phil@gadgetoid.com>
Sat, 6 Jul 2019 13:16:10 +0000 (14:16 +0100)
committerPhil Howard <phil@gadgetoid.com>
Sat, 6 Jul 2019 13:16:10 +0000 (14:16 +0100)
install.sh

index 5cde03b4128ef18e0da07bae5b6191c9892ac2f2..ad610363b4bea4c0dca92ec2a4a5cdcea9d8ff3a 100755 (executable)
@@ -3,33 +3,10 @@
 CONFIG=/boot/config.txt
 DATESTAMP=`date "+%Y-%M-%d-%H-%M-%S"`
 CONFIG_BACKUP=false
+APT_HAS_UPDATED=false
 
-CONFIG_VARS=`python - <<EOF
-from configparser import ConfigParser
-c = ConfigParser()
-c.read('library/setup.cfg')
-p = dict(c['pimoroni'])
-# Convert multi-line config entries into bash arrays
-for k in p.keys():
-    fmt = '"{}"'
-    if '\n' in p[k]:
-        p[k] = "'\n\t'".join(p[k].split('\n')[1:])
-        fmt = "('{}')"
-    p[k] = fmt.format(p[k])
-print("""
-LIBRARY_NAME="{name}"
-LIBRARY_VERSION="{version}"
-""".format(**c['metadata']))
-print("""
-PY3_DEPS={py3deps}
-PY2_DEPS={py2deps}
-SETUP_CMDS={commands}
-CONFIG_TXT={configtxt}
-""".format(**p))
-EOF`
-
-if [ $? -ne 0 ]; then
-       printf "Error parsing configuration...\n"
+if [ $(id -u) -ne 0 ]; then
+       printf "Script must be run as root. Try 'sudo ./install.sh'\n"
        exit 1
 fi
 
@@ -56,20 +33,49 @@ function apt_pkg_install {
        PACKAGES="${PACKAGES[@]}"
        if ! [ "$PACKAGES" == "" ]; then
                echo "Installing missing packages: $PACKAGES"
-               sudo apt update
-               sudo apt install -y $PACKAGES
+        if [ ! $APT_HAS_UPDATED ]; then
+                   apt update
+            APT_HAS_UPDATED=true
+        fi
+               apt install -y $PACKAGES
        fi
 }
 
-eval $CONFIG_VARS
+apt_pkg_install python-configparser
 
-printf "$LIBRARY_NAME $LIBRARY_VERSION Python Library: Installer\n\n"
+CONFIG_VARS=`python - <<EOF
+from configparser import ConfigParser
+c = ConfigParser()
+c.read('library/setup.cfg')
+p = dict(c['pimoroni'])
+# Convert multi-line config entries into bash arrays
+for k in p.keys():
+    fmt = '"{}"'
+    if '\n' in p[k]:
+        p[k] = "'\n\t'".join(p[k].split('\n')[1:])
+        fmt = "('{}')"
+    p[k] = fmt.format(p[k])
+print("""
+LIBRARY_NAME="{name}"
+LIBRARY_VERSION="{version}"
+""".format(**c['metadata']))
+print("""
+PY3_DEPS={py3deps}
+PY2_DEPS={py2deps}
+SETUP_CMDS={commands}
+CONFIG_TXT={configtxt}
+""".format(**p))
+EOF`
 
-if [ $(id -u) -ne 0 ]; then
-       printf "Script must be run as root. Try 'sudo ./install.sh'\n"
+if [ $? -ne 0 ]; then
+       printf "Error parsing configuration...\n"
        exit 1
 fi
 
+eval $CONFIG_VARS
+
+printf "$LIBRARY_NAME $LIBRARY_VERSION Python Library: Installer\n\n"
+
 cd library
 
 printf "Installing for Python 2..\n"