Skip to content

Commit 59e9100

Browse files
authored
Merge pull request #10 from pimoroni/patch-install
Fixes to the install.sh endpoint
2 parents 11f6655 + fdd33d1 commit 59e9100

File tree

5 files changed

+32
-19
lines changed

5 files changed

+32
-19
lines changed

.github/workflows/qa.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ jobs:
1010
test:
1111
name: linting & spelling
1212
runs-on: ubuntu-latest
13+
14+
env:
15+
TERM: xterm-256color
16+
1317
steps:
1418
- name: Checkout Code
1519
uses: actions/checkout@v2

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ Latest/development library from GitHub:
2828

2929
* `git clone https://github.com/pimoroni/PROJECT_NAME-python`
3030
* `cd PROJECT_NAME-python`
31-
* `sudo ./install.sh`
31+
* `./install.sh --unstable`
3232

install.sh

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#!/bin/bash
22
LIBRARY_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)}'`
43
CONFIG=/boot/config.txt
54
DATESTAMP=`date "+%Y-%m-%d-%H-%M-%S"`
65
CONFIG_BACKUP=false
76
APT_HAS_UPDATED=false
87
RESOURCES_TOP_DIR=$HOME/Pimoroni
98
WD=`pwd`
10-
USAGE="sudo ./install.sh (--unstable)"
9+
USAGE="./install.sh (--unstable)"
1110
POSITIONAL_ARGS=()
1211
FORCE=false
1312
UNSTABLE=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+
98101
while [[ $# -gt 0 ]]; do
99102
K="$1"
100103
case $K in
@@ -131,11 +134,11 @@ fi
131134

132135
PYTHON_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

136139
inform "Checking Dependencies. Please wait..."
137140

138-
$PYTHON -m pip install --upgrade toml
141+
pip_pkg_install toml
139142

140143
CONFIG_VARS=`$PYTHON - <<EOF
141144
import toml
@@ -162,6 +165,13 @@ eval $CONFIG_VARS
162165
RESOURCES_DIR=$RESOURCES_TOP_DIR/$LIBRARY_NAME
163166
UNINSTALLER=$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+
165175
mkdir -p $RESOURCES_DIR
166176
167177
cat << EOF > $UNINSTALLER
@@ -180,9 +190,9 @@ fi
180190
inform "Installing for $PYTHON_VER...\n"
181191
apt_pkg_install "${APT_PACKAGES[@]}"
182192
if $UNSTABLE; then
183-
$PYTHON -m pip install .
193+
pip_pkg_install .
184194
else
185-
$PYTHON -m pip install --upgrade $LIBRARY_NAME
195+
pip_pkg_install $LIBRARY_NAME
186196
fi
187197
if [ $? -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
213223
done
@@ -223,13 +233,12 @@ fi
223233
224234
printf "\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."

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ twine
66
hatch
77
hatch-fancy-pypi-readme
88
tox
9+
pdoc

uninstall.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
FORCE=false
44
LIBRARY_NAME=`grep -m 1 name pyproject.toml | awk -F" = " '{print substr($2,2,length($2)-2)}'`
5-
LIBRARY_VERSION=`grep __version__ $LIBRARY_NAME/__init__.py | awk -F" = " '{print substr($2,2,length($2)-2)}'`
65
RESOURCES_DIR=$HOME/Pimoroni/$LIBRARY_NAME
76
PYTHON="/usr/bin/python3"
87

@@ -47,7 +46,7 @@ warning() {
4746
echo -e "$(tput setaf 1)$1$(tput sgr0)"
4847
}
4948

50-
printf "$LIBRARY_NAME $LIBRARY_VERSION Python Library: Uninstaller\n\n"
49+
printf "$LIBRARY_NAME Python Library: Uninstaller\n\n"
5150

5251
user_check
5352

0 commit comments

Comments
 (0)