#!/bin/bash . /usr/lib/wb-utils/wb_env.sh wb_source "of" # generate u-boot env config before config-package debheler UBOOT_DIR="/usr/share/wb-configs/u-boot" UBOOT_FNAME="fw_env.config.wb" if of_machine_match "allwinner,sun50i-h616"; then FVER="sun50i" elif of_machine_match "allwinner,sun8i-r40"; then FVER="sun8i" elif of_machine_match "fsl,imx6ul" || of_machine_match "fsl,imx6ull"; then FVER="imx6" elif of_machine_match "fsl,imx28" || of_machine_match "fsl,imx23"; then FVER="mxs" else FVER="default" fi cp "${UBOOT_DIR}/${UBOOT_FNAME}.${FVER}" "/etc/${UBOOT_FNAME}" ours=.wb theirs=.wb-orig # Remove diversion of sshd_configs from wb-configs which # was accidently left unattended # These functions are taken from config-package-dev heplers # with modifications which allow to remove diversions from # other packages wb_undisplace_unlink_symlink() { file="$1" ourfile="$2" theirfile="$3" if [ ! -L "$file" ] || \ [ "$(readlink "$file")" != "$(basename "$ourfile")" -a \ "$(readlink "$file")" != "$(basename "$theirfile")" ]; then echo "*** OMINOUS WARNING ***: $file is not linked to either $(basename "$ourfile") or $(basename "$theirfile")" >&2 else rm -f "$file" fi } wb_undisplace_unlink_displace() { file="$1" if [ ! -L "$file" ] && [ ! -e "$file" ]; then echo "Run dpkg-divert --remove..." dpkg-divert --remove --rename "$file" else echo "Not removing diversion of $file by $package" >&2 fi } wb_undisplace_unlink() { prefix=$1 suffix=$2 file=$prefix$suffix ourfile=$prefix$ours$suffix theirfile=$prefix$theirs$suffix wb_undisplace_unlink_symlink "$file" "$ourfile" "$theirfile" wb_undisplace_unlink_displace "$file" } wb_check_undisplace_unlink_from() { prefix=$1 suffix=$2 from_package=$3 from_version=$4 file=$prefix$suffix ourfile=$prefix$ours$suffix theirfile=$prefix$theirs$suffix if LC_ALL=C dpkg-divert --list "$from_package" | \ grep -xFq "diversion of $file to $theirfile by $from_package" && dpkg --compare-versions `dpkg-query -f '${Version}' -W "$from_package"` "lt" "$from_version"; then echo "Picking up diversion of $file from $package to replace it with our one" wb_undisplace_unlink "$prefix" "$suffix" "$from_package" fi } if [ "$1" = "configure" ]; then wb_check_undisplace_unlink_from /etc/ssh/sshd_config "" wb-configs "1.75.4" fi # Automatically added by dh_systemd_enable/13.3.4 if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then # This will only remove masks created by d-s-h on package removal. deb-systemd-helper unmask 'wb-configs-early.service' >/dev/null || true # was-enabled defaults to true, so new installations run enable. if deb-systemd-helper --quiet was-enabled 'wb-configs-early.service'; then # Enables the unit on first installation, creates new # symlinks on upgrades if the unit file has changed. deb-systemd-helper enable 'wb-configs-early.service' >/dev/null || true else # Update the statefile to add new symlinks (if any), which need to be # cleaned up on purge. Also remove old symlinks. deb-systemd-helper update-state 'wb-configs-early.service' >/dev/null || true fi fi # End automatically added section # Automatically added by dh_systemd_enable/13.3.4 if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then # This will only remove masks created by d-s-h on package removal. deb-systemd-helper unmask 'wb-configs.service' >/dev/null || true # was-enabled defaults to true, so new installations run enable. if deb-systemd-helper --quiet was-enabled 'wb-configs.service'; then # Enables the unit on first installation, creates new # symlinks on upgrades if the unit file has changed. deb-systemd-helper enable 'wb-configs.service' >/dev/null || true else # Update the statefile to add new symlinks (if any), which need to be # cleaned up on purge. Also remove old symlinks. deb-systemd-helper update-state 'wb-configs.service' >/dev/null || true fi fi # End automatically added section # Automatically added by dh_systemd_enable/13.3.4 if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then # This will only remove masks created by d-s-h on package removal. deb-systemd-helper unmask 'wb-systime-adjust.service' >/dev/null || true # was-enabled defaults to true, so new installations run enable. if deb-systemd-helper --quiet was-enabled 'wb-systime-adjust.service'; then # Enables the unit on first installation, creates new # symlinks on upgrades if the unit file has changed. deb-systemd-helper enable 'wb-systime-adjust.service' >/dev/null || true else # Update the statefile to add new symlinks (if any), which need to be # cleaned up on purge. Also remove old symlinks. deb-systemd-helper update-state 'wb-systime-adjust.service' >/dev/null || true fi fi # End automatically added section # Automatically added by dh_systemd_start/13.3.4 if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then if [ -d /run/systemd/system ]; then systemctl --system daemon-reload >/dev/null || true if [ -n "$2" ]; then _dh_action=restart else _dh_action=start fi deb-systemd-invoke $_dh_action 'wb-configs.service' >/dev/null || true fi fi # End automatically added section # Automatically added by dh_systemd_start/13.3.4 if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then if [ -d /run/systemd/system ]; then systemctl --system daemon-reload >/dev/null || true if [ -n "$2" ]; then deb-systemd-invoke try-restart 'wb-systime-adjust.service' >/dev/null || true fi fi fi # End automatically added section # Automatically added by dh_configpackage/UNDECLARED # displace.sh.in: diversion helpers for maintainer scripts # # displace_link # # Ensures that the file is properly diverted to # .divert-orig by this package, and becomes a # symbolic link to either .divert (default) or # .divert-orig. # # undisplace_unlink # # Undoes the action of displace_link specified # above. # # Version: 4.0 # # Copyright © 2008–2012 Tim Abbott and Anders # Kaseorg # # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation files # (the “Software”), to deal in the Software without restriction, # including without limitation the rights to use, copy, modify, merge, # publish, distribute, sublicense, and/or sell copies of the Software, # and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # package=wb-configs ours=.wb theirs=.wb-orig displace_link_divert() { file=$1 ourfile=$2 theirfile=$3 if ! LC_ALL=C dpkg-divert --list "$package" | \ grep -xFq "diversion of $file to $theirfile by $package"; then dpkg-divert --divert "$theirfile" --rename --package "$package" --add "$file" fi } displace_link_symlink() { file=$1 ourfile=$2 theirfile=$3 if [ ! -L "$file" ] && [ ! -e "$file" ]; then ln -s "$(basename "$ourfile")" "$file" elif [ ! -L "$file" ] || \ [ "$(readlink "$file")" != "$(basename "$ourfile")" -a \ "$(readlink "$file")" != "$(basename "$theirfile")" ]; then echo "*** OMINOUS WARNING ***: $file is not linked to either $(basename "$ourfile") or $(basename "$theirfile")" >&2 fi } displace_link() { prefix=$1 suffix=$2 file=$prefix$suffix ourfile=$prefix$ours$suffix theirfile=$prefix$theirs$suffix displace_link_divert "$file" "$ourfile" "$theirfile" displace_link_symlink "$file" "$ourfile" "$theirfile" } displace_hide() { file=$1 ourfile="" theirfile=$2 displace_link_divert "$file" "$ourfile" "$theirfile" } undisplace_unlink_symlink() { file="$1" ourfile="$2" theirfile="$3" if [ ! -L "$file" ] || \ [ "$(readlink "$file")" != "$(basename "$ourfile")" -a \ "$(readlink "$file")" != "$(basename "$theirfile")" ]; then echo "*** OMINOUS WARNING ***: $file is not linked to either $(basename "$ourfile") or $(basename "$theirfile")" >&2 else rm -f "$file" fi } undisplace_unlink_divert() { file="$1" if [ ! -L "$file" ] && [ ! -e "$file" ]; then dpkg-divert --remove --rename --package "$package" "$file" else echo "Not removing diversion of $file by $package" >&2 fi } undisplace_unlink() { prefix=$1 suffix=$2 file=$prefix$suffix ourfile=$prefix$ours$suffix theirfile=$prefix$theirs$suffix undisplace_unlink_symlink "$file" "$ourfile" "$theirfile" undisplace_unlink_divert "$file" } undisplace_unhide() { file=$1 undisplace_unlink_divert "$file" } check_undisplace_unlink() { prefix=$1 suffix=$2 file=$prefix$suffix ourfile=$prefix$ours$suffix theirfile=$prefix$theirs$suffix if LC_ALL=C dpkg-divert --list "$package" | \ grep -xFq "diversion of $file to $theirfile by $package"; then undisplace_unlink "$prefix" "$suffix" fi } check_undisplace_unhide() { file=$1 hiddenfile=$2 if LC_ALL=C dpkg-divert --list "$package" | \ grep -xFq "diversion of $file to $hiddenfile by $package"; then undisplace_unhide "$file" fi } # End of displace.sh.in if [ "$1" = "configure" ] || [ "$1" = "abort-remove" ]; then check_undisplace_unlink /etc/ssh/sshd_config check_undisplace_unlink /lib/systemd/system/networking.service check_undisplace_unlink /root/.config/mosquitto_sub check_undisplace_unlink /root/.config/mosquitto_pub check_undisplace_unlink /etc/ssl/openssl.cnf displace_link /root/.bashrc displace_link /etc/locale.gen displace_link /etc/hostname displace_link /etc/modules displace_link /etc/inittab displace_link /etc/fstab displace_link /etc/gai.conf displace_link /etc/default/rcS displace_link /etc/hosts displace_link /etc/network/interfaces displace_link /etc/dnsmasq.conf displace_link /etc/hostapd.conf displace_link /etc/default/hostapd displace_link /etc/watchdog.conf displace_link /etc/ppp/chap-secrets displace_link /etc/ppp/ip-up.d/0000usepeerdns displace_link /etc/nginx/sites-available/default displace_link /etc/nfc/libnfc.conf displace_link /etc/lirc/hardware.conf displace_link /etc/sysctl.conf displace_link /etc/default/avahi-daemon displace_link /etc/nsswitch.conf displace_link /etc/fw_env.config displace_link /etc/e2fsck.conf displace_link /etc/ssh/sshd_config displace_link /etc/avahi/avahi-daemon.conf displace_link /etc/systemd/journald.conf displace_link /etc/rsyslog.conf fi # End automatically added section # Automatically added by dh_installdeb/13.3.4 dpkg-maintscript-helper rm_conffile /etc/kernel/postinst.d/zImage-uboot -- "$@" dpkg-maintscript-helper rm_conffile /etc/init.d/wb-configs 1.76\~ -- "$@" dpkg-maintscript-helper rm_conffile /etc/apt/sources.list.d/contactless.list 1.76\~ -- "$@" dpkg-maintscript-helper rm_conffile /etc/apt/sources.list.d/wheezy-backports.list 1.76\~ -- "$@" dpkg-maintscript-helper rm_conffile /etc/apt/sources.list.d/nodesource.list 3.30.1\~ -- "$@" dpkg-maintscript-helper rm_conffile /etc/apt/preferences 1.78\~ -- "$@" dpkg-maintscript-helper rm_conffile /etc/preferences 1.78\~ -- "$@" dpkg-maintscript-helper rm_conffile /etc/mosquitto/conf.d/auth.conf 3.0.0\~ -- "$@" dpkg-maintscript-helper rm_conffile /etc/mosquitto/conf.d/listeners.conf 3.0.0\~ -- "$@" dpkg-maintscript-helper rm_conffile /etc/mosquitto/conf.d/bridge.conf 3.0.0\~ -- "$@" dpkg-maintscript-helper rm_conffile /etc/mosquitto/conf.d/bridge.conf.example 3.0.0\~ -- "$@" dpkg-maintscript-helper rm_conffile /etc/mosquitto/conf.d/30limits.conf 3.22.0\~ -- "$@" dpkg-maintscript-helper rm_conffile /etc/ssl/openssl.cnf 3.22.1\~ -- "$@" # End automatically added section # Automatically added by dh_installinit/13.3.4 if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then if [ -x "/etc/init.d/wb-configs-early" ]; then update-rc.d wb-configs-early defaults >/dev/null if [ -n "$2" ]; then _dh_action=restart else _dh_action=start fi invoke-rc.d wb-configs-early $_dh_action || exit 1 fi fi # End automatically added section # Automatically added by dh_installinit/13.3.4 if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then if [ -x "/etc/init.d/wb-configs" ]; then update-rc.d wb-configs defaults >/dev/null if [ -n "$2" ]; then _dh_action=restart else _dh_action=start fi invoke-rc.d wb-configs $_dh_action || exit 1 fi fi # End automatically added section # Automatically added by dh_installinit/13.3.4 if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then if [ -x "/etc/init.d/wb-systime-adjust" ]; then update-rc.d wb-systime-adjust defaults >/dev/null if [ -n "$2" ]; then _dh_action=restart else _dh_action=start fi invoke-rc.d wb-systime-adjust $_dh_action || exit 1 fi fi # End automatically added section . /etc/wb-prepare.d/01udev-rules # install hw-specific udev rules if dpkg-query -s rsyslog >/dev/null 2>/dev/null; then rm -f /etc/logrotate.d/messages fi rm -f /etc/logrotate.d/rsyslog rm -f /etc/update-motd.d/10-uname # remove default Debian motd if [[ -f /etc/motd ]] && [[ $(sha256sum /etc/motd | head -c 6) == 'a37897' ]]; then rm -f /etc/motd ln -s /var/run/motd /etc/motd fi deb-systemd-invoke reload nginx || true # comment old patched mosquitto's `allow_anonymous_localhost` out # or it will break new mosquitto launch OPT_REGEX='^\s*\(allow_anonymous_localhost\)' if grep -q -R --include=\*.conf "$OPT_REGEX" /etc/mosquitto/; then DEPR_MSG="allow_anonymous_localhost is deprecated, use per listener settings from mosquitto 2.0" echo "WARNING: $DEPR_MSG" find /etc/mosquitto/ -name '*.conf' \ -exec grep -q '^\s*allow_anonymous_localhost' '{}' \; \ -exec sed -i.wb-bak3 "s/${OPT_REGEX}/# ${DEPR_MSG}\n#\1/" '{}' \; fi # this flag may be created in preinst MOSQUITTO_UPGRADE_FLAG=/var/lib/wirenboard/.mosquitto2-upgrade-restart-required if [ -f $MOSQUITTO_UPGRADE_FLAG ]; then echo "mosquitto configs are updated, restarting mosquitto and all Wiren Board MQTT services" deb-systemd-invoke restart mosquitto rm $MOSQUITTO_UPGRADE_FLAG -rf fi deb-systemd-invoke restart rsyslog || true deb-systemd-invoke start watchdog deb-systemd-invoke restart systemd-journald # remove transitional files left after 2.0~~transitional if echo "$2" | grep '~~transitional' >/dev/null; then echo "Cleaning up transitional APT settings" rm -f /etc/apt/preferences.d/00wirenboard-release-transition-tmp rm -f /etc/apt/sources.list.d/wirenboard-release-transition-tmp.list rm -f /etc/update-motd.d/99wb-upgrade-transition-tmp echo "Generating new APT preferences according to installed release info" wb-release -r fi # nginx user should has rw access to fwupdate uploads dir nginx_uploads_dir="/mnt/data/uploads" nginx_user="www-data" if [[ -d $nginx_uploads_dir ]] && $(id -u $nginx_user > /dev/null 2>&1); then echo "Setting ownership $nginx_user to $nginx_uploads_dir" chown -R $nginx_user:$nginx_user $nginx_uploads_dir fi # grant access fastcgi sripts to mosquitto's unix socket chgrp mosquitto /run/mosquitto chmod g+x /run/mosquitto usermod -a -G mosquitto $nginx_user # restart fcgiwrap to apply group changes deb-systemd-invoke restart fcgiwrap || true nm_fixes() { local nm_connections=("/etc/NetworkManager/system-connections/wb-eth0.nmconnection" "/etc/NetworkManager/system-connections/wb-eth1.nmconnection" "/etc/NetworkManager/system-connections/wb-gsm-sim1.nmconnection" "/etc/NetworkManager/system-connections/wb-gsm-sim2.nmconnection" "/etc/NetworkManager/system-connections/wb-rndis.nmconnection") local connection_hashes=("d99be5a51292b10e558a37d5766c8859" # wb-eth0.nmconnection "687766120810d07efd06d07b9995fdc1" # wb-eth1.nmconnection "1bde0e56b5ab5d9fc79daae90840d2dd" # wb-gsm-sim1.nmconnection "5303529f247a0e991898caa056da8d83" # wb-gsm-sim2.nmconnection "6a36f2ea4321342c0156442c6bbf5d29") # wb-rndis.nmconnection # remove old default connections for cn in ${nm_connections[@]}; do if [ -f $cn ]; then local cn_calculated_hash=$(md5sum "$cn" | cut -f 1 -d ' ') for cn_hash in ${connection_hashes[@]}; do if [ "$cn_calculated_hash" == "$cn_hash" ]; then echo "Removing old default connection $cn" rm -f $cn || true break fi done fi done # Wiren Board config for NetworkManager is now in /usr/lib/NetworkManager/conf.d/ old_wb_conf="/etc/NetworkManager/conf.d/wb.conf" if [ -f $old_wb_conf ]; then local wb_conf_calculated_hash=$(md5sum "$old_wb_conf" | cut -f 1 -d ' ') if [ "$wb_conf_calculated_hash" == "e9f7aac3e4ff8fe00b8465958ec00da7" ]; then echo "Removing old $old_wb_conf" rm -f $old_wb_conf || true fi fi deb-systemd-invoke restart dnsmasq || true deb-systemd-invoke restart NetworkManager || true } # manually unsetting WBGSM_INTERACTIVE var for all ppp-peers to allow launch ppp-connection via pon/poff ppp_peers_fixes() { for fname in $(ls -d /etc/ppp/peers/*); do sed -i 's#"/usr/bin/wb-gsm\s#"WBGSM_INTERACTIVE= /usr/bin/wb-gsm #g' $fname done } nm_fixes ppp_peers_fixes add_mmc_mount_options(){ awk '{ EMMC_REGEX="^(\/dev\/mmcblk0p2|\/dev\/mmcblk0p5|\/dev\/mmcblk0p6)" TIME_OPTION_REGEX="(noatime|atime|relatime)" options=$4 if ($1 ~ EMMC_REGEX){ if (options !~ "(discard)") options="discard,"options; if (options !~ TIME_OPTION_REGEX) options="noatime,"options; } printf "%-20s %-20s %-10s %-70s %-10s %-10s\n", $1, $2, $3, options, $5, $6; }' /etc/fstab > /tmp/fstab_tmp mv /tmp/fstab_tmp /etc/fstab } add_mmc_mount_options mosquitto_fixes() { MOSQUITTO_CONF="/etc/mosquitto/mosquitto.conf" LISTENERS_CONF='/etc/mosquitto/conf.d/10listeners.conf' local restart_required=0 if grep -q "log_dest file /var/log/mosquitto/mosquitto.log" $MOSQUITTO_CONF; then sed -i 's#log_dest file /var/log/mosquitto/mosquitto.log#log_dest syslog#' $MOSQUITTO_CONF restart_required=1 fi if grep -q "pid_file /var/run/mosquitto.pid" $MOSQUITTO_CONF; then sed -i 's#pid_file /var/run/mosquitto.pid#pid_file /run/mosquitto/mosquitto.pid#' $MOSQUITTO_CONF restart_required=1 fi if ! grep -q -F "include_dir /usr/share/wb-configs/mosquitto" $MOSQUITTO_CONF; then sed -i '\#include_dir /etc/mosquitto/conf.d#iinclude_dir /usr/share/wb-configs/mosquitto' $MOSQUITTO_CONF restart_required=1 fi if grep -q "^listener 18883$" $LISTENERS_CONF; then sed -i '/^listener 18883$/clistener 18883 lo' $LISTENERS_CONF restart_required=1 fi if [ $restart_required -eq 1 ]; then if [ "$(deb-systemd-invoke is-enabled mosquitto)" != "masked" ]; then deb-systemd-invoke restart mosquitto else echo "Mosquitto is masked, skipping restart" fi fi /usr/lib/wb-configs/fix_mosquitto.sh } mosquitto_fixes