2017-05-27 18:09:50 +00:00
|
|
|
#!/bin/bash
|
2018-04-28 16:27:32 +00:00
|
|
|
|
2020-10-27 13:27:21 +00:00
|
|
|
# 2020-10-27: Most of the 11 variables require a command[*] to be run to
|
2020-10-19 19:10:27 +00:00
|
|
|
# establish the var's value. WE DISPLAY ALL ERRORS / DIAGNOSTICS AND CONTINUE.
|
|
|
|
#
|
|
|
|
# [*] DOESN'T MATTER WHAT COMMAND: so long as it fails with Return Code != 0
|
|
|
|
# If statements then use that RC to force the var to these default values...
|
|
|
|
|
|
|
|
STAGE=0
|
|
|
|
OS="none"
|
|
|
|
VERSION_ID="none" # This var's combined with the above, before being output
|
|
|
|
IIAB_BRANCH="none"
|
|
|
|
IIAB_COMMIT="none"
|
|
|
|
XO_MODEL="none"
|
|
|
|
RPI_MODEL="none"
|
|
|
|
ANSIBLE_VERSION="none"
|
|
|
|
DHCPCD="none" # The last 3 conditioned on string output not RC. SEE BELOW.
|
|
|
|
NETWORK_MANAGER="none"
|
|
|
|
SYSTEMD_NETWORKD="none"
|
|
|
|
|
2020-10-19 16:45:36 +00:00
|
|
|
|
2020-10-19 19:49:43 +00:00
|
|
|
# STAGE variable is for ./iiab-install which runs Ansible with iiab-stages.yml
|
2020-10-19 16:45:36 +00:00
|
|
|
# - fresh installs start at STAGE 0
|
|
|
|
# - interrupted installs record the last completed STAGE (1-9)
|
|
|
|
#
|
2020-10-19 19:49:43 +00:00
|
|
|
# We initialize it to '0' (zero) to cover the following 2 possibs: (1) iiab.env
|
|
|
|
# doesn't exist, or (2) iiab.env exists but fails to set STAGE=<something>
|
|
|
|
source /etc/iiab/iiab.env || true # STAGE var auto-set, so no "if" required.
|
2018-04-28 16:27:32 +00:00
|
|
|
|
2020-10-27 18:03:55 +00:00
|
|
|
# /etc/lsb-release could also be grep'd. But /etc/upstream-release/lsb-release
|
|
|
|
# on Linux Mint 20 caused grep of /etc/*elease to fail (on directory not file)
|
|
|
|
if tmp=$(grep ^ID= /etc/os-release); then
|
2020-10-27 21:17:40 +00:00
|
|
|
OS=$(echo "$tmp" | cut -d= -f2)
|
2020-10-19 19:10:27 +00:00
|
|
|
OS=${OS//\"/} # Remove all '"'
|
|
|
|
fi
|
2020-05-29 16:59:28 +00:00
|
|
|
if [ -f /etc/rpi-issue ]; then
|
2020-10-27 20:57:56 +00:00
|
|
|
OS="raspbian" # For 64-bit Raspberry Pi OS which contains "ID=debian" as
|
|
|
|
fi # of 2020: https://github.com/raspberrypi/Raspberry-Pi-OS-64bit/issues/6
|
2020-10-19 19:10:27 +00:00
|
|
|
|
2020-10-27 14:39:34 +00:00
|
|
|
if tmp=$(grep ^VERSION_ID= /etc/os-release); then
|
2020-10-27 21:17:40 +00:00
|
|
|
VERSION_ID=$(echo "$tmp" | cut -d= -f2)
|
2020-10-19 19:10:27 +00:00
|
|
|
VERSION_ID=${VERSION_ID//\"/} # Remove all '"'
|
|
|
|
VERSION_ID=${VERSION_ID%%.*} # Remove all '.' & stuff to the right of em
|
|
|
|
fi
|
2017-07-04 20:07:47 +00:00
|
|
|
OS_VER=$OS-$VERSION_ID
|
2017-05-27 18:09:50 +00:00
|
|
|
|
2020-09-02 18:39:19 +00:00
|
|
|
# Previously supported Linux distributions / versions:
|
2020-09-02 02:42:11 +00:00
|
|
|
#"fedora-18" | \
|
|
|
|
#"fedora-22" | \
|
|
|
|
#"debian-8" | \
|
|
|
|
#"debian-9" | \
|
|
|
|
#"ubuntu-16" | \
|
|
|
|
#"ubuntu-17" | \
|
|
|
|
#"ubuntu-18" | \
|
|
|
|
#"ubuntu-19" | \
|
|
|
|
#"centos-7" | \
|
|
|
|
#"raspbian-8" | \
|
|
|
|
#"raspbian-9" | \
|
2020-09-02 18:39:19 +00:00
|
|
|
|
2020-10-21 16:54:52 +00:00
|
|
|
# 2020-10-21: Debian 11 (Bullseye) not yet supported but adding this line to
|
|
|
|
# its /etc/os-release can help testing this unreleased OS: VERSION_ID="11"
|
|
|
|
|
2020-11-15 00:25:49 +00:00
|
|
|
# 2020-11-14: Ubuntu 21.04 (Hirsute Hippo) not yet supported but this
|
|
|
|
# unreleased OS can help testing.
|
|
|
|
|
2020-09-02 18:39:19 +00:00
|
|
|
case $OS_VER in
|
|
|
|
"debian-10" | \
|
2020-10-21 16:54:52 +00:00
|
|
|
"debian-11" | \
|
2020-09-02 18:39:19 +00:00
|
|
|
"ubuntu-20" | \
|
2020-11-15 00:25:49 +00:00
|
|
|
"ubuntu-21" | \
|
2020-09-02 18:39:19 +00:00
|
|
|
"linuxmint-20" | \
|
2019-03-23 11:58:35 +00:00
|
|
|
"raspbian-10")
|
2020-08-20 16:51:17 +00:00
|
|
|
;;
|
|
|
|
*) OS_VER="OS_not_supported"
|
|
|
|
;;
|
2017-07-04 20:07:47 +00:00
|
|
|
esac
|
2020-08-20 16:51:17 +00:00
|
|
|
|
2020-10-19 19:10:27 +00:00
|
|
|
# These next 2 help indicate what version of IIAB
|
|
|
|
tmp=$(git rev-parse --abbrev-ref HEAD) &&
|
|
|
|
IIAB_BRANCH=$tmp
|
2020-10-19 16:45:36 +00:00
|
|
|
|
2020-10-19 19:10:27 +00:00
|
|
|
tmp=$(git rev-parse --verify HEAD) &&
|
|
|
|
IIAB_COMMIT=$tmp
|
2017-05-27 18:09:50 +00:00
|
|
|
|
2020-10-19 19:10:27 +00:00
|
|
|
tmp=$(cat /proc/device-tree/mfg-data/MN) &&
|
|
|
|
XO_MODEL=$tmp
|
2017-05-27 18:09:50 +00:00
|
|
|
|
2020-10-19 19:10:27 +00:00
|
|
|
tmp=$(cat /proc/device-tree/model) &&
|
|
|
|
RPI_MODEL=$tmp
|
2020-03-04 23:02:01 +00:00
|
|
|
|
2020-10-19 19:10:27 +00:00
|
|
|
tmp=$(ansible --version) &&
|
2020-10-27 21:17:40 +00:00
|
|
|
ANSIBLE_VERSION=$(echo "$tmp" | head -n 1 | cut -f 2 -d " ")
|
2020-10-19 19:10:27 +00:00
|
|
|
|
2020-10-19 19:29:46 +00:00
|
|
|
|
2020-10-19 19:10:27 +00:00
|
|
|
# THESE LAST 3 ARE DIFFEENT as "systemctl is-enabled" unhelpfully returns the
|
|
|
|
# same rerror code (i.e. 1) REGARDLESS whether service is (A) disabled or
|
|
|
|
# (B) doesn't exist. SO WE TEST THE STRING OUTPUT INSTEAD OF THE RETURN CODE.
|
|
|
|
|
|
|
|
tmp=$(systemctl is-enabled dhcpcd)
|
2020-10-19 19:29:46 +00:00
|
|
|
[[ $tmp != "" ]] &&
|
|
|
|
DHCPCD=$tmp
|
|
|
|
#[[ $tmp ]] && DHCPCD=$tmp # Short Ain't Sweet (less understandable)
|
2017-11-19 03:08:11 +00:00
|
|
|
|
2020-10-27 11:53:28 +00:00
|
|
|
# is_redhat uses "NetworkManager". Debian 7 & Ubuntu 14.10 required
|
|
|
|
# "network-manager" (prior to 2015/systemd). Ubuntu 20.10 dropped the
|
2020-10-27 14:52:11 +00:00
|
|
|
# legacy symlink from "network-manager.service" to "NetworkManager.service"
|
2020-10-27 11:53:28 +00:00
|
|
|
tmp=$(systemctl is-enabled NetworkManager)
|
2020-10-19 19:29:46 +00:00
|
|
|
[[ $tmp != "" ]] &&
|
|
|
|
NETWORK_MANAGER=$tmp
|
2020-10-19 16:45:36 +00:00
|
|
|
|
2020-10-19 19:10:27 +00:00
|
|
|
tmp=$(systemctl is-enabled systemd-networkd)
|
2020-10-19 19:29:46 +00:00
|
|
|
[[ $tmp != "" ]] &&
|
|
|
|
SYSTEMD_NETWORKD=$tmp
|
2020-10-19 16:45:36 +00:00
|
|
|
|
2017-11-23 02:38:46 +00:00
|
|
|
|
2017-05-27 18:09:50 +00:00
|
|
|
cat <<EOF
|
2020-10-27 13:27:21 +00:00
|
|
|
{"stage" : "$STAGE",
|
2017-11-10 19:01:22 +00:00
|
|
|
"dhcpcd" : "$DHCPCD",
|
2020-10-19 19:10:27 +00:00
|
|
|
"network_manager" : "$NETWORK_MANAGER",
|
|
|
|
"systemd_networkd" : "$SYSTEMD_NETWORKD",
|
|
|
|
"iiab_branch" : "$IIAB_BRANCH",
|
|
|
|
"iiab_commit" : "$IIAB_COMMIT",
|
|
|
|
"xo_model" : "$XO_MODEL",
|
|
|
|
"rpi_model" : "$RPI_MODEL",
|
2017-11-10 19:01:22 +00:00
|
|
|
"ansible_version" : "$ANSIBLE_VERSION",
|
2017-05-27 18:09:50 +00:00
|
|
|
"os" : "$OS",
|
2017-07-04 22:39:45 +00:00
|
|
|
"os_ver" : "$OS_VER"}
|
2017-05-27 18:09:50 +00:00
|
|
|
EOF
|