diff --git a/adafruit-pitft.py b/adafruit-pitft.py index aec0e6d..cfa43c2 100644 --- a/adafruit-pitft.py +++ b/adafruit-pitft.py @@ -667,7 +667,7 @@ def uninstall_fbcp(): if not wayland and not is_bullseye: print("Restoring Wayland as default display manager...") - disable_wayland(False) + shell.set_window_manager("wayland") return True @@ -736,18 +736,6 @@ Settings take effect on next boot. shell.reboot() shell.exit() -def disable_wayland(disable): - if is_bullseye: - return - if disable: - print("Using X11 instead of Wayland") - if not shell.run_command("sudo raspi-config nonint do_wayland W1"): - shell.bail("Unable to disable Wayland") - else: - print("Using Wayland instead of X11") - if not shell.run_command("sudo raspi-config nonint do_wayland W2"): - shell.bail("Unable to enable Wayland") - ####################################################### MAIN target_homedir = "/home/pi" username = os.environ["SUDO_USER"] @@ -755,9 +743,9 @@ user_homedir = os.path.expanduser(f"~{username}") if shell.isdir(user_homedir): target_homedir = user_homedir -boot_dir = "/boot/firmware" -if not shell.exists(boot_dir) or not shell.isdir(boot_dir): - boot_dir = "/boot" +boot_dir = shell.get_boot_config() +if boot_dir is None: + shell.bail("Unable to find boot directory") if shell.get_raspbian_version() == "bullseye": is_bullseye = True @@ -805,14 +793,13 @@ Run time of up to 5 minutes. Reboot required! def select_display(config, interactive=False): global pitft_config, wayland - print(("Wayland" if wayland else "X11") + " Detected") pitft_config = config print("Display Type: {}".format(pitft_config["menulabel"])) if is_kernel_upgrade_required(): print("WARNING! WILL UPGRADE YOUR KERNEL TO LATEST") if "force_x11" in pitft_config and pitft_config["force_x11"] and wayland: if not interactive or shell.prompt("This display works better with X11, but Wayland is currently running. Use X11 instead? (Recommended)", default="y"): - disable_wayland(True) + shell.set_window_manager("x11") wayland = False if display in [str(x) for x in range(1, len(config) + 1)]: @@ -951,5 +938,7 @@ restart the script and choose a different orientation.""".format(rotation=pitftr # Main function if __name__ == "__main__": shell.require_root() + if shell.is_raspberry_pi_os() and shell.is_kernel_userspace_mismatched() and shell.is_pi5_or_newer(): + shell.bail("Unable to proceed on Pi 5 or newer boards with a with a 32-bit OS. Please reinstall with a 64-bit OS.") shell.check_kernel_userspace_mismatch() main() diff --git a/pi-touch-cam.sh b/converted_shell_scripts/pi-touch-cam.sh similarity index 100% rename from pi-touch-cam.sh rename to converted_shell_scripts/pi-touch-cam.sh diff --git a/i2s_mic_module/README.md b/i2s_mic_module/README.md index f43c391..3b40987 100644 --- a/i2s_mic_module/README.md +++ b/i2s_mic_module/README.md @@ -16,7 +16,7 @@ Then do the following # Installing raspberrypi-kernel-headers works only if you haven't messed with # the rpi-update thing. # If you did, then you would have to do the rpi-source method -# to get the kernel headers. See: +# to get the kernel headers. See: # https://learn.adafruit.com/adafruit-i2s-mems-microphone-breakout/raspberry-pi-wiring-and-test#kernel-compiling $ sudo apt install dkms raspberrypi-kernel-headers @@ -24,8 +24,8 @@ $ sudo apt install dkms raspberrypi-kernel-headers $ sudo dpkg -i snd-i2s-rpi-dkms_0.0.2_all.deb # For this to work, remember to modify these first: -# /boot/config.txt -> dtparam=i2s=on -# and +# /boot/firmware/config.txt -> dtparam=i2s=on +# and # /etc/modules -> snd-bcm2835 # remember to reboot diff --git a/i2samp.py b/i2samp.py index 82a28c0..225af58 100644 --- a/i2samp.py +++ b/i2samp.py @@ -32,10 +32,8 @@ def main(): print("\nChecking hardware requirements...") # Enable I2S overlay - config = "/boot/firmware/config.txt" - if not os.path.exists(config): - config = "/boot/config.txt" - if not os.path.exists(config): + config = shell.get_boot_config() + if config is None: shell.bail("No Device Tree Detected, not supported") print(f"\nAdding Device Tree Entry to {config}") diff --git a/i2smic.py b/i2smic.py index b193292..6912bf7 100644 --- a/i2smic.py +++ b/i2smic.py @@ -9,6 +9,7 @@ shell = Shell() def main(): shell.clear() + boot_config = shell.get_boot_config() print("""This script downloads and installs I2S microphone support. """) @@ -56,10 +57,7 @@ Installing...""") ) # Enable I2S overlay - if os.path.exists("/boot/firmware/config.txt"): - shell.run_command("sed -i -e 's/#dtparam=i2s/dtparam=i2s/g' /boot/firmware/config.txt") - else: - shell.run_command("sed -i -e 's/#dtparam=i2s/dtparam=i2s/g' /boot/config.txt") + shell.run_command(f"sed -i -e 's/#dtparam=i2s/dtparam=i2s/g' {boot_config}") # Done print("""DONE. @@ -72,5 +70,8 @@ Settings take effect on next boot. # Main function if __name__ == "__main__": shell.require_root() + # Probably not necessary for now because the Pi 5 doesn't work anyway + if shell.is_raspberry_pi_os() and shell.is_kernel_userspace_mismatched() and shell.is_pi5_or_newer(): + shell.bail("Unable to proceed on Pi 5 or newer boards with a with a 32-bit OS. Please reinstall with a 64-bit OS.") shell.check_kernel_userspace_mismatch() main() diff --git a/pi-touch-cam.py b/pi-touch-cam.py index c5d5039..eb3a949 100755 --- a/pi-touch-cam.py +++ b/pi-touch-cam.py @@ -25,7 +25,7 @@ adafruit-pitft.sh installer script (for PiTFT display support) was run first. Operations performed include: -- In /boot/config.txt, enable camera +- In /boot/firmware/config.txt, enable camera - apt-get update - Install Python libraries: picamera, pygame, PIL @@ -37,33 +37,35 @@ Operations performed include: Run time 5+ minutes. Reboot required. """) + boot_config = shell.get_boot_config() + if not shell.prompt("CONTINUE?", default='n'): print("Canceled.") shell.exit() print("Continuing...") - if shell.grep("dtoverlay=pitft", "/boot/config.txt"): - shell.bail("PiTFT overlay not in /boot/config.txt.\n" + if shell.grep("dtoverlay=pitft", boot_config): + shell.bail(f"PiTFT overlay not in {boot_config}.\n" "Download & run adafruit-pitft.py first.\n" "Canceling.") print("Configuring camera + PiTFT settings...") # Set PiTFT speed to 80 MHz, 60 Hz - shell.pattern_replace("/boot/config.txt", "speed=.*,fps=.*", "speed=80000000,fps=60") + shell.pattern_replace(boot_config, "speed=.*,fps=.*", "speed=80000000,fps=60") # Check if Pi camera is enabled. If not, add it... - shell.reconfig("/boot/config.txt", "^start_x=.*", "start_x=1") + shell.reconfig(boot_config, "^start_x=.*", "start_x=1") # gpu_mem must be >= 128 MB for camera to work - result = shell.pattern_search("/boot/config.txt", "^gpu_mem=", return_match=True) + result = shell.pattern_search(boot_config, "^gpu_mem=", return_match=True) if not result: # gpu_mem isn't set. Add to config - shell.write_text_file("/boot/config.txt", "\ngpu_mem=128", append=True) + shell.write_text_file(boot_config, "\ngpu_mem=128", append=True) elif result.group(1) < 128: # gpu_mem present but too small; increase to 128MB - shell.reconfig("/boot/config.txt", "^gpu_mem=.*", "gpu_mem=128") + shell.reconfig(boot_config, "^gpu_mem=.*", "gpu_mem=128") print("Installing prerequisite packages...") diff --git a/raspi-blinka.py b/raspi-blinka.py index 66e422e..fb6b0eb 100644 --- a/raspi-blinka.py +++ b/raspi-blinka.py @@ -96,7 +96,7 @@ def install_blinka(user=False): # Custom function to run additional commands for Pi 5 def check_and_install_for_pi5(pi_model, user=False): - if pi_model.startswith("RASPBERRY_PI_5"): + if shell.is_pi5_or_newer(): username = None if user: username = os.environ["SUDO_USER"] @@ -112,7 +112,7 @@ def main(): shell.clear() # Check Raspberry Pi and Bail pi_model = shell.get_board_model() - if not pi_model: + if not shell.is_raspberry_pi(): shell.bail("This model of Raspberry Pi is not currently supported by Blinka") print("""This script configures your Raspberry Pi and installs Blinka diff --git a/rtc.py b/rtc.py index c92bdfd..b59cd10 100755 --- a/rtc.py +++ b/rtc.py @@ -63,7 +63,7 @@ CURRENT_SETTING = False UPDATED_DB = False BOOTCMD = "/boot/cmdline.txt" -CONFIG = "/boot/config.txt" +CONFIG = shell.get_boot_config() APTSRC = "/etc/apt/sources.list" INITABCONF = "/etc/inittab" BLACKLIST = "/etc/modprobe.d/raspi-blacklist.conf" @@ -74,7 +74,7 @@ def raspbian_old(): return shell.get_raspbian_version() in ("wheezy", "squeeze") def dt_check(): - # Check if /boot/config.txt exists and de + # Check if /boot/firmware/config.txt exists and de return shell.exists(CONFIG) and not shell.pattern_search(CONFIG, "^device_tree=$") #Perform all global variables declarations as well as function definition