Fix issue where blinka installs as root

This commit is contained in:
Melissa LeBlanc-Williams 2023-09-12 12:53:17 -07:00
parent 43914b6163
commit 189997aae8
5 changed files with 38 additions and 21 deletions

View file

@ -246,9 +246,9 @@ def sysupdate():
if not UPDATE_DB:
print("Updating apt indexes...", end='')
progress(3)
if not shell.run_command('sudo apt update', True):
if not shell.run_command('sudo apt update', suppress_message=True):
warn_exit("Apt failed to update indexes!")
if not shell.run_command('sudo apt-get update', True):
if not shell.run_command('sudo apt-get update', suppress_message=True):
warn_exit("Apt failed to update indexes!")
print("Reading package lists...")
progress(3)
@ -259,7 +259,7 @@ def sysupdate():
def softwareinstall():
print("Installing Pre-requisite Software...This may take a few minutes!")
if not shell.run_command("apt-get install -y libts0", True):
if not shell.run_command("apt-get install -y libts0", suppress_message=True):
if not shell.run_command("apt-get install -y tslib"):
if not shell.run_command("apt-get install -y libts-dev"):
warn_exit("Apt failed to install TSLIB!")
@ -489,7 +489,7 @@ restart the script and choose a different orientation.""".format(rotation=pitftr
# check init system (technique borrowed from raspi-config):
shell.info('Checking init system...')
if shell.run_command("which systemctl", True) and shell.run_command("systemctl | grep '\-\.mount'", True):
if shell.run_command("which systemctl", suppress_message=True) and shell.run_command("systemctl | grep '\-\.mount'", suppress_message=True):
SYSTEMD = True
print("Found systemd")
elif os.path.isfile("/etc/init.d/cron") and not os.path.islink("/etc/init.d/cron"):

View file

@ -223,9 +223,9 @@ def sysupdate():
if not UPDATE_DB:
print("Updating apt indexes...", end='')
progress(3)
if not shell.run_command('sudo apt update', True):
if not shell.run_command('sudo apt update', suppress_message=True):
warn_exit("Apt failed to update indexes! Try running 'sudo apt update' manually.")
if not shell.run_command('sudo apt-get update', True):
if not shell.run_command('sudo apt-get update', suppress_message=True):
warn_exit("Apt failed to update indexes! Try running 'sudo apt-get update' manually.")
print("Reading package lists...")
progress(3)
@ -236,7 +236,7 @@ def sysupdate():
def softwareinstall():
print("Installing Pre-requisite Software...This may take a few minutes!")
if not shell.run_command("apt-get install -y libts0", True):
if not shell.run_command("apt-get install -y libts0", suppress_message=True):
if not shell.run_command("apt-get install -y tslib"):
if not shell.run_command("apt-get install -y libts-dev"):
warn_exit("Apt failed to install TSLIB!")
@ -282,13 +282,13 @@ def install_drivers():
if is_kernel_upgrade_required():
print("############# UPGRADING KERNEL ###############")
print("Updating packages...")
if not shell.run_command("sudo apt-get update", True):
if not shell.run_command("sudo apt-get update", suppress_message=True):
warn_exit("Apt failed to update itself!")
print("Upgrading packages...")
if not shell.run_command("sudo apt-get -y upgrade", False):
if not shell.run_command("sudo apt-get -y upgrade"):
warn_exit("Apt failed to install software!")
print("Installing Kernel Headers. This may take a few minutes...")
if not shell.run_command("apt-get install -y raspberrypi-kernel-headers", True):
if not shell.run_command("apt-get install -y raspberrypi-kernel-headers", suppress_message=True):
warn_exit("Apt failed to install software!")
# If the kernel was upgraded, a build folder should exist once it has been loaded
module = pitft_config['kernel_module']
@ -390,23 +390,23 @@ def uninstall_console():
def install_fbcp():
global fbcp_rotations
print("Installing cmake...")
if not shell.run_command("apt-get --yes --allow-downgrades --allow-remove-essential --allow-change-held-packages install cmake", True):
if not shell.run_command("apt-get --yes --allow-downgrades --allow-remove-essential --allow-change-held-packages install cmake", suppress_message=True):
warn_exit("Apt failed to install software!")
print("Downloading rpi-fbcp...")
shell.pushd("/tmp")
shell.run_command("curl -sLO https://github.com/adafruit/rpi-fbcp/archive/master.zip")
print("Uncompressing rpi-fbcp...")
shell.run_command("rm -rf /tmp/rpi-fbcp-master")
if not shell.run_command("unzip master.zip", True):
if not shell.run_command("unzip master.zip", suppress_message=True):
warn_exit("Failed to uncompress fbcp!")
shell.chdir("rpi-fbcp-master")
shell.run_command("mkdir build")
shell.chdir("build")
print("Building rpi-fbcp...")
shell.write_text_file("../CMakeLists.txt", "\nset (CMAKE_C_FLAGS \"-std=gnu99 ${CMAKE_C_FLAGS}\")")
if not shell.run_command("cmake ..", True):
if not shell.run_command("cmake ..", suppress_message=True):
warn_exit("Failed to cmake fbcp!")
if not shell.run_command("make", True):
if not shell.run_command("make", suppress_message=True):
warn_exit("Failed to make fbcp!")
print("Installing rpi-fbcp...")
shell.run_command("install fbcp /usr/local/bin/fbcp")
@ -669,7 +669,7 @@ restart the script and choose a different orientation.""".format(rotation=pitftr
# check init system (technique borrowed from raspi-config):
shell.info('Checking init system...')
if shell.run_command("which systemctl", True) and shell.run_command("systemctl | grep '\-\.mount'", True):
if shell.run_command("which systemctl", suppress_message=True) and shell.run_command("systemctl | grep '\-\.mount'", suppress_message=True):
SYSTEMD = True
print("Found systemd")
elif os.path.isfile("/etc/init.d/cron") and not os.path.islink("/etc/init.d/cron"):

View file

@ -47,7 +47,7 @@ Run time < 1 minute. Reboot not required.""")
# check init system (technique borrowed from raspi-config):
shell.group = 'FAN'
shell.info('Checking init system...')
if shell.run_command("which systemctl", True) and shell.run_command("systemctl | grep '\-\.mount'", True):
if shell.run_command("which systemctl", suppress_message=True) and shell.run_command("systemctl | grep '\-\.mount'", suppress_message=True):
print("Found systemd, OK!")
elif os.path.isfile("/etc/init.d/cron") and not os.path.islink("/etc/init.d/cron"):
shell.bail("Found sysvinit, but we require systemd")

View file

@ -56,7 +56,7 @@ EXISTING INSTALLATION, IF ANY, WILL BE OVERWRITTEN.
print("""
Starting installation...
Updating package index files...""")
shell.run_command('sudo apt-get update', True)
shell.run_command('sudo apt-get update', suppress_message=True)
print("Installing Python libraries...")
shell.run_command('sudo apt-get install -y python3-pip python3-dev python3-smbus')

View file

@ -5,6 +5,9 @@ Adafruit Raspberry Pi Blinka Setup Script
Written by Melissa LeBlanc-Williams for Adafruit Industries
"""
import os
import sys
try:
from adafruit_shell import Shell
except ImportError:
@ -15,6 +18,9 @@ shell.group="Blinka"
default_python = 3
blinka_minimum_python_version = 3.7
def in_venv():
return sys.prefix != sys.base_prefix
def default_python_version(numeric=True):
version = shell.run_command("python -c 'import platform; print(platform.python_version())'", suppress_message=True, return_output=True)
if numeric:
@ -76,11 +82,19 @@ def update_pip():
shell.run_command("sudo apt-get install -y python3-pip")
shell.run_command("sudo pip3 install --upgrade setuptools")
def install_blinka():
def install_blinka(user=False):
print("Installing latest version of Blinka locally")
shell.run_command("sudo apt-get install -y i2c-tools libgpiod-dev")
shell.run_command("pip3 install --upgrade RPi.GPIO")
shell.run_command("pip3 install --upgrade adafruit-blinka")
pip_command = "pip3 install --upgrade"
username = None
if user:
username = os.environ["SUDO_USER"]
#user_homedir = os.path.expanduser(f"~{username}")
#install_dir = os.path.join(user_homedir, ".local", "lib", f"python{get_python3_version()}", "sitet-packages")
#print(f"Installing to {install_dir}")
#pip_command += f" -t {install_dir}"
shell.run_command(f"{pip_command} RPi.GPIO", run_as_user=username)
shell.run_command(f"{pip_command} adafruit-blinka", run_as_user=username)
def main():
global default_python
@ -115,7 +129,10 @@ Raspberry Pi and installs Blinka
set_raspiconfig()
update_python()
update_pip()
install_blinka()
if in_venv():
install_blinka()
else:
install_blinka(True)
# Done
print("""DONE.