11#! /bin/bash
22LIBRARY_NAME=` grep -m 1 name pyproject.toml | awk -F" = " ' {print substr($2,2,length($2)-2)}' `
3- LIBRARY_VERSION=` grep __version__ $LIBRARY_NAME /__init__.py | awk -F" = " ' {print substr($2,2,length($2)-2)}' `
43CONFIG=/boot/config.txt
54DATESTAMP=` date " +%Y-%m-%d-%H-%M-%S" `
65CONFIG_BACKUP=false
76APT_HAS_UPDATED=false
87RESOURCES_TOP_DIR=$HOME /Pimoroni
98WD=` pwd`
10- USAGE=" sudo ./install.sh (--unstable)"
9+ USAGE=" ./install.sh (--unstable)"
1110POSITIONAL_ARGS=()
1211FORCE=false
1312UNSTABLE=false
@@ -60,7 +59,7 @@ function do_config_backup {
6059 CONFIG_BACKUP=true
6160 FILENAME=" config.preinstall-$LIBRARY_NAME -$DATESTAMP .txt"
6261 inform " Backing up $CONFIG to /boot/$FILENAME \n"
63- cp $CONFIG /boot/$FILENAME
62+ sudo cp $CONFIG /boot/$FILENAME
6463 mkdir -p $RESOURCES_TOP_DIR /config-backups/
6564 cp $CONFIG $RESOURCES_TOP_DIR /config-backups/$FILENAME
6665 if [ -f " $UNINSTALLER " ]; then
@@ -90,11 +89,15 @@ function apt_pkg_install {
9089 fi
9190 sudo apt install -y $PACKAGES
9291 if [ -f " $UNINSTALLER " ]; then
93- echo " apt uninstall -y $PACKAGES "
92+ echo " apt uninstall -y $PACKAGES " >> $UNINSTALLER
9493 fi
9594 fi
9695}
9796
97+ function pip_pkg_install {
98+ PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring $PYTHON -m pip install --upgrade " $@ "
99+ }
100+
98101while [[ $# -gt 0 ]]; do
99102 K=" $1 "
100103 case $K in
131134
132135PYTHON_VER=` $PYTHON --version`
133136
134- printf " $LIBRARY_NAME ( $LIBRARY_VERSION ) Python Library: Installer\n\n"
137+ printf " $LIBRARY_NAME Python Library: Installer\n\n"
135138
136139inform " Checking Dependencies. Please wait..."
137140
138- $PYTHON -m pip install --upgrade toml
141+ pip_pkg_install toml
139142
140143CONFIG_VARS=` $PYTHON - << EOF
141144import toml
@@ -162,6 +165,13 @@ eval $CONFIG_VARS
162165RESOURCES_DIR=$RESOURCES_TOP_DIR /$LIBRARY_NAME
163166UNINSTALLER=$RESOURCES_DIR /uninstall.sh
164167
168+ RES_DIR_OWNER=` stat -c "%U" $RESOURCES_TOP_DIR `
169+
170+ if [[ " $RES_DIR_OWNER " == " root" ]]; then
171+ warning " \n\nFixing $RESOURCES_TOP_DIR permissions!\n\n"
172+ sudo chown -R $USER :$USER $RESOURCES_TOP_DIR
173+ fi
174+
165175mkdir -p $RESOURCES_DIR
166176
167177cat << EOF > $UNINSTALLER
180190inform " Installing for $PYTHON_VER ...\n"
181191apt_pkg_install " ${APT_PACKAGES[@]} "
182192if $UNSTABLE ; then
183- $PYTHON -m pip install .
193+ pip_pkg_install .
184194else
185- $PYTHON -m pip install --upgrade $LIBRARY_NAME
195+ pip_pkg_install $LIBRARY_NAME
186196fi
187197if [ $? -eq 0 ]; then
188198 success " Done!\n"
@@ -205,9 +215,9 @@ for ((i = 0; i < ${#CONFIG_TXT[@]}; i++)); do
205215 if ! [ " $CONFIG_LINE " == " " ]; then
206216 do_config_backup
207217 inform " Adding $CONFIG_LINE to $CONFIG \n"
208- sed -i " s/^#$CONFIG_LINE /$CONFIG_LINE /" $CONFIG
218+ sudo sed -i " s/^#$CONFIG_LINE /$CONFIG_LINE /" $CONFIG
209219 if ! grep -q " ^$CONFIG_LINE " $CONFIG ; then
210- printf " $CONFIG_LINE \n" >> $CONFIG
220+ printf " $CONFIG_LINE \n" | sudo tee --append $CONFIG
211221 fi
212222 fi
213223done
223233
224234printf " \n"
225235
226- if [ -f " /usr/bin/pydoc" ]; then
236+ if confirm " Would you like to generate documentation?" ; then
237+ pip_pkg_install pdoc
227238 printf " Generating documentation.\n"
228- pydoc -w $LIBRARY_NAME > /dev/null
229- if [ -f " $LIBRARY_NAME .html" ]; then
230- cp $LIBRARY_NAME .html $RESOURCES_DIR /docs.html
231- rm -f $LIBRARY_NAME .html
232- inform " Documentation saved to $RESOURCES_DIR /docs.html"
239+ $PYTHON -m pdoc $LIBRARY_NAME -o $RESOURCES_DIR /docs > /dev/null
240+ if [ $? -eq 0 ]; then
241+ inform " Documentation saved to $RESOURCES_DIR /docs"
233242 success " Done!"
234243 else
235244 warning " Error: Failed to generate documentation."
0 commit comments