3 CONFIG
=/boot
/config.txt
4 DATESTAMP
=`date "+%Y-%M-%d-%H-%M-%S"`
7 CONFIG_VARS
=`python - <<EOF
8 from configparser import ConfigParser
10 c.read('library/setup.cfg')
11 p = dict(c['pimoroni'])
12 # Convert multi-line config entries into bash arrays
16 p[k] = "'\n\t'".join(p[k].split('\n')[1:])
18 p[k] = fmt.format(p[k])
21 LIBRARY_VERSION="{version}"
22 """.format(**c['metadata']))
27 CONFIG_TXT={configtxt}
32 printf "Error parsing configuration...\n"
36 function do_config_backup
{
37 if [ ! $CONFIG_BACKUP == true
]; then
39 FILENAME
="/boot/config.preinstall-$LIBRARY_NAME-$DATESTAMP.txt"
40 printf "Backing up $CONFIG to $FILENAME\n"
45 function apt_pkg_install
{
48 for ((i
= 0; i
< ${#PACKAGES_IN[@]}; i
++)); do
49 PACKAGE
="${PACKAGES_IN[$i]}"
50 printf "Checking for $PACKAGE\n"
51 dpkg
-L $PACKAGE > /dev
/null
2>&1
52 if [ "$?" == "1" ]; then
53 PACKAGES
+=("$PACKAGE")
56 PACKAGES
="${PACKAGES[@]}"
57 if ! [ "$PACKAGES" == "" ]; then
58 echo "Installing missing packages: $PACKAGES"
60 sudo apt
install -y $PACKAGES
66 printf "$LIBRARY_NAME $LIBRARY_VERSION Python Library: Installer\n\n"
68 if [ $
(id
-u) -ne 0 ]; then
69 printf "Script must be run as root. Try 'sudo ./install.sh'\n"
75 printf "Installing for Python 2..\n"
76 apt_pkg_install
"${PY2_DEPS[@]}"
77 python setup.py
install
79 if [ -f "/usr/bin/python3" ]; then
80 printf "Installing for Python 3..\n"
81 apt_pkg_install
"${PY3_DEPS[@]}"
82 python3 setup.py
install
87 for ((i
= 0; i
< ${#SETUP_CMDS[@]}; i
++)); do
88 CMD
="${SETUP_CMDS[$i]}"
89 # Attempt to catch anything that touches /boot/config.txt and trigger a backup
90 if [[ "$CMD" == *"raspi-config"* ]] ||
[[ "$CMD" == *"$CONFIG"* ]] ||
[[ "$CMD" == *"\$CONFIG"* ]]; then
96 for ((i
= 0; i
< ${#CONFIG_TXT[@]}; i
++)); do
97 CONFIG_LINE
="${CONFIG_TXT[$i]}"
98 if ! [ "$CONFIG_LINE" == "" ]; then
100 printf "Adding $CONFIG_LINE to $CONFIG\n"
101 sed -i "s/^#$CONFIG_LINE/$CONFIG_LINE/" $CONFIG
102 if ! grep -q "^$CONFIG_LINE" $CONFIG; then
103 printf "$CONFIG_LINE\n" >> $CONFIG