3 CONFIG
=/boot
/config.txt
4 DATESTAMP
=`date "+%Y-%M-%d-%H-%M-%S"`
8 if [ $
(id
-u) -ne 0 ]; then
9 printf "Script must be run as root. Try 'sudo ./install.sh'\n"
13 function do_config_backup
{
14 if [ ! $CONFIG_BACKUP == true
]; then
16 FILENAME
="/boot/config.preinstall-$LIBRARY_NAME-$DATESTAMP.txt"
17 printf "Backing up $CONFIG to $FILENAME\n"
22 function apt_pkg_install
{
25 for ((i
= 0; i
< ${#PACKAGES_IN[@]}; i
++)); do
26 PACKAGE
="${PACKAGES_IN[$i]}"
27 printf "Checking for $PACKAGE\n"
28 dpkg
-L $PACKAGE > /dev
/null
2>&1
29 if [ "$?" == "1" ]; then
30 PACKAGES
+=("$PACKAGE")
33 PACKAGES
="${PACKAGES[@]}"
34 if ! [ "$PACKAGES" == "" ]; then
35 echo "Installing missing packages: $PACKAGES"
36 if [ ! $APT_HAS_UPDATED ]; then
40 apt
install -y $PACKAGES
44 apt_pkg_install python-configparser
46 CONFIG_VARS
=`python - <<EOF
47 from configparser import ConfigParser
49 c.read('library/setup.cfg')
50 p = dict(c['pimoroni'])
51 # Convert multi-line config entries into bash arrays
55 p[k] = "'\n\t'".join(p[k].split('\n')[1:])
57 p[k] = fmt.format(p[k])
60 LIBRARY_VERSION="{version}"
61 """.format(**c['metadata']))
66 CONFIG_TXT={configtxt}
71 printf "Error parsing configuration...\n"
77 printf "$LIBRARY_NAME $LIBRARY_VERSION Python Library: Installer\n\n"
81 printf "Installing for Python 2..\n"
82 apt_pkg_install
"${PY2_DEPS[@]}"
83 python setup.py
install
85 if [ -f "/usr/bin/python3" ]; then
86 printf "Installing for Python 3..\n"
87 apt_pkg_install
"${PY3_DEPS[@]}"
88 python3 setup.py
install
93 for ((i
= 0; i
< ${#SETUP_CMDS[@]}; i
++)); do
94 CMD
="${SETUP_CMDS[$i]}"
95 # Attempt to catch anything that touches /boot/config.txt and trigger a backup
96 if [[ "$CMD" == *"raspi-config"* ]] ||
[[ "$CMD" == *"$CONFIG"* ]] ||
[[ "$CMD" == *"\$CONFIG"* ]]; then
102 for ((i
= 0; i
< ${#CONFIG_TXT[@]}; i
++)); do
103 CONFIG_LINE
="${CONFIG_TXT[$i]}"
104 if ! [ "$CONFIG_LINE" == "" ]; then
106 printf "Adding $CONFIG_LINE to $CONFIG\n"
107 sed -i "s/^#$CONFIG_LINE/$CONFIG_LINE/" $CONFIG
108 if ! grep -q "^$CONFIG_LINE" $CONFIG; then
109 printf "$CONFIG_LINE\n" >> $CONFIG