diff --git a/builder/assets/clever_rename b/builder/assets/clever_rename new file mode 100755 index 00000000..8312af36 --- /dev/null +++ b/builder/assets/clever_rename @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +# Set Clever hostname to the specified value + +set -e + +NEW_NAME_OPT=$1 + +if [[ -z ${NEW_NAME_OPT} ]]; then + echo "Please specify new name for this Clever" + exit 1 +fi + +NEW_NAME=$(echo ${NEW_NAME_OPT} | tr '[:upper:]' '[:lower:]') + +echo "Setting name to ${NEW_NAME}" + +echo "Backing up /etc/hostname" +cp /etc/hostname /etc/hostname.bak +echo "Writing new /etc/hostname" +echo ${NEW_NAME} > /etc/hostname + +echo "Backing up /etc/hosts" +cp /etc/hosts /etc/hosts.bak +echo "Rewriting /etc/hosts with new values" +sed -i 's/127\.0\.1\.1.*/127.0.1.1\t'${NEW_NAME}'/g' /etc/hosts + +echo "Changing hostname in /lib/systemd/system/roscore.env" +sed -i 's/ROS_HOSTNAME=.*/ROS_HOSTNAME='${NEW_NAME}'.local/g' /lib/systemd/system/roscore.env + +echo "Changing hostname in .bashrc" +sed -i 's/export ROS_HOSTNAME=.*/export ROS_HOSTNAME='${NEW_NAME}'.local/g' /home/pi/.bashrc + +echo "Done, reboot your Clever to see the results" + diff --git a/builder/assets/init_rpi.sh b/builder/assets/init_rpi.sh index 94873288..4eec267e 100755 --- a/builder/assets/init_rpi.sh +++ b/builder/assets/init_rpi.sh @@ -32,7 +32,9 @@ echo_stamp() { } echo_stamp "Rename SSID" -sudo sed -i.OLD "s/CLEVER/CLEVER-$(head -c 100 /dev/urandom | xxd -ps -c 100 | sed -e 's/[^0-9]//g' | cut -c 1-4)/g" /etc/wpa_supplicant/wpa_supplicant.conf +NEW_SSID='CLEVER-'$(head -c 100 /dev/urandom | xxd -ps -c 100 | sed -e "s/[^0-9]//g" | cut -c 1-4) +sudo sed -i.OLD "s/CLEVER/${NEW_SSID}" /etc/wpa_supplicant/wpa_supplicant.conf +clever_rename ${NEW_SSID} echo_stamp "Harware setup" /root/hardware_setup.sh diff --git a/builder/image-build.sh b/builder/image-build.sh index 76d2ccb4..4680d89e 100755 --- a/builder/image-build.sh +++ b/builder/image-build.sh @@ -113,6 +113,8 @@ ${BUILDER_DIR}/image-chroot.sh ${IMAGE_PATH} copy ${SCRIPTS_DIR}'/assets/ros_pyt # Add PX4 udev rules ${BUILDER_DIR}/image-chroot.sh ${IMAGE_PATH} copy ${SCRIPTS_DIR}'/assets/99-px4fmu.rules' '/lib/udev/rules.d/' ${BUILDER_DIR}/image-chroot.sh ${IMAGE_PATH} copy ${SCRIPTS_DIR}'/assets/rosled.service' '/lib/systemd/system/' +# Add rename script +${BUILDER_DIR}/image-chroot.sh ${IMAGE_PATH} copy ${SCRIPTS_DIR}'/assets/clever_rename' '/usr/local/bin/clever_rename' ${BUILDER_DIR}/image-chroot.sh ${IMAGE_PATH} exec ${SCRIPTS_DIR}'/image-ros.sh' ${REPO_URL} ${IMAGE_VERSION} false false ${NUMBER_THREADS} ${BUILDER_DIR}/image-chroot.sh ${IMAGE_PATH} exec ${SCRIPTS_DIR}'/image-validate.sh'