diff --git a/.dockerignore b/.dockerignore index e7f7a4a927..e62639a471 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,3 +3,4 @@ work/ deploy/ apt-cacher-ng/ .git/objects/* +mender_work/ diff --git a/.gitignore b/.gitignore index 96a23b6acf..8c9680925d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ postrun.sh .pc *-pc apt-cacher-ng/ +mender_work/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 4bffa4aef1..0000000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,27 +0,0 @@ -stages: - - - Deploy - -before_script: - - git submodule update --remote - -Compile Base Software: - stage: Deploy - variables: - GIT_SUBMODULE_STRATEGY: recursive - GIT_STRATEGY: clone - GIT_DEPTH: 0 - script: - - echo Building the Base Software - - mkdir -p build - - cd build - - cmake .. - - make LeafletBaseSoftware - - ls - except: - - /^release\/[0-9]{1,2}.[0-9]{1,2}.[0-9]{1,2}-[0-9]{1,2}$/ - artifacts: - paths: - - build/* - expire_in: 1 day - tags: [Leaflet] diff --git a/build-docker.sh b/build-docker.sh index 85200e4c1a..636502a4b6 100755 --- a/build-docker.sh +++ b/build-docker.sh @@ -86,6 +86,7 @@ case "$(uname -m)" in esac ${DOCKER} build --build-arg BASE_IMAGE=${BASE_IMAGE} -t pi-gen "${DIR}" +#A.Pietsch: added -e "IMG_VERSION=${IMG_VERSION}"\ if [ "${CONTAINER_EXISTS}" != "" ]; then trap 'echo "got CTRL+C... please wait 5s" && ${DOCKER} stop -t 5 ${CONTAINER_NAME}_cont' SIGINT SIGTERM time ${DOCKER} run --rm --privileged \ @@ -95,6 +96,7 @@ if [ "${CONTAINER_EXISTS}" != "" ]; then ${PIGEN_DOCKER_OPTS} \ --volume "${CONFIG_FILE}":/config:ro \ -e "GIT_HASH=${GIT_HASH}" \ + -e "IMG_VERSION=${IMG_VERSION}"\ --volumes-from="${CONTAINER_NAME}" --name "${CONTAINER_NAME}_cont" \ pi-gen \ bash -e -o pipefail -c "dpkg-reconfigure qemu-user-static && @@ -103,6 +105,7 @@ if [ "${CONTAINER_EXISTS}" != "" ]; then wait "$!" else trap 'echo "got CTRL+C... please wait 5s" && ${DOCKER} stop -t 5 ${CONTAINER_NAME}' SIGINT SIGTERM + #A.Pietsch: added -e "IMG_VERSION=${IMG_VERSION}"\ time ${DOCKER} run --name "${CONTAINER_NAME}" --privileged \ --cap-add=ALL \ -v /dev:/dev \ @@ -110,6 +113,7 @@ else ${PIGEN_DOCKER_OPTS} \ --volume "${CONFIG_FILE}":/config:ro \ -e "GIT_HASH=${GIT_HASH}" \ + -e "IMG_VERSION=${IMG_VERSION}"\ pi-gen \ bash -e -o pipefail -c "dpkg-reconfigure qemu-user-static && cd /pi-gen; ./build.sh ${BUILD_OPTS} && diff --git a/build.sh b/build.sh index bcfdeb69ff..06945d31c9 100755 --- a/build.sh +++ b/build.sh @@ -192,10 +192,17 @@ if [ -z "${IMG_NAME}" ]; then exit 1 fi +# A.Pietsch: Added IMG_VERSION as mandatory Input parameter +if [ -z "${IMG_VERSION}" ]; then + echo "IMG_VERSION not set" 1>&2 + exit 1 +fi + export USE_QEMU="${USE_QEMU:-0}" export IMG_DATE="${IMG_DATE:-"$(date +%Y-%m-%d)"}" -export IMG_FILENAME="${IMG_FILENAME:-"${IMG_DATE}-${IMG_NAME}"}" -export ZIP_FILENAME="${ZIP_FILENAME:-"image_${IMG_DATE}-${IMG_NAME}"}" +# A.Pietsch: Changed IMGfilename +export IMG_FILENAME="${IMG_FILENAME:-"${IMG_NAME}-${IMG_VERSION}"}" +export ZIP_FILENAME="${ZIP_FILENAME:-"${IMG_NAME}-${IMG_VERSION}"}" export SCRIPT_DIR="${BASE_DIR}/scripts" export WORK_DIR="${WORK_DIR:-"${BASE_DIR}/work/${IMG_NAME}"}" @@ -228,6 +235,7 @@ export PUBKEY_SSH_FIRST_USER export CLEAN export IMG_NAME export APT_PROXY +export IMG_VERSION export STAGE export STAGE_DIR diff --git a/config b/config index 86c718a571..2cdb2e6205 100644 --- a/config +++ b/config @@ -1,8 +1,8 @@ -IMG_NAME=consolinno-buster +IMG_NAME=leafletpi_cems FIRST_USER_NAME="leaf" FIRST_USER_PASS="leaflet" TARGET_HOSTNAME="leaflet" ENABLE_SSH=1 -WPA_COUNTRY=GB +WPA_COUNTRY=DE diff --git a/export-image/04-finalise/01-run.sh b/export-image/04-finalise/01-run.sh index d7ace58d85..49c2ed2d61 100755 --- a/export-image/04-finalise/01-run.sh +++ b/export-image/04-finalise/01-run.sh @@ -55,26 +55,21 @@ rm -f "${ROOTFS_DIR}/etc/vnc/updateid" update_issue "$(basename "${EXPORT_DIR}")" install -m 644 "${ROOTFS_DIR}/etc/rpi-issue" "${ROOTFS_DIR}/boot/issue.txt" -cp "$ROOTFS_DIR/etc/rpi-issue" "$INFO_FILE" - +# A. Pietsch: modified info file +#cp "$ROOTFS_DIR/etc/rpi-issue" "$INFO_FILE" { - if [ -f "$ROOTFS_DIR/usr/share/doc/raspberrypi-kernel/changelog.Debian.gz" ]; then - firmware=$(zgrep "firmware as of" \ - "$ROOTFS_DIR/usr/share/doc/raspberrypi-kernel/changelog.Debian.gz" | \ - head -n1 | sed -n 's|.* \([^ ]*\)$|\1|p') - printf "\nFirmware: https://github.com/raspberrypi/firmware/tree/%s\n" "$firmware" + + # A. Pietsch: modified info file + printf "Consolinno Energy Leaflet Base Image\n\n" + printf "Image Name: ${IMG_FILENAME}\n" + printf "Hostname: ${TARGET_HOSTNAME}\n" - kernel="$(curl -s -L "https://github.com/raspberrypi/firmware/raw/$firmware/extra/git_hash")" - printf "Kernel: https://github.com/raspberrypi/linux/tree/%s\n" "$kernel" +} >> "$INFO_FILE" - uname="$(curl -s -L "https://github.com/raspberrypi/firmware/raw/$firmware/extra/uname_string7")" - printf "Uname string: %s\n" "$uname" - fi +# A.Pietsch: Add info about kernel and packages +cat ${ROOTFS_DIR}/etc/leafletimage.info >> "$INFO_FILE" - printf "\nPackages:\n" - dpkg -l --root "$ROOTFS_DIR" -} >> "$INFO_FILE" mkdir -p "${DEPLOY_DIR}" diff --git a/release-notes.txt b/release-notes.txt new file mode 100644 index 0000000000..d15e63c8f2 --- /dev/null +++ b/release-notes.txt @@ -0,0 +1,16 @@ +2021-10-06: + * Added Config Wizzard + * Updated Hotspot Tool + * Changed Motd + +2021-09-08: + * Updated Hotspot Tool + * Changed Motd + +2021-08-02: + * Consolinno Stage added + * Nymea Stage added + * Leaflet Hotspot added + * Leaflet Pi Kernel 5.4. added + * Sc16is752 Overlay added + diff --git a/stage1/01-sys-tweaks/00-run.sh b/stage1/01-sys-tweaks/00-run.sh index 9c380ec558..36252b281a 100755 --- a/stage1/01-sys-tweaks/00-run.sh +++ b/stage1/01-sys-tweaks/00-run.sh @@ -4,12 +4,13 @@ install -d "${ROOTFS_DIR}/etc/systemd/system/getty@tty1.service.d" install -m 644 files/noclear.conf "${ROOTFS_DIR}/etc/systemd/system/getty@tty1.service.d/noclear.conf" install -v -m 644 files/fstab "${ROOTFS_DIR}/etc/fstab" -on_chroot << EOF -if ! id -u ${FIRST_USER_NAME} >/dev/null 2>&1; then - adduser --disabled-password --gecos "" ${FIRST_USER_NAME} -fi -echo "${FIRST_USER_NAME}:${FIRST_USER_PASS}" | chpasswd -echo "root:root" | chpasswd -EOF +#A.Pietsch: remove First User +# on_chroot << EOF +# if ! id -u ${FIRST_USER_NAME} >/dev/null 2>&1; then +# adduser --disabled-password --gecos "" ${FIRST_USER_NAME} +# fi +# echo "${FIRST_USER_NAME}:${FIRST_USER_PASS}" | chpasswd +# #echo "root:root" | chpasswd +# EOF diff --git a/stage2/01-sys-tweaks/01-run.sh b/stage2/01-sys-tweaks/01-run.sh index bb3e11ac08..7d4cb0af41 100755 --- a/stage2/01-sys-tweaks/01-run.sh +++ b/stage2/01-sys-tweaks/01-run.sh @@ -48,14 +48,15 @@ systemctl enable resize2fs_once EOF fi -on_chroot </etc/apt/preferences.d/nymea -Package: * -Pin: release c=raspbian -Pin-Priority: 700 -Package: * -Pin: origin repository.nymea.io c=main -Pin-Priority: 500 +cat < /etc/apt/sources.list.d/consolinno.list +# leaflet repos +deb https://repo.services.consolinno.de buster main +deb https://repo.services.consolinno.de/live buster main EOM -apt-get update +wget -qO - http://repo.services.consolinno.de/repo_signing.key | apt-key add - + +# Update package list +apt update - cat < /etc/motd +# empty default motd (replaced by motd.sh) +cat < /etc/motd EOM - +# Update maschine Info cat < /etc/machine-info PRETTY_HOSTNAME=leaflet EOM +# Update issue.net cat < /etc/issue.net leaflet - consolinno.de | Debian GNU/Linux 10 EOM @@ -39,32 +30,41 @@ cat < /etc/issue leaflet - consolinno.de | Debian GNU/Linux 10 \n \l EOM +# Stop journal.d to syslog forward +echo -e "ForwardToSyslog=no" >> /etc/systemd/journald.conf +# Reduce write/read operations on Pi +echo -e "tmpfs /var/tmp tmpfs defaults,noatime,nosuid,size=30m 0 0"\ + >> /etc/fstab +echo -e "tmpfs /tmp tmpfs defaults,noatime,nosuid,size=100m 0 0" \ +>> /etc/fstab +echo -e "#uncomment if needed\n#tmpfs /var/log tmpfs "\ +" defaults,noatime,nosuid,size=20m 0 0" >> /etc/fstab +# Activate Watchdog +echo -e "RuntimeWatchdogSec=30s" >> /etc/systemd/system.conf +# Generate SSH Key +mkdir -p /root/.ssh/ -# Drop packages conflicting with network-manager -apt-get purge --yes openresolv dhcpcd5 - -# # Disable BlueZ plugins QtBluetooth can't deal with -# mkdir /etc/systemd/system/bluetooth.service.d -# cat < /etc/systemd/system/bluetooth.service.d/01-disable-battery-plugin.conf -# [Service] -# ExecStart= -# ExecStart=/usr/lib/bluetooth/bluetoothd --noplugin=battery,sap -# EOM - -# FS TAB -echo -e "tmpfs /var/tmp tmpfs defaults,noatime,nosuid,size=30m 0 0" >> /etc/fstab -echo -e "tmpfs /tmp tmpfs defaults,noatime,nosuid,size=100m 0 0" >> /etc/fstab -echo -e "#uncomment if needed\n#tmpfs /var/log tmpfs defaults,noatime,nosuid,size=20m 0 0" >> /etc/fstab +ssh-keygen -q -f /root/.ssh/id_rsa -N "" \ +-C "root@${TARGET_HOSTNAME}" +# Convert filename version x_x_x to x.x.x and store in Info +LPI_IMG_VERSION=$(echo "${IMG_VERSION}" | sed -e 's/_/\./g') +echo -e "LPI_IMG_VERSION=${LPI_IMG_VERSION}" >> /etc/leaflet/leaflet.info -# WATCHDOG -echo -e "RuntimeWatchdogSec=30s" >> /etc/systemd/system.conf +# Make First user use no sudo password +# touch /etc/sudoers.d/010_${FIRST_USER_NAME}-nopasswd +# echo -e "${FIRST_USER_NAME} ALL=(ALL) NOPASSWD: ALL" >> \ +# /etc/sudoers.d/010_${FIRST_USER_NAME}-nopasswd +# ssh key only +sed -i -Ee 's/^#?[[:blank:]]*PubkeyAuthentication[[:blank:]]*no[[:blank:]]*$/PubkeyAuthentication yes/ +s/^#?[[:blank:]]*PasswordAuthentication[[:blank:]]*yes[[:blank:]]*$/PasswordAuthentication no/' /etc/ssh/sshd_config -#MBUS TOOLS, CLI +# Drop packages conflicting with network-manager +apt-get purge --yes openresolv dhcpcd5 diff --git a/stage2/04-consolinno/02-packages b/stage2/04-consolinno/02-packages index 56976a7d6d..277b055c52 100644 --- a/stage2/04-consolinno/02-packages +++ b/stage2/04-consolinno/02-packages @@ -1,7 +1,11 @@ -nymea -nymea-plugins -nymea-networkmanager leafletbs-app +leafletbs-cli vim modpoll - +nmap +i2c-tools +jq +openvpn +gpiod +python3-pip +network-manager diff --git a/stage2/04-consolinno/files/01_motd.sh b/stage2/04-consolinno/files/01_motd.sh new file mode 100644 index 0000000000..6c312c4832 --- /dev/null +++ b/stage2/04-consolinno/files/01_motd.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +# @file motdh.sh +# @author A.Pietsch +# @brief Message of the Day for Leaflet Pi +# @version 0.1 +# @date 2021-07-01 +# +# @copyright Copyright (c) 2021 Consolinno Energy GmbH +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see +# +# Description: +# Message of the Day for Leaflet Pi + +# Uptime +let upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)" +let secs=$((${upSeconds}%60)) +let mins=$((${upSeconds}/60%60)) +let hours=$((${upSeconds}/3600%24)) +let days=$((${upSeconds}/86400)) +UPTIME=`printf "%d days, %02dh %02dm %02ds" "$days" "$hours" "$mins" "$secs"` + + + +# Storage +DISK1=`df -h | grep 'dev/root' | awk '{print $2}'` # Total +DISK2=`df -h | grep 'dev/root' | awk '{print $3}'` # Full +DISK3=`df -h | grep 'dev/root' | awk '{print $4}'` # Free + + + + +echo "$(tput setaf 2) +.__ _____.__ __ +| | _____ ____ / ____\ | _____/ |_ +| | / __ \\\__ \ | __\| | _/ __ \ __\\ +| |_\ ___// __ \| | | |_\ ___/| | +|____/\____ \___ /___| |____/\___ |__| + + +Consolinno Energy GmbH `date +"%A, %e %B %Y, %r"` +$(tput setaf 6) +SerialNumber.......: `lpi-identity.sh` +ImageVersion.......: `cat /etc/leaflet/leaflet.info | grep LPI_IMG_VERSION | cut -d '=' -f 2` +Uptime.............: ${UPTIME} +HotSpotName........: `sudo leaflet-network -m` +CPU Temperature....: `exec -- /opt/vc/bin/vcgencmd measure_temp | cut -c "6-9"` +BaseSoftwareVersion: `dpkg -s leafletbs-app | grep '^Version:' | cut -d ' ' -f2` +Disk Space.........: Total: $DISK1 | Used: $DISK2 | Free: $DISK3$(tput sgr0)" + + diff --git a/stage2/04-consolinno/files/leaflet.info b/stage2/04-consolinno/files/leaflet.info new file mode 100644 index 0000000000..733dfb687a --- /dev/null +++ b/stage2/04-consolinno/files/leaflet.info @@ -0,0 +1 @@ +# Info File for Consolinno Leaflet diff --git a/stage2/04-consolinno/files/lpi-identity.sh b/stage2/04-consolinno/files/lpi-identity.sh new file mode 100755 index 0000000000..9a3b567270 --- /dev/null +++ b/stage2/04-consolinno/files/lpi-identity.sh @@ -0,0 +1,65 @@ +#!/bin/bash + +# @file mender-inventory-oems +# @author A.Pietsch +# @brief get unique device id +# @version 0.1 +# @date 2021-07-01 +# +# @copyright Copyright (c) 2021 Consolinno Energy GmbH +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see +# +# Description: +# This script gets the mac id of the aprhrd_ether device wiht lowest index + + + + +set -ue + +SCN=/sys/class/net +min=65535 +arphrd_ether=1 +ifdev= + +# find iface with lowest ifindex, skip non ARPHRD_ETHER types (lo, sit ...) +for dev in $SCN/*; do + if [ ! -f "$dev/type" ]; then + continue + fi + + iftype=$(cat $dev/type) + if [ $iftype -ne $arphrd_ether ]; then + continue + fi + + # Skip dummy interfaces + if echo "$dev" | grep -q "$SCN/dummy" 2>/dev/null; then + continue + fi + + idx=$(cat $dev/ifindex) + if [ $idx -lt $min ]; then + min=$idx + ifdev=$dev + fi +done + +if [ -z "$ifdev" ]; then + echo "no suitable interfaces found" >&2 + exit 1 +else + + echo "$(cat $ifdev/address)" +fi diff --git a/stage2/04-consolinno/files/motd.sh b/stage2/04-consolinno/files/motd.sh deleted file mode 100644 index 8704a5a878..0000000000 --- a/stage2/04-consolinno/files/motd.sh +++ /dev/null @@ -1,41 +0,0 @@ -# MOTD -let upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)" -let secs=$((${upSeconds}%60)) -let mins=$((${upSeconds}/60%60)) -let hours=$((${upSeconds}/3600%24)) -let days=$((${upSeconds}/86400)) -UPTIME=`printf "%d days, %02dh %02dm %02ds" "$days" "$hours" "$mins" "$secs"` -LBS_Version=`apt-cache policy leafletbs-app | grep -F "Installed: "| grep -o "[0-9].*"` - -#Get Hotspot info -# HOTSPOT_SSID=`nmcli connection show LeafletHotSpot | grep "802-11-wireless.ssid:" | sed 's/[^[:space:]]*//' | sed 's/[[:space:]]*//'` -# nmcli connection show --active | grep -q LeafletHotSpot -# if [[ $? -ne 0 ]]; then -# HOTSPOT_STATUS="(inactive)" -# else -# HOTSPOT_STATUS="(active)" -# fi - -# Get Inet Status -ping -c1 -W1 -s1 8.8.8.8 > /dev/null 2>&1 -if [[ $? -ne 0 ]]; then - INET_CONNECTION="Not Active" -else - INET_CONNECTION="Active" -fi - -echo "$(tput setaf 2) -.__ _____.__ __ -| | _____ ____ / ____\ | _____/ |_ -| | / __ \\\__ \ | __\| | _/ __ \ __\\ -| |_\ ___// __ \| | | |_\ ___/| | -|____/\____ \___ /___| |____/\___ >__| - \/ \/ \/ - -`date +"%A, %e %B %Y, %r"` -Uptime: ${UPTIME}$(tput setaf 6) -CPU Temperature....: `exec -- /opt/vc/bin/vcgencmd measure_temp | cut -c "6-9"` -BaseSoftwareVersion: ${LBS_Version} -InternetStatus.....: ${INET_CONNECTION}$(tput sgr0)" - - diff --git a/stage2/05-cems/01-run-chroot.sh b/stage2/05-cems/01-run-chroot.sh new file mode 100644 index 0000000000..feac4861c2 --- /dev/null +++ b/stage2/05-cems/01-run-chroot.sh @@ -0,0 +1,7 @@ +#!/bin/bash -e + + + +# Add Custom Cems stage + + diff --git a/stage2/05-cems/02-packages b/stage2/05-cems/02-packages new file mode 100644 index 0000000000..e69de29bb2 diff --git a/stage2/05-cems/SKIP b/stage2/05-cems/SKIP new file mode 100644 index 0000000000..e69de29bb2 diff --git a/stage2/05-hems/01-run-chroot.sh b/stage2/05-hems/01-run-chroot.sh new file mode 100644 index 0000000000..ec889a5e90 --- /dev/null +++ b/stage2/05-hems/01-run-chroot.sh @@ -0,0 +1,28 @@ +#!/bin/bash -e + + + +# Add nymea repository +echo -e "\n## nymea repo\ndeb http://repository.nymea.io buster rpi\n#deb-src http://repository.nymea.io buster rpi\ndeb http://ci-repo.nymea.io/experimental-silo/ buster rpi non-free" | tee /etc/apt/sources.list.d/nymea.list +wget -qO - http://repository.nymea.io/repository-pubkey.gpg | apt-key add - + + +sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key A1A19ED6 +# Update package list +apt update + +# Set repository priority (prefer packages from raspbian section) +cat </etc/apt/preferences.d/nymea +Package: * +Pin: release c=raspbian +Pin-Priority: 700 +Package: * +Pin: origin repository.nymea.io c=main +Pin-Priority: 500 +EOM + +# Drop packages conflicting with network-manager +apt-get purge --yes openresolv +#apt-get purge --yes dhcpcd5 + + diff --git a/stage2/05-hems/02-packages b/stage2/05-hems/02-packages new file mode 100644 index 0000000000..221f660254 --- /dev/null +++ b/stage2/05-hems/02-packages @@ -0,0 +1,27 @@ +nymea +nymea-data +nymea-apikeysprovider-plugin-community +nymea-zeroconf-plugin-avahi +nymea-system-plugin-systemd +nymea-energy-plugin-consolinno +nymea-plugin-keba +nymea-plugin-systemmonitor +nymea-plugin-fronius +nymea-plugin-shelly +nymea-plugin-wallbe +nymea-plugin-openweathermap +nymea-plugin-webasto +nymea-plugin-sunspec +nymea-plugin-solarlog +nymea-plugin-sma +nymea-plugin-mypv +nymea-plugin-modbuscommander +nymea-plugin-idm +nymea-plugin-homeconnect +nymea-plugin-energymeters +nymea-plugin-drexelundweiss +nymea-plugin-datetime +nymea-plugin-awattar +nymea-plugin-goecharger +nymea-plugin-alphainnotec +nymea-plugin-kaco diff --git a/stage2/05-hems/SKIP b/stage2/05-hems/SKIP new file mode 100644 index 0000000000..e69de29bb2 diff --git a/stage2/06-Hotspot-Network/00-run.sh b/stage2/06-Hotspot-Network/00-run.sh new file mode 100755 index 0000000000..e9ef8f914e --- /dev/null +++ b/stage2/06-Hotspot-Network/00-run.sh @@ -0,0 +1,7 @@ +#!/bin/bash -e + +# Install network files +install -m 755 files/leaflet-network "${ROOTFS_DIR}/usr/bin/" +install -m 755 files/changehostname "${ROOTFS_DIR}/usr/bin/" +install -m 644 files/leaflet-network.service "${ROOTFS_DIR}/etc/systemd/system/" +install -m 755 files/network-settings.json "${ROOTFS_DIR}/etc/leaflet/" diff --git a/stage2/06-Hotspot-Network/01-run-chroot.sh b/stage2/06-Hotspot-Network/01-run-chroot.sh new file mode 100644 index 0000000000..604debdf2a --- /dev/null +++ b/stage2/06-Hotspot-Network/01-run-chroot.sh @@ -0,0 +1,11 @@ +#!/bin/bash -e + +########################### +# Leaflet Hotspot Settings +########################### + +# Adding executable right to hotspot script +chmod +x /usr/bin/leaflet-network +chmod +x /usr/bin/changehostname +# enable the hotspot service +systemctl enable leaflet-network.service diff --git a/stage2/06-Hotspot-Network/files/changehostname b/stage2/06-Hotspot-Network/files/changehostname new file mode 100755 index 0000000000..4fe33998b6 --- /dev/null +++ b/stage2/06-Hotspot-Network/files/changehostname @@ -0,0 +1,148 @@ +#!/bin/bash + +# @file changehostname +# @author A.Pietsch +# @brief +# @version 0.1 +# @date 2021-07-01 +# +# @copyright Copyright (c) 2021 Consolinno Energy GmbH +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see +# + + +# Check Root +if [ `whoami` != root ]; then + echo "Please run this script as root or using sudo" + exit 1 +fi + +HOTSPOT_CON_NAME=LeafletHotSpot +PERSISTENT_CONFIG="/data/leaflet/network-settings.json" +LOCAL_CONFIG="/etc/leaflet/network-settings.json" +if [[ -e $PERSISTENT_CONFIG ]]; then + + DEFAULT_CONFIG_PATH=$PERSISTENT_CONFIG +else + DEFAULT_CONFIG_PATH=$LOCAL_CONFIG +fi + + +Help() +{ + # Display Help + echo "changehostname:" + echo + echo "Syntax: changehostname -n "newname" | -c "pathtofile" " + echo "Sets new Hostname for Leaflet" + echo "options:" + echo "h show help." + echo "n hostname" + echo "c Read settings from json file path and update Hotspot" + echo "u Update Hostname after changes made to default Config file at:" + echo " /etc/leaflet/network-settings.json" + +} + +ChangeFromFile() +{ + + + # Change Hotspot settings parsed by file + if [[ -r ${DEFAULT_CONFIG_PATH} ]]; then + + echo "Updating Hostname" + else + echo "[ERROR] Configfile not found at ${DEFAULT_CONFIG_PATH}" + exit + fi + + HOSTNAME=$(cat ${DEFAULT_CONFIG_PATH} | jq -r .hostname) + if [[ -n ${HOTSPOTSSID} ]]; then + + echo "[CHANGE] Hotspot SSID = ${HOTSPOTSSID}" + nmcli con modify ${HOTSPOT_CON_NAME} 802-11-wireless.ssid ${HOTSPOTSSID} + fi + + + + if [[ -n ${HOSTNAME} ]]; then + + # change hosts file + OLDHOST=$(cat /etc/hostname) + echo "[CHANGE] Hostname ${OLDHOST} -> ${HOSTNAME}" + + echo "${HOSTNAME}" > /etc/hostname + sudo sed -i -e 's/'${OLDHOST}'/'${HOSTNAME}'/' /etc/hosts + + # apply new hostname + hostnamectl set-hostname ${HOSTNAME} + + # restart service + sudo systemctl restart avahi-daemon + + fi + + # Write Back Hostname to JSON File + cat <<< $(jq '.hostname = "'${HOSTNAME}'"' ${DEFAULT_CONFIG_PATH}) > ${DEFAULT_CONFIG_PATH} + +} +ChangeParsed() +{ + + if [[ -n ${HOSTNAME} ]]; then + + # change hosts file + OLDHOST=$(cat /etc/hostname) + echo "[CHANGE] Hostname ${OLDHOST} -> ${HOSTNAME}" + + echo "${HOSTNAME}" > /etc/hostname + sudo sed -i -e 's/'${OLDHOST}'/'${HOSTNAME}'/' /etc/hosts + + # apply new hostname + hostnamectl set-hostname ${HOSTNAME} + + # restart service + sudo systemctl restart avahi-daemon + + fi + + # Write Back Hostname to JSON File + cat <<< $(jq '.hostname = "'${HOSTNAME}'"' ${DEFAULT_CONFIG_PATH}) > ${DEFAULT_CONFIG_PATH} +} + + +# Read Arguments +while getopts "c:un:" arg; do + case $arg in + c) #Update Networksettings File + ChangeFromFile + exit;; + n) #Enter Name + HOSTNAME=${OPTARG} + ChangeParsed + exit;; + + h) Help + exit;; + ?) + echo "Invalid option: -${OPTARG}" + Help + exit 2 + ;; + esac +done + +Help + diff --git a/stage2/06-Hotspot-Network/files/leaflet-network b/stage2/06-Hotspot-Network/files/leaflet-network new file mode 100755 index 0000000000..ee4e21eedd --- /dev/null +++ b/stage2/06-Hotspot-Network/files/leaflet-network @@ -0,0 +1,324 @@ +#!/bin/bash + +# @file leaflet-network +# @author A.Pietsch +# @brief +# @version 0.2 +# @date 2021-07-01 +# +# @copyright Copyright (c) 2021 Consolinno Energy GmbH +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see +# +# Description: +# This script is intended to be run by leaflet-hotspot.service using +# the -k option. It will then creat the Hotspot and will keep it runnig +# by checking it periodicaly. +# It also features options to change the hotspot settings via json file with +# -c option. Run -h for further info + +# Check Root +if [ `whoami` != root ]; then + echo "Please run this script as root or using sudo" + exit 1 +fi + + + +HOTSPOT_CON_NAME=LeafletHotSpot +PERSISTENT_CONFIG="/data/leaflet/network-settings.json" +LOCAL_CONFIG="/etc/leaflet/network-settings.json" +if [[ -e $PERSISTENT_CONFIG ]]; then + + DEFAULT_CONFIG_PATH=$PERSISTENT_CONFIG +else + DEFAULT_CONFIG_PATH=$LOCAL_CONFIG +fi + + +Help() +{ + # Display Help + echo "leaflet-hotspot Tool:" + echo + echo "Syntax: leaflet-hotspot [-h|s|c]" + echo "Checks if LeafletHotspot is active and creates or reloads if not" + echo "options:" + echo "h show help." + echo "s show status" + echo "m shows SSID for motd" + echo "i Initializes Connection for first time" + echo "c Read settings from json file path and update Hotspot" + echo "u Update Hotspot after changes made to default Config file at:" + echo " /etc/leaflet/network-settings.json" + +} + +Show() +{ + # Check if connection exists if not create + nmcli connection show | grep -q ${HOTSPOT_CON_NAME} + if [[ $? = 0 ]]; then + + echo "Leaflet Hotspot Status: $(nmcli -g general.state connection show LeafletHotSpot)" + echo "SSID: $(nmcli -g 802-11-wireless.ssid connection show LeafletHotSpot)" + echo "Interface: $(nmcli -g connection.interface-name connection show LeafletHotSpot)" + echo "AdressRange: $(nmcli -g ipv4.addresses connection show LeafletHotSpot)" + return 0 + + else + echo "Leaflet Hotspot is not Setup (password set ?)" + return -1 + + fi +} + +Motd() +{ + # Check if connection exists if not create + nmcli connection show | grep -q ${HOTSPOT_CON_NAME} + if [[ $? = 0 ]]; then + + + echo "$(nmcli -g 802-11-wireless.ssid connection show LeafletHotSpot)" + return 0 + else + echo "Leaflet Hotspot is not Setup (password set ?)" + return -1 + fi +} + +Change() +{ + # Check if connection exists if not create + nmcli connection show | grep -q ${HOTSPOT_CON_NAME} + + if [[ $? = 0 ]]; then + + # Change Hotspot settings parsed by file + if [[ -r ${DEFAULT_CONFIG_PATH} ]]; then + + echo "Updating Hotspot to Settings" + else + echo "[ERROR] Configfile not found at ${DEFAULT_CONFIG_PATH}" + exit + fi + + # Read json + ETH0_IP=$(cat ${DEFAULT_CONFIG_PATH} | jq -r .eth0_ip) + ETH0_GATEWAY=$(cat ${DEFAULT_CONFIG_PATH} | jq -r .eth0_gateway) + ETH0_DNS=$(cat ${DEFAULT_CONFIG_PATH} | jq -r .eth0_dnsserver) + NTP_SERVER=$(cat ${DEFAULT_CONFIG_PATH} | jq -r .ntp_server) + + # Create Unique SSID based on Serial Number json SSID + HOTSPOT_DEFAULT_SSID=$(cat ${DEFAULT_CONFIG_PATH} | jq -r .wifi_ssid) + HOTSPOTPW=$(cat ${DEFAULT_CONFIG_PATH} | jq -r .wifi_pw) + HOTSPOTIP=$(cat ${DEFAULT_CONFIG_PATH} | jq -r .wifi_ip)"/24" + HOSTNAME=$(cat ${DEFAULT_CONFIG_PATH} | jq -r .hostname) + + if [[ -n ${ETH0_IP} && ${ETH0_IP} != "null" ]]; then + + echo "[CHANGE] Wired Connection IP = ${ETH0_IP}" + nmcli con modify Wired\ connection\ 1 ipv4.addresses ${ETH0_IP} + + else + nmcli con modify Wired\ connection\ 1 ipv4.addresses "" + fi + + if [[ -n ${ETH0_GATEWAY} && ${ETH0_GATEWAY} != "null" ]]; then + + echo "[CHANGE] Wired Connection GATEWAY = ${ETH0_GATEWAY}" + nmcli con modify Wired\ connection\ 1 ipv4.gateway ${ETH0_GATEWAY} + else + nmcli con modify Wired\ connection\ 1 ipv4.gateway "" + fi + + if [[ -n ${ETH0_DNS} && ${ETH0_DNS} != "null" ]]; then + + echo "[CHANGE] Wired Connection GATEWAY = ${ETH0_DNS}" + nmcli con modify Wired\ connection\ 1 ipv4.dns ${ETH0_DNS} + else + nmcli con modify Wired\ connection\ 1 ipv4.dns "" + fi + + if [[ -n ${HOTSPOT_DEFAULT_SSID} && ${HOTSPOT_DEFAULT_SSID} != "null" ]]; then + + echo "[CHANGE] Hotspot SSID = ${HOTSPOT_DEFAULT_SSID}" + nmcli con modify ${HOTSPOT_CON_NAME} 802-11-wireless.ssid ${HOTSPOT_DEFAULT_SSID} + fi + + if [[ -n ${HOTSPOTPW} && ${HOTSPOTPW} != "null" ]]; then + + echo "[CHANGE] Hotspot PW = ********" + nmcli con modify ${HOTSPOT_CON_NAME} wifi-sec.psk ${HOTSPOTPW} + fi + + if [[ -n ${HOTSPOTIP} && ${HOTSPOTIP} != "null" ]]; then + + echo "[CHANGE] Hotspot IP = ${HOTSPOTIP}" + nmcli con modify ${HOTSPOT_CON_NAME} ipv4.addresses ${HOTSPOTIP} + fi + + if [[ -n ${HOSTNAME} && ${HOSTNAME} != "null" ]]; then + + changehostname -n ${HOSTNAME} + + fi + + nmcli connection reload ${HOTSPOT_CON_NAME} + nmcli connection up ${HOTSPOT_CON_NAME} + + else + echo "Connection not setup. Initializing now." + Init + fi +} + +Init() +{ + + # Check if connection exists if not create + nmcli connection show | grep -q ${HOTSPOT_CON_NAME} + + + + if [[ $? = 0 ]]; then + echo "leaflet connection is set up already" + else + + # check if there is a + + + # Create Unique SSID based on Serial Number json SSID + HOTSPOT_DEFAULT_SSID=$(cat ${DEFAULT_CONFIG_PATH} | jq -r .wifi_ssid) + + HOTSPOTPW=$(cat ${DEFAULT_CONFIG_PATH} | jq -r .wifi_pw) + HOTSPOTIP=$(cat ${DEFAULT_CONFIG_PATH} | jq -r .wifi_ip)"/24" + + # Only activate if individual password was configured + if [[ ${HOTSPOTPW} = "nopassword" ]]; then + echo "No Passord set. Hotspot will not be started" + + else + + # Setup Hotspot + echo "setting up LeafletHotspot SSID: ${HOTSPOT_DEFAULT_SSID}" + nmcli con add type wifi ifname wlan0 con-name ${HOTSPOT_CON_NAME} autoconnect yes ssid ${HOTSPOT_DEFAULT_SSID} + if [[ $? -ne 0 ]]; then + + echo "Error Initalizing Hotspot. Check Settings" + nmcli con delete ${HOTSPOT_CON_NAME} + return -1 + fi + + nmcli con modify ${HOTSPOT_CON_NAME} 802-11-wireless.mode ap 802-11-wireless.band bg ipv4.method shared + if [[ $? -ne 0 ]]; then + + echo "Error Setting wireless mode. Check Settings" + nmcli con delete ${HOTSPOT_CON_NAME} + return -1 + fi + nmcli con modify ${HOTSPOT_CON_NAME} wifi-sec.key-mgmt wpa-psk + if [[ $? -ne 0 ]]; then + + echo "Error setting wpa setting. Check Settings" + nmcli con delete ${HOTSPOT_CON_NAME} + return -1 + fi + RetVal=$(nmcli con modify ${HOTSPOT_CON_NAME} wifi-sec.psk ${HOTSPOTPW}) + if [[ $? -ne 0 ]]; then + + echo "Error setting Hotspot Password. Check Password " + nmcli con delete ${HOTSPOT_CON_NAME} + return -1 + fi + RetVal=$(nmcli con modify ${HOTSPOT_CON_NAME} ipv4.addresses ${HOTSPOTIP}) + if [[ $? -ne 0 ]]; then + + echo "Error setting Hotspot IP. Check Settings" + nmcli con delete ${HOTSPOT_CON_NAME} + return -1 + fi + + nmcli connection reload ${HOTSPOT_CON_NAME} + nmcli connection up ${HOTSPOT_CON_NAME} + + fi + fi + +} + +Start() +{ + # Check if hotspot is running if not bring it up + nmcli connection show --active | grep -q ${HOTSPOT_CON_NAME} + if [[ $? -ne 0 ]]; then + nmcli connection show | grep -q ${HOTSPOT_CON_NAME} + if [[ $? -ne 0 ]]; then + echo "Leaflet Hotspot is not setup (password not set ?)" + Init + else + echo "Leaflet Hotspot is down" + nmcli connection reload ${HOTSPOT_CON_NAME} + nmcli connection up ${HOTSPOT_CON_NAME} + fi + fi + +} + +KeepUp() +{ + # Init Hotspot if not exists + Init + # Periodicaly Check if active and start Hotspot + while [ 1 ] + do + Start + sleep 1m + done +} +# Read Arguments +while getopts "c:usmhki" arg; do + case $arg in + c) #Update Networksettings File + FILEPATH=${OPTARG} + if [[ -r ${FILEPATH} ]]; then + cp -f ${FILEPATH} ${DEFAULT_CONFIG_PATH} + Change + else + echo "No ConfigFile parsed" + Help + fi + exit;; + u) Change + exit;; + h) Help + exit;; + s) Show + exit;; + m) Motd + exit;; + k) KeepUp + exit;; + i) Init + exit;; + ?) + echo "Invalid option: -${OPTARG}" + Help + exit 2 + ;; + esac +done + +Help + diff --git a/stage2/06-Hotspot/files/leaflet-hotspot.service b/stage2/06-Hotspot-Network/files/leaflet-network.service similarity index 67% rename from stage2/06-Hotspot/files/leaflet-hotspot.service rename to stage2/06-Hotspot-Network/files/leaflet-network.service index 2bc8bd83da..142301d1f5 100644 --- a/stage2/06-Hotspot/files/leaflet-hotspot.service +++ b/stage2/06-Hotspot-Network/files/leaflet-network.service @@ -1,12 +1,12 @@ [Unit] Description=Service running the Leaflet Hotspot -After=network-online.target +After=network-online.target NetworkManager.service StartLimitIntervalSec=500 StartLimitBurst=5 [Service] Type=simple -ExecStart=/usr/bin/leaflet-hotspot +ExecStart=/usr/bin/leaflet-network -k Restart=always RestartSec=10 diff --git a/stage2/06-Hotspot-Network/files/network-settings.json b/stage2/06-Hotspot-Network/files/network-settings.json new file mode 100644 index 0000000000..5ee1ea05fc --- /dev/null +++ b/stage2/06-Hotspot-Network/files/network-settings.json @@ -0,0 +1,10 @@ +{ + "hostname": "leaflet", + "#eth0_ip": "192.168.0.12/24", + "#eth0_gateway" : "irgendeineip", + "#eth0_dnsserver" : "8.8.8.8", + "#ntp_server" : "ip", + "wifi_pw": "nopassword", + "wifi_ssid": "Leaflet", + "wifi_ip": "192.168.101.1" +} diff --git a/stage2/06-Hotspot/00-run.sh b/stage2/06-Hotspot/00-run.sh deleted file mode 100755 index e659b1549e..0000000000 --- a/stage2/06-Hotspot/00-run.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -e - -#install -m 644 files/LeafletHotspot.nmconnection "${ROOTFS_DIR}/etc/NetworkManager/system-connections/" -install -m 755 files/leaflet-hotspot "${ROOTFS_DIR}/usr/bin/" -install -m 644 files/leaflet-hotspot.service "${ROOTFS_DIR}/etc/systemd/system/" diff --git a/stage2/06-Hotspot/01-run-chroot.sh b/stage2/06-Hotspot/01-run-chroot.sh deleted file mode 100644 index 354e104378..0000000000 --- a/stage2/06-Hotspot/01-run-chroot.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -e - - -#Adding Wifi Hotspot -chmod +x /usr/bin/leaflet-hotspot - -systemctl enable leaflet-hotspot.service diff --git a/stage2/06-Hotspot/files/LeafletHotspot.nmconnection b/stage2/06-Hotspot/files/LeafletHotspot.nmconnection deleted file mode 100644 index 2238c37d11..0000000000 --- a/stage2/06-Hotspot/files/LeafletHotspot.nmconnection +++ /dev/null @@ -1,27 +0,0 @@ -[connection] -id=LeafletHotspot -uuid=4ed9ac09-16d6-4fec-b243-0ee9146529b7 -type=wifi -interface-name=wlan0 -permissions= -timestamp=1621948119 - -[wifi] -band=bg -mac-address-blacklist= -mode=ap -seen-bssids=B8:27:EB:41:32:FB; -ssid=LeafletAP - -[wifi-security] -key-mgmt=wpa-psk -psk=consolinno - -[ipv4] -dns-search= -method=shared - -[ipv6] -addr-gen-mode=stable-privacy -dns-search= -method=auto diff --git a/stage2/06-Hotspot/files/leaflet-hotspot b/stage2/06-Hotspot/files/leaflet-hotspot deleted file mode 100755 index 65ac50da9e..0000000000 --- a/stage2/06-Hotspot/files/leaflet-hotspot +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash -HOTSPOT_CON_NAME=LeafletHotSpot -#HOTSPOT_IS_ACTIVE=TRUE -HOTSPOT_SSID=LeafletAP -HOTSPOT_DEFAULT_PW=consolinno - -# Check if connection exists if not create - -nmcli connection show | grep -q ${HOTSPOT_CON_NAME} - -if [[ $? = 0 ]]; then - - echo "leaflet connection is set up" -else - echo "setting up LeafletHotspot" - nmcli con add type wifi ifname wlan0 con-name ${HOTSPOT_CON_NAME} autoconnect yes ssid ${HOTSPOT_SSID} - nmcli con modify ${HOTSPOT_CON_NAME} 802-11-wireless.mode ap 802-11-wireless.band bg ipv4.method shared - nmcli con modify ${HOTSPOT_CON_NAME} wifi-sec.key-mgmt wpa-psk - nmcli con modify ${HOTSPOT_CON_NAME} wifi-sec.psk ${HOTSPOT_DEFAULT_PW} -fi - - -#Start Hotspot -echo "activating LeafletHotspot" -nmcli connection up ${HOTSPOT_CON_NAME} - - -# Periodicaly Check if active -while [ 1 ] -do -nmcli connection show --active | grep -q ${HOTSPOT_CON_NAME} -if [[ $? -ne 0 ]]; then - echo "Leaflet Hotspot is down" - nmcli connection reload ${HOTSPOT_CON_NAME} - nmcli connection up ${HOTSPOT_CON_NAME} -fi -sleep 1m -done - diff --git a/stage2/05-Hw-tweaks/00-packages b/stage2/07-Hw-tweaks/00-packages similarity index 100% rename from stage2/05-Hw-tweaks/00-packages rename to stage2/07-Hw-tweaks/00-packages diff --git a/stage2/05-Hw-tweaks/01-run.sh b/stage2/07-Hw-tweaks/01-run.sh similarity index 100% rename from stage2/05-Hw-tweaks/01-run.sh rename to stage2/07-Hw-tweaks/01-run.sh diff --git a/stage2/05-Hw-tweaks/02-run-chroot.sh b/stage2/07-Hw-tweaks/02-run-chroot.sh similarity index 90% rename from stage2/05-Hw-tweaks/02-run-chroot.sh rename to stage2/07-Hw-tweaks/02-run-chroot.sh index f8389a1d32..39cee7d19b 100644 --- a/stage2/05-Hw-tweaks/02-run-chroot.sh +++ b/stage2/07-Hw-tweaks/02-run-chroot.sh @@ -14,7 +14,7 @@ rm -r /usr/lib/leafletpi-kernel/ # Enable AMA0 if not for Mender -echo -e "\n# ttyAMA0/RS232\ndtoverlay=disable-bt\ndtoverlay=minuart-bt" >> /boot/config.txt +echo -e "\n# ttyAMA0/RS232\ndtoverlay=pi3-disable-bt\ndtoverlay=pi3-minuart-bt" >> /boot/config.txt # Hide console log messages and blinking cursor and activate the splash sed -i "s/console=tty1/console=tty3 quiet vt.global_cursor_default=0 splash/" "/boot/cmdline.txt" diff --git a/stage2/05-Hw-tweaks/files/leaflet-5-10.dts b/stage2/07-Hw-tweaks/files/leaflet-5-10.dts similarity index 100% rename from stage2/05-Hw-tweaks/files/leaflet-5-10.dts rename to stage2/07-Hw-tweaks/files/leaflet-5-10.dts diff --git a/stage2/05-Hw-tweaks/files/leaflet-5-4.dts b/stage2/07-Hw-tweaks/files/leaflet-5-4.dts similarity index 100% rename from stage2/05-Hw-tweaks/files/leaflet-5-4.dts rename to stage2/07-Hw-tweaks/files/leaflet-5-4.dts diff --git a/stage2/08-InfoFile/00-run.sh b/stage2/08-InfoFile/00-run.sh new file mode 100755 index 0000000000..6a7ad787af --- /dev/null +++ b/stage2/08-InfoFile/00-run.sh @@ -0,0 +1,4 @@ +#!/bin/bash -e + +# Install Info File +install -m 755 files/leafletimage.info "${ROOTFS_DIR}/etc/" diff --git a/stage2/08-InfoFile/02-run-chroot.sh b/stage2/08-InfoFile/02-run-chroot.sh new file mode 100644 index 0000000000..4b233b8762 --- /dev/null +++ b/stage2/08-InfoFile/02-run-chroot.sh @@ -0,0 +1,10 @@ +#!/bin/bash -e + +# Create Package List +INFO_FILE=/etc/leafletimage.info + +echo -e "Kernel $(dpkg -s leafletpi-kernel | grep -i '^Version:') \n\n" >> $"$INFO_FILE" + +echo -e "Installed Packages:\n\n $(dpkg-query --show) \n\n" >> $"$INFO_FILE" + + diff --git a/stage2/08-InfoFile/files/leafletimage.info b/stage2/08-InfoFile/files/leafletimage.info new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/stage2/08-InfoFile/files/leafletimage.info @@ -0,0 +1 @@ + diff --git a/stage2/09-LeafletConfigure/00-packages b/stage2/09-LeafletConfigure/00-packages new file mode 100644 index 0000000000..3f95446f14 --- /dev/null +++ b/stage2/09-LeafletConfigure/00-packages @@ -0,0 +1 @@ +leafletpi-kernel diff --git a/stage2/09-LeafletConfigure/01-run.sh b/stage2/09-LeafletConfigure/01-run.sh new file mode 100755 index 0000000000..5a457190d5 --- /dev/null +++ b/stage2/09-LeafletConfigure/01-run.sh @@ -0,0 +1,7 @@ +#!/bin/bash -e + +install -m 755 files/leaflet-configure "${ROOTFS_DIR}/usr/bin/" +install -m 755 files/leaflet-wizzard "${ROOTFS_DIR}/usr/bin/" +install -m 755 files/02_launchwizzard.sh "${ROOTFS_DIR}/etc/profile.d/" +install -m 644 files/leaflet-configure.service "${ROOTFS_DIR}/etc/systemd/system/" + diff --git a/stage2/09-LeafletConfigure/02-run-chroot.sh b/stage2/09-LeafletConfigure/02-run-chroot.sh new file mode 100644 index 0000000000..36d1995a30 --- /dev/null +++ b/stage2/09-LeafletConfigure/02-run-chroot.sh @@ -0,0 +1,20 @@ +#!/bin/bash -e + +########################### +# Leaflet Hotspot Settings +########################### + +# Adding executable right to hotspot script +chmod +x /usr/bin/leaflet-wizzard +chmod +x /usr/bin/leaflet-configure + + +# Disable Leaflet Base Software by default (gets activated when leafletis +# configured) +systemctl disable leafletbs.service +# enable the leaflet-configure service(this will reactivate basesoftware) +systemctl enable leaflet-configure.service + + +# create notconfigured file +touch /.notconfigured diff --git a/stage2/09-LeafletConfigure/SKIP b/stage2/09-LeafletConfigure/SKIP new file mode 100644 index 0000000000..e69de29bb2 diff --git a/stage2/09-LeafletConfigure/files/02_launchwizzard.sh b/stage2/09-LeafletConfigure/files/02_launchwizzard.sh new file mode 100755 index 0000000000..579045ab07 --- /dev/null +++ b/stage2/09-LeafletConfigure/files/02_launchwizzard.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# @file leaflet-preconf +# @author A.Pietsch +# @brief +# @version 0.1 +# @date 2021-07-01 +# +# @copyright Copyright (c) 2021 Consolinno Energy GmbH +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see +# +# Description: +# This script will run once at first boot and make configurations + + + +sudo leaflet-wizzard +return $? + diff --git a/stage2/09-LeafletConfigure/files/leaflet-configure b/stage2/09-LeafletConfigure/files/leaflet-configure new file mode 100755 index 0000000000..d704ba7fe6 --- /dev/null +++ b/stage2/09-LeafletConfigure/files/leaflet-configure @@ -0,0 +1,76 @@ +#!/bin/bash + +# @file leaflet-preconf +# @author A.Pietsch +# @brief +# @version 0.1 +# @date 2021-07-01 +# +# @copyright Copyright (c) 2021 Consolinno Energy GmbH +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see +# +# Description: +# This script will run once at first boot and make configurations + +PRECONFIGURED="/.preconfigured" +NOTCONFIGURED="/.notconfigured" + + +# Check if configured +if [[ -f ${NOTCONFIGURED} ]]; then + + echo "THIS LEAFLET IS NOT CONFIGURED" + echo "Base Software is not running yet" + + +elif [[ -f ${PRECONFIGURED} ]]; then + echo "THIS LEAFLET IS PRECONFIGURED" + echo "load presettings" + exit 0 + +else + echo "THIS LEAFLET IS CONFIGURED" + echo "enabling Basesoftware and removing Wizzard" + systemctl disable leaflet-configure.service + mv /etc/profile.d/02_launchwizzard.sh / + chmod -x /usr/bin/leaflet-wizzard + systemctl enable leafletbs.service + systemctl start leafletbs.service + exit 0 +fi + +# Blink ALL Leds for Setup Mode + +BLINKER=0 + + + +while true; do + + if [[ $BLINKER = 1 ]]; then + BLINKER=0 + + else + BLINKER=1 + fi + + sleep 0.5 + + gpioset 3 0=$BLINKER + gpioset 3 1=$BLINKER + gpioset 3 2=$BLINKER + +done + + diff --git a/stage2/09-LeafletConfigure/files/leaflet-configure.service b/stage2/09-LeafletConfigure/files/leaflet-configure.service new file mode 100644 index 0000000000..9f1121ff82 --- /dev/null +++ b/stage2/09-LeafletConfigure/files/leaflet-configure.service @@ -0,0 +1,11 @@ +[Unit] +Description=Leaflet Configuration Service +After=leaflet-hotspot.service +Before=rc-local.service +ConditionFileNotEmpty=/usr/bin/leaflet-configure +[Service] +ExecStart=/usr/bin/leaflet-configure +Type=oneshot +RemainAfterExit=no +[Install] +WantedBy=multi-user.target diff --git a/stage2/09-LeafletConfigure/files/leaflet-wizzard b/stage2/09-LeafletConfigure/files/leaflet-wizzard new file mode 100755 index 0000000000..4f900655bf --- /dev/null +++ b/stage2/09-LeafletConfigure/files/leaflet-wizzard @@ -0,0 +1,211 @@ +#!/bin/bash + +# @file leaflet-preconf +# @author A.Pietsch +# @brief +# @version 0.1 +# @date 2021-07-01 +# +# @copyright Copyright (c) 2021 Consolinno Energy GmbH +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see +# +# Description: +# This script will run once at first boot and make configurations + + +# Check Root +if [ `whoami` != root ]; then + echo "Please run this script as root or using sudo" + exit 1 +fi + +HOTSPOT_CON_NAME=LeafletHotSpot +PERSISTENT_CONFIG="/data/leaflet/network-settings.json" +LOCAL_CONFIG="/etc/leaflet/network-settings.json" +if [[ -e $PERSISTENT_CONFIG ]]; then + + DEFAULT_CONFIG_PATH=$PERSISTENT_CONFIG +else + DEFAULT_CONFIG_PATH=$LOCAL_CONFIG +fi + +RunWizzard() +{ + +##################### USER PASSWORD +echo "$(tput setaf 2) +################################################################### +###################### Leaflet Setup Wizzard ###################### +################################################################### +$(tput sgr0) +Before you can start we need to set some passwords first. + +$(tput setaf 2) +######################### User Password ##########################$(tput sgr0) +Please enter the Password for the user $(tput setaf 2)leaf$(tput sgr0) (login password)" + + sudo passwd + +if [[ $? != 0 ]]; then +echo "$(tput setaf 2) +######################### User Password ##########################$(tput sgr0)" +echo "$(tput setaf 1)ERROR:$(tput sgr0) Password was not set. Please relog in this console to restart +the wizzard" +exit 1 + +fi + + +##################### HOTSPOT SSID +echo "$(tput setaf 2) +########################## Hotspot Name ##########################$(tput sgr0)" +HOTSPOTNAMEOK=1 + + +while [[ $HOTSPOTNAMEOK -eq 1 ]];do +echo "Please enter a Name for the the Wifi Hotspot (minimum 8 symbols). +Just press Enter if you want to use default SSID (ConsolinnoEnergy):" + + +read HOTSPOTNAME + +if [[ -z $HOTSPOTNAME ]]; then + HOTSPOTNAME="ConsolinnoEnergy" + HOTSPOTNAMEOK=0 +else +# Check password lenght +LENGHT=`expr length "$HOTSPOTNAME"` + + if [[ $LENGHT -lt 8 ]]; then +echo "$(tput setaf 1)ERROR:$(tput sgr0) Hotspot name is to short." + else +echo "Hotspot name will be: $HOTSPOTNAME" + HOTSPOTNAMEOK=0 + fi +fi +done + +##################### WIFI PASSWORD +echo "$(tput setaf 2) +######################### WiFi Password ########################## +$(tput sgr0)" + +PASSWORDNOTOK=1 + +while [[ $PASSWORDNOTOK -eq 1 ]];do +echo -n "Enter new Wifi Password(minimum 8 symbols): +" + +#get Password 1 +read -s PASSWORD1 +# Get the Hotspot Password 2 + +echo"" +echo -n "Retype new Wifi Password: +" +read -s PASSWORD2 + + + +# Check password lenght +LENGHT=`expr length "$PASSWORD1"` + +if [[ $LENGHT -lt 8 ]]; then +echo "$(tput setaf 1)ERROR:$(tput sgr0) Wifi Password is to short." + +elif [[ $PASSWORD1 != $PASSWORD2 ]]; then +echo "$(tput setaf 1)ERROR:$(tput sgr0) Wifi Passwords do not match." + +else +echo "Password for WiFi set." + PASSWORDNOTOK=0 +fi + +done +echo "$(tput setaf 2) +####################### Configuration done ####################### +$(tput sgr0)" +echo "$(tput setaf 2)We are ready now to save some Energy!" +echo "Leaflet is now rebooting..." + +# Write Back Password to JSON File +cat <<< $(jq '.wifi_pw = "'${PASSWORD1}'"' ${DEFAULT_CONFIG_PATH}) > ${DEFAULT_CONFIG_PATH} + +# Write Back SSID to JSON File +cat <<< $(jq '.wifi_ssid = "'${HOTSPOTNAME}'"' ${DEFAULT_CONFIG_PATH}) > ${DEFAULT_CONFIG_PATH} +# Update Hotspot +leaflet-hotspot -u > /dev/null 2>&1 +if [[ $? != 0 ]]; then +echo "$(tput setaf 1)ERROR:$(tput sgr0)UUuuuuups...Setting Hotspot failed. Please relog in this console to restart the wizzard" +exit 1 +fi +# Remove Setup Mode +rm /.notconfigured +reboot now +} + +ResetDefault() +{ + echo "$(tput setaf 1)You are about to Reset the Leaflet to Default settings!" + echo "Are you sure? type \"letmedothis\": " + + read SECURITYQUESTION + + if [[ $SECURITYQUESTION == "letmedothis" ]]; then + echo "Here we go:" + + # Reset Default Wifi Settings + # Write Back Hostname to JSON File + cat <<< $(jq '.wifi_pw = "consolinno"' ${DEFAULT_CONFIG_PATH}) > ${DEFAULT_CONFIG_PATH} + + # Write Back SSID to JSON File + cat <<< $(jq '.wifi_ssid = "LeafletSetup"' ${DEFAULT_CONFIG_PATH}) > ${DEFAULT_CONFIG_PATH} + # Update Hotspot + leaflet-hotspot -u > /dev/null 2>&1 + if [[ $? != 0 ]]; then + + # Write Back Hostname to JSON File + echo "ERROR: Setting Hotspot failed. Please relog in this console to restart the wizzard" + exit 1 + fi + + systemctl enable leaflet-configure.service + mv /02_leafletwizzarddone.sh /etc/profile.d/02_leafletwizzard.sh + systemctl disable leafletbs.service + systemctl stop leafletbs.service + touch /.notconfigured + echo "rebooting now..." + reboot now + exit 0 + + fi + echo "$(tput setaf 2)Aborted...$(tput sgr0)" + exit 1 + +} +# Read Arguments +while getopts "r" arg; do + case $arg in + r) #Update Networksettings File + ResetDefault + exit;; + ?) + echo "Invalid option: -${OPTARG}" + Help + exit 2 + ;; + esac +done + +RunWizzard diff --git a/stage2/EXPORT_IMAGE b/stage2/EXPORT_IMAGE index aa8f936488..79ec11a3d0 100644 --- a/stage2/EXPORT_IMAGE +++ b/stage2/EXPORT_IMAGE @@ -1,4 +1,4 @@ -IMG_SUFFIX="-lite" +IMG_SUFFIX="" if [ "${USE_QEMU}" = "1" ]; then export IMG_SUFFIX="${IMG_SUFFIX}-qemu" fi