Skip to content

Commit 53dd772

Browse files
committed
Merge branch 'installer-patch-1'
2 parents d2be91e + d7fc0b6 commit 53dd772

File tree

1 file changed

+38
-32
lines changed

1 file changed

+38
-32
lines changed

install.sh

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,10 @@
33
CONFIG=/boot/config.txt
44
DATESTAMP=`date "+%Y-%M-%d-%H-%M-%S"`
55
CONFIG_BACKUP=false
6+
APT_HAS_UPDATED=false
67

7-
CONFIG_VARS=`python - <<EOF
8-
from configparser import ConfigParser
9-
c = ConfigParser()
10-
c.read('library/setup.cfg')
11-
p = dict(c['pimoroni'])
12-
# Convert multi-line config entries into bash arrays
13-
for k in p.keys():
14-
fmt = '"{}"'
15-
if '\n' in p[k]:
16-
p[k] = "'\n\t'".join(p[k].split('\n')[1:])
17-
fmt = "('{}')"
18-
p[k] = fmt.format(p[k])
19-
print("""
20-
LIBRARY_NAME="{name}"
21-
LIBRARY_VERSION="{version}"
22-
""".format(**c['metadata']))
23-
print("""
24-
PY3_DEPS={py3deps}
25-
PY2_DEPS={py2deps}
26-
SETUP_CMDS={commands}
27-
CONFIG_TXT={configtxt}
28-
""".format(**p))
29-
EOF`
30-
31-
if [ $? -ne 0 ]; then
32-
printf "Error parsing configuration...\n"
8+
if [ $(id -u) -ne 0 ]; then
9+
printf "Script must be run as root. Try 'sudo ./install.sh'\n"
3310
exit 1
3411
fi
3512

@@ -56,20 +33,49 @@ function apt_pkg_install {
5633
PACKAGES="${PACKAGES[@]}"
5734
if ! [ "$PACKAGES" == "" ]; then
5835
echo "Installing missing packages: $PACKAGES"
59-
sudo apt update
60-
sudo apt install -y $PACKAGES
36+
if [ ! $APT_HAS_UPDATED ]; then
37+
apt update
38+
APT_HAS_UPDATED=true
39+
fi
40+
apt install -y $PACKAGES
6141
fi
6242
}
6343

64-
eval $CONFIG_VARS
44+
apt_pkg_install python-configparser
6545

66-
printf "$LIBRARY_NAME $LIBRARY_VERSION Python Library: Installer\n\n"
46+
CONFIG_VARS=`python - <<EOF
47+
from configparser import ConfigParser
48+
c = ConfigParser()
49+
c.read('library/setup.cfg')
50+
p = dict(c['pimoroni'])
51+
# Convert multi-line config entries into bash arrays
52+
for k in p.keys():
53+
fmt = '"{}"'
54+
if '\n' in p[k]:
55+
p[k] = "'\n\t'".join(p[k].split('\n')[1:])
56+
fmt = "('{}')"
57+
p[k] = fmt.format(p[k])
58+
print("""
59+
LIBRARY_NAME="{name}"
60+
LIBRARY_VERSION="{version}"
61+
""".format(**c['metadata']))
62+
print("""
63+
PY3_DEPS={py3deps}
64+
PY2_DEPS={py2deps}
65+
SETUP_CMDS={commands}
66+
CONFIG_TXT={configtxt}
67+
""".format(**p))
68+
EOF`
6769
68-
if [ $(id -u) -ne 0 ]; then
69-
printf "Script must be run as root. Try 'sudo ./install.sh'\n"
70+
if [ $? -ne 0 ]; then
71+
printf "Error parsing configuration...\n"
7072
exit 1
7173
fi
7274
75+
eval $CONFIG_VARS
76+
77+
printf "$LIBRARY_NAME $LIBRARY_VERSION Python Library: Installer\n\n"
78+
7379
cd library
7480
7581
printf "Installing for Python 2..\n"

0 commit comments

Comments
 (0)