<commit_before>#!/bin/sh
#
# Installer script for Freetronics PiLeven support on Raspberry Pi.
#
# This installer does up to 4 things:
#
# * (Pi 3 only), adds a Device Tree overlay to move the Bluetooth
#   serial UART connection to the "mini-UART" to free up the main UART for PiLeven.
#
# * Disable Linux console serial UART output (via kernel command line
#   and systemd getty or inittab)
#
# * Adds a "udev rule" to configure the built-in serial port & GPIO
#   pins at startup so they will work with PiLeven & Arduino
#
#   (GPIO 17 is set to UART0 RTS (ALT3), GPIOs 14 & 15 are set to
#    UART0 TX/RX (ALT0).
#
# * Installs wiringpi for the /usr/bin/gpio pin configuration tool.
#
if [ `id -u` -ne 0 ]; then
    echo "This install script needs to be run as root"
    exit 1
fi

echo "Installing PiLeven support..."
echo "***"

for SERIAL in ttyAMA0 serial0; do

    if grep -q =${SERIAL} /boot/cmdline.txt 2>/dev/null; then
		if ! [ -f /boot/cmdline.txt.prepilv ]; then
  			echo "Backing up /boot/cmdline.txt as /boot/cmdline.txt.prepilv..."
			cp /boot/cmdline.txt /boot/cmdline.txt.prepilv
		fi
		echo "Disabling Linux console output to serial port ${SERIAL}..."
		# matches console=${SERIAL},12345 or kgdboc=${SERIAL},12345
		sed -i "s/[a-z]*=${SERIAL}[0-9,]* *//g" /boot/cmdline.txt
	elif ! [ -e /boot/cmdline.txt ]; then
		echo "WARNING: /boot/cmdline.txt not found. You will need to manually remove any console=${SERIAL} line from kernel boot arguments!"
	fi

done

echo "***"

if [ -f /dev/inittab ] && grep ttyAMA0 /etc/inittab 2>/dev/null; then
	echo "Disabling serial port login console in /etc/inittab..."
	sed -i 's/.\+ttyAMA0/#\0/' /etc/inittab
elif [ -x /bin/systemctl ]; then
	echo "Disabling serial port console..."
	/bin/systemctl disable serial-getty@ttyAMA0.service # silent if doesn't exist
	/bin/systemctl disable serial-getty@serial0.service
else
    echo "WARNING: Console mechanism not found. You will need to disable the ttyAMA0/serial0 console manually."
fi

echo "***"

if [ -d /etc/udev/rules.d ]; then
    echo "Installing new udev rule /etc/udev/rules.d/99-PiLeven-ttyAMA0-config.rules"
    cat > /etc/udev/rules.d/99-PiLeven-ttyAMA0-config.rules <<EOF
# /dev/ttyAMA0 needs two things (apart from disabled console) to work with Freetronics PiLeven
#
# - RTS pin on GPIO 17 needs to be enabled, this acts as auto-reset for Arduino upload.
# - A symlink as /dev/ttyS99 is created as the Arduino IDE doesn't see /dev/ttyAMA0 as a valid serial port
#
KERNEL=="ttyAMA0", ACTION=="add", SYMLINK+="ttyS99", RUN+="/usr/bin/gpio -g mode 17 alt3", RUN+="/usr/bin/gpio -g mode 14 alt0", RUN+="/usr/bin/gpio -g mode 15 alt0"
EOF
else
    echo "WARNING: no directory /etc/udev/rules.d. Cannot installed the PiLeven udev rule."
fi<commit_msg>PiLeven udev rules: Set serial port group to 'dialout' if such a group exists<commit_after>#!/bin/sh
#
# Installer script for Freetronics PiLeven support on Raspberry Pi.
#
# This installer does up to 4 things:
#
# * (Pi 3 only), adds a Device Tree overlay to move the Bluetooth
#   serial UART connection to the "mini-UART" to free up the main UART for PiLeven.
#
# * Disable Linux console serial UART output (via kernel command line
#   and systemd getty or inittab)
#
# * Adds a "udev rule" to configure the built-in serial port & GPIO
#   pins at startup so they will work with PiLeven & Arduino
#
#   (GPIO 17 is set to UART0 RTS (ALT3), GPIOs 14 & 15 are set to
#    UART0 TX/RX (ALT0).
#
# * Installs wiringpi for the /usr/bin/gpio pin configuration tool.
#
if [ `id -u` -ne 0 ]; then
    echo "This install script needs to be run as root"
    exit 1
fi

echo "Installing PiLeven support..."
echo "***"

for SERIAL in ttyAMA0 serial0; do

    if grep -q =${SERIAL} /boot/cmdline.txt 2>/dev/null; then
		if ! [ -f /boot/cmdline.txt.prepilv ]; then
  			echo "Backing up /boot/cmdline.txt as /boot/cmdline.txt.prepilv..."
			cp /boot/cmdline.txt /boot/cmdline.txt.prepilv
		fi
		echo "Disabling Linux console output to serial port ${SERIAL}..."
		# matches console=${SERIAL},12345 or kgdboc=${SERIAL},12345
		sed -i "s/[a-z]*=${SERIAL}[0-9,]* *//g" /boot/cmdline.txt
	elif ! [ -e /boot/cmdline.txt ]; then
		echo "WARNING: /boot/cmdline.txt not found. You will need to manually remove any console=${SERIAL} line from kernel boot arguments!"
	fi

done

echo "***"

if [ -f /dev/inittab ] && grep ttyAMA0 /etc/inittab 2>/dev/null; then
	echo "Disabling serial port login console in /etc/inittab..."
	sed -i 's/.\+ttyAMA0/#\0/' /etc/inittab
elif [ -x /bin/systemctl ]; then
	echo "Disabling serial port console..."
	/bin/systemctl disable serial-getty@ttyAMA0.service # silent if doesn't exist
	/bin/systemctl disable serial-getty@serial0.service
else
    echo "WARNING: Console mechanism not found. You will need to disable the ttyAMA0/serial0 console manually."
fi

echo "***"

if [ -d /etc/udev/rules.d ]; then
    echo "Installing new udev rule /etc/udev/rules.d/99-PiLeven-ttyAMA0-config.rules"
    cat > /etc/udev/rules.d/99-PiLeven-ttyAMA0-config.rules <<EOF
# /dev/ttyAMA0 needs three things (apart from disabled console) to work with Freetronics PiLeven
#
# - RTS pin on GPIO 17 needs to be enabled, this acts as auto-reset for Arduino upload.
# - A symlink as /dev/ttyS99 is created as the Arduino IDE doesn't see /dev/ttyAMA0 as a valid serial port
# - Set group to 'dialout' if a dialout group exists on this system.
#
KERNEL=="ttyAMA0", ACTION=="add", SYMLINK+="ttyS99", RUN+="/usr/bin/gpio -g mode 17 alt3", RUN+="/usr/bin/gpio -g mode 14 alt0", RUN+="/usr/bin/gpio -g mode 15 alt0", GROUP="dialout"
EOF
else
    echo "WARNING: no directory /etc/udev/rules.d. Cannot installed the PiLeven udev rule."
fi
{'fraction_non_alphanumeric': 0.12627506155469576, 'fraction_numerical': 0.021456208230742173, 'mean_word_length': 3.4188034188034186, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7085698', 'n_tokens_mistral': 2133, 'n_tokens_neox': 1971, 'n_words': 721}