diff --git a/build_raspOVOS.sh b/build_raspOVOS.sh index e9dd777..eca29b8 100644 --- a/build_raspOVOS.sh +++ b/build_raspOVOS.sh @@ -8,22 +8,8 @@ set -e # Update package list and install necessary tools echo "Updating base system..."ã apt-get update -apt-get install -y --no-install-recommends git curl systemd-zram-generator i2c-tools swig libssl-dev libfann-dev portaudio19-dev libpulse-dev build-essential python3-dev python3-pip linux-cpupower +apt-get install -y --no-install-recommends git curl i2c-tools swig libssl-dev libfann-dev portaudio19-dev libpulse-dev build-essential python3-dev python3-pip -# setup ovos-i2csound -echo "Installing ovos-i2csound..." -git clone https://github.com/OpenVoiceOS/ovos-i2csound /tmp/ovos-i2csound - -mkdir /etc/OpenVoiceOS - -cp /tmp/ovos-i2csound/i2c.conf /etc/modules-load.d/i2c.conf -cp /tmp/ovos-i2csound/bcm2835-alsa.conf /etc/modules-load.d/bcm2835-alsa.conf -cp /tmp/ovos-i2csound/i2csound.service /etc/systemd/system/i2csound.service -cp /tmp/ovos-i2csound/ovos-i2csound /usr/libexec/ovos-i2csound -cp /tmp/ovos-i2csound/99-i2c.rules /usr/lib/udev/rules.d/99-i2c.rules - -chmod +x /usr/libexec/ovos-i2csound -systemctl enable i2csound.service # Create virtual environment for ovos echo "Creating virtual environment..." @@ -35,13 +21,13 @@ source ~/.venvs/ovos/bin/activate # install OVOS in venv echo "Installing OVOS..." +pip3 install wheel cython pip3 install sdnotify tflite_runtime pip3 install ovos-core[lgpl,mycroft,plugins,skills-audio,skills-essential,skills-internet,skills-media] pip3 install ovos-dinkum-listener[extras,linux,onnx] pip3 install ovos-phal[extras,linux,mk1] - echo "Setting up systemd..." # copy system scripts over mkdir -p /home/pi/.config/systemd/user/ @@ -53,6 +39,9 @@ cp -v /mounted-github-repo/ovos-dinkum-listener.service /home/pi/.config/systemd cp -v /mounted-github-repo/ovos-phal.service /home/pi/.config/systemd/user/ cp -v /mounted-github-repo/ovos-admin-phal.service /etc/systemd/system/ +systemctl --user daemon-reload +systemctl daemon-reload + systemctl --user enable ovos systemctl --user enable ovos-messagebus systemctl --user enable ovos-dinkum-listener @@ -61,184 +50,28 @@ systemctl --user enable ovos-skills systemctl --user enable ovos-phal systemctl enable ovos-admin-phal -systemctl --user daemon-reload -systemctl daemon-reload -#chown -v pi:pi /home/pi/README.md - - -# tuning - -# Define the backup file -FSTAB="/etc/fstab" -BACKUP="/etc/fstab.bak" - -# Make a backup of the original /etc/fstab -cp "$FSTAB" "$BACKUP" -echo "Backup of /etc/fstab created at $BACKUP" - -# Process /etc/fstab -while IFS= read -r line; do - # Skip comments and empty lines - if [[ "$line" =~ ^# ]] || [[ -z "$line" ]]; then - echo "$line" - continue - fi - - # Match lines with ext4, xfs, or btrfs filesystems - if [[ "$line" =~ ^(\S+)\s+(\S+)\s+(ext4|xfs|btrfs)\s+([^#]*)\s+(\d+)\s+(\d+)$ ]]; then - DEVICE="${BASH_REMATCH[1]}" - MOUNTPOINT="${BASH_REMATCH[2]}" - FSTYPE="${BASH_REMATCH[3]}" - OPTIONS="${BASH_REMATCH[4]}" - DUMP="${BASH_REMATCH[5]}" - PASS="${BASH_REMATCH[6]}" - - # Check if "noatime" is already present - if [[ ! "$OPTIONS" =~ noatime ]]; then - OPTIONS="$OPTIONS,noatime" - fi - - # Check if "nodiratime" is already present - if [[ ! "$OPTIONS" =~ nodiratime ]]; then - OPTIONS="$OPTIONS,nodiratime" - fi - - # Print the updated line - echo -e "$DEVICE\t$MOUNTPOINT\t$FSTYPE\t$OPTIONS\t$DUMP\t$PASS" - else - # Print lines that do not match the filesystem types - echo "$line" - fi -done < "$FSTAB" > "${FSTAB}.tmp" - -# Replace the original fstab with the updated one -mv "${FSTAB}.tmp" "$FSTAB" -echo "Updated /etc/fstab with noatime and nodiratime options." - - -# Configure the CPU governor to "performance" -CONFIG_FILE="/etc/default/cpupower" -if [[ -f "$CONFIG_FILE" ]]; then - sed -i 's/^CPU_DEFAULT_GOVERNOR=.*/CPU_DEFAULT_GOVERNOR="performance"/' "$CONFIG_FILE" -else - echo 'CPU_DEFAULT_GOVERNOR="performance"' > "$CONFIG_FILE" -fi - -# Create the cpu governor systemd service file -cp -v /mounted-github-repo/cpu-governor.service /etc/systemd/system/cpu-governor.service -# Set permissions, enable, and start the service -chmod 644 /etc/systemd/system/cpu-governor.service -systemctl daemon-reload -systemctl enable cpu-governor.service -echo "CPU governor set to performance and service enabled" - -# Load I2C, SPI, and I2S kernel modules and make persistent -for module in i2c-dev spidev; do - if ! grep -q "$module" /etc/modules; then - echo "$module" >> /etc/modules - fi - modprobe "$module" -done - -# Enable I2C, SPI, and I2S in /boot/config.txt -CONFIG_FILE="/boot/config.txt" - -declare -A dtparams=( - ["dtparam=i2c_arm"]="on" - ["dtparam=spi"]="on" - ["dtparam=i2s"]="on" -) - -for key in "${!dtparams[@]}"; do - value="${dtparams[$key]}" - if grep -q "^${key}=" "$CONFIG_FILE"; then - sed -i "s|^${key}=.*|${key}=${value}|" "$CONFIG_FILE" - else - echo "${key}=${value}" >> "$CONFIG_FILE" - fi -done - -echo "Kernel modules and Device Tree parameters configured." - -# Define the sysctl configuration file -SYSCTL_FILE="/etc/sysctl.d/99-ovos.conf" - -# Sysctl options to apply -declare -A sysctl_options=( - ["net.ipv4.tcp_slow_start_after_idle"]=0 - ["net.ipv4.tcp_tw_reuse"]=1 - ["net.core.netdev_max_backlog"]=50000 - ["net.ipv4.tcp_max_syn_backlog"]=30000 - ["net.ipv4.tcp_max_tw_buckets"]=2000000 - ["net.core.rmem_max"]=16777216 - ["net.core.wmem_max"]=16777216 - ["net.core.rmem_default"]=16777216 - ["net.core.wmem_default"]=16777216 - ["net.ipv4.tcp_rmem"]="4096 87380 16777216" - ["net.ipv4.tcp_wmem"]="4096 65536 16777216" - ["net.core.optmem_max"]=40960 - ["fs.inotify.max_user_instances"]=8192 - ["fs.inotify.max_user_watches"]=524288 -) - -# Create or update sysctl configuration -echo "# OVOS kernel tuning parameters" > "$SYSCTL_FILE" -for option in "${!sysctl_options[@]}"; do - echo "$option = ${sysctl_options[$option]}" >> "$SYSCTL_FILE" -done - -echo "Kernel tuning parameters applied. Configuration saved to $SYSCTL_FILE." - - -# Define the udev rules file path -UDEV_RULES_FILE="/etc/udev/rules.d/60-mmc-usb-scheduler.rules" - -# Check if the rules file exists and create if necessary -if [ ! -f "$UDEV_RULES_FILE" ]; then - echo "Creating udev rules file at $UDEV_RULES_FILE" - touch "$UDEV_RULES_FILE" - chown root:root "$UDEV_RULES_FILE" - chmod 644 "$UDEV_RULES_FILE" -fi - -# Add I/O scheduler rules for MMC and USB -echo 'ACTION=="add|change", KERNEL=="mmc*", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="none"' >> "$UDEV_RULES_FILE" -echo 'ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{removable}=="1", ATTR{queue/scheduler}="none"' >> "$UDEV_RULES_FILE" - -echo "I/O scheduler rules applied for MMC and USB devices." - - -echo "Copying wlan0-power systemd service to /etc/systemd/system/wlan0-power.service" -cp -v /mounted-github-repo/wlan0-power.service /etc/systemd/system/wlan0-power.service -sudo systemctl daemon-reload -sudo systemctl enable wlan0-power.service -echo "wlan0-power service is now enabled." - - - -# ZRAM -cp -v /mounted-github-repo/zram-generator.conf /etc/systemd/zram-generator.conf - - -SYSCTL_CONF="/etc/sysctl.d/98-zram.conf" - - -# Configure sysctl settings for ZRAM -echo "Applying sysctl settings for ZRAM..." -cat < "$CONFIG_FILE" +fi + +# Create the cpu governor systemd service file +cp -v /mounted-github-repo/cpu-governor.service /etc/systemd/system/cpu-governor.service +# Set permissions, enable, and start the service +chmod 644 /etc/systemd/system/cpu-governor.service +systemctl daemon-reload +systemctl enable cpu-governor.service +echo "CPU governor set to performance and service enabled" diff --git a/setup_fstab.sh b/setup_fstab.sh new file mode 100644 index 0000000..c0b0183 --- /dev/null +++ b/setup_fstab.sh @@ -0,0 +1,49 @@ +#!/bin/bash +# Exit on error +# If something goes wrong just stop. +# it allows the user to see issues at once rather than having +# scroll back and figure out what went wrong. +set -e + + +# Define the backup file +FSTAB="/etc/fstab" + +# Process /etc/fstab +while IFS= read -r line; do + # Skip comments and empty lines + if [[ "$line" =~ ^# ]] || [[ -z "$line" ]]; then + echo "$line" + continue + fi + + # Match lines with ext4, xfs, or btrfs filesystems + if [[ "$line" =~ ^(\S+)\s+(\S+)\s+(ext4|xfs|btrfs)\s+([^#]*)\s+(\d+)\s+(\d+)$ ]]; then + DEVICE="${BASH_REMATCH[1]}" + MOUNTPOINT="${BASH_REMATCH[2]}" + FSTYPE="${BASH_REMATCH[3]}" + OPTIONS="${BASH_REMATCH[4]}" + DUMP="${BASH_REMATCH[5]}" + PASS="${BASH_REMATCH[6]}" + + # Check if "noatime" is already present + if [[ ! "$OPTIONS" =~ noatime ]]; then + OPTIONS="$OPTIONS,noatime" + fi + + # Check if "nodiratime" is already present + if [[ ! "$OPTIONS" =~ nodiratime ]]; then + OPTIONS="$OPTIONS,nodiratime" + fi + + # Print the updated line + echo -e "$DEVICE\t$MOUNTPOINT\t$FSTYPE\t$OPTIONS\t$DUMP\t$PASS" + else + # Print lines that do not match the filesystem types + echo "$line" + fi +done < "$FSTAB" > "${FSTAB}.tmp" + +# Replace the original fstab with the updated one +mv "${FSTAB}.tmp" "$FSTAB" +echo "Updated /etc/fstab with noatime and nodiratime options." diff --git a/setup_kernel_modules.sh b/setup_kernel_modules.sh new file mode 100644 index 0000000..9df10c6 --- /dev/null +++ b/setup_kernel_modules.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# Exit on error +# If something goes wrong just stop. +# it allows the user to see issues at once rather than having +# scroll back and figure out what went wrong. +set -e + + +# Load I2C, SPI, and I2S kernel modules and make persistent +for module in i2c-dev spidev; do + if ! grep -q "$module" /etc/modules; then + echo "$module" >> /etc/modules + fi + modprobe "$module" +done + +# Enable I2C, SPI, and I2S in /boot/config.txt +CONFIG_FILE="/boot/config.txt" + +declare -A dtparams=( + ["dtparam=i2c_arm"]="on" + ["dtparam=spi"]="on" + ["dtparam=i2s"]="on" +) + +for key in "${!dtparams[@]}"; do + value="${dtparams[$key]}" + if grep -q "^${key}=" "$CONFIG_FILE"; then + sed -i "s|^${key}=.*|${key}=${value}|" "$CONFIG_FILE" + else + echo "${key}=${value}" >> "$CONFIG_FILE" + fi +done + +echo "Kernel modules and Device Tree parameters configured." diff --git a/setup_sysctl.sh b/setup_sysctl.sh new file mode 100644 index 0000000..4bccf5e --- /dev/null +++ b/setup_sysctl.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# Exit on error +# If something goes wrong just stop. +# it allows the user to see issues at once rather than having +# scroll back and figure out what went wrong. +set -e + +# Define the sysctl configuration file +SYSCTL_FILE="/etc/sysctl.d/99-ovos.conf" + +# Sysctl options to apply +declare -A sysctl_options=( + ["net.ipv4.tcp_slow_start_after_idle"]=0 + ["net.ipv4.tcp_tw_reuse"]=1 + ["net.core.netdev_max_backlog"]=50000 + ["net.ipv4.tcp_max_syn_backlog"]=30000 + ["net.ipv4.tcp_max_tw_buckets"]=2000000 + ["net.core.rmem_max"]=16777216 + ["net.core.wmem_max"]=16777216 + ["net.core.rmem_default"]=16777216 + ["net.core.wmem_default"]=16777216 + ["net.ipv4.tcp_rmem"]="4096 87380 16777216" + ["net.ipv4.tcp_wmem"]="4096 65536 16777216" + ["net.core.optmem_max"]=40960 + ["fs.inotify.max_user_instances"]=8192 + ["fs.inotify.max_user_watches"]=524288 +) + +# Create or update sysctl configuration +echo "# OVOS kernel tuning parameters" > "$SYSCTL_FILE" +for option in "${!sysctl_options[@]}"; do + echo "$option = ${sysctl_options[$option]}" >> "$SYSCTL_FILE" +done + +echo "Kernel tuning parameters applied. Configuration saved to $SYSCTL_FILE." + + diff --git a/setup_udev.sh b/setup_udev.sh new file mode 100644 index 0000000..177c7d5 --- /dev/null +++ b/setup_udev.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# Exit on error +# If something goes wrong just stop. +# it allows the user to see issues at once rather than having +# scroll back and figure out what went wrong. +set -e + + +# Define the udev rules file path +UDEV_RULES_FILE="/etc/udev/rules.d/60-mmc-usb-scheduler.rules" + +# Check if the rules file exists and create if necessary +if [ ! -f "$UDEV_RULES_FILE" ]; then + echo "Creating udev rules file at $UDEV_RULES_FILE" + touch "$UDEV_RULES_FILE" + chown root:root "$UDEV_RULES_FILE" + chmod 644 "$UDEV_RULES_FILE" +fi + +# Add I/O scheduler rules for MMC and USB +echo 'ACTION=="add|change", KERNEL=="mmc*", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="none"' >> "$UDEV_RULES_FILE" +echo 'ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{removable}=="1", ATTR{queue/scheduler}="none"' >> "$UDEV_RULES_FILE" + +echo "I/O scheduler rules applied for MMC and USB devices." + + diff --git a/setup_wlan0power.sh b/setup_wlan0power.sh new file mode 100644 index 0000000..db6ed25 --- /dev/null +++ b/setup_wlan0power.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# Exit on error +# If something goes wrong just stop. +# it allows the user to see issues at once rather than having +# scroll back and figure out what went wrong. +set -e + + +echo "Copying wlan0-power systemd service to /etc/systemd/system/wlan0-power.service" +cp -v /mounted-github-repo/wlan0-power.service /etc/systemd/system/wlan0-power.service +sudo systemctl daemon-reload +sudo systemctl enable wlan0-power.service +echo "wlan0-power service is now enabled." + diff --git a/setup_zram.sh b/setup_zram.sh new file mode 100644 index 0000000..a803ad3 --- /dev/null +++ b/setup_zram.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# Exit on error +# If something goes wrong just stop. +# it allows the user to see issues at once rather than having +# scroll back and figure out what went wrong. +set -e + +# ZRAM +echo "Setting up ZRAM..." +apt-get install -y --no-install-recommends systemd-zram-generator + +cp -v /mounted-github-repo/zram-generator.conf /etc/systemd/zram-generator.conf +SYSCTL_CONF="/etc/sysctl.d/98-zram.conf" + +# Configure sysctl settings for ZRAM +echo "Applying sysctl settings for ZRAM..." +cat <