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
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"