mirror of
https://github.com/iiab/iiab.git
synced 2025-03-09 15:40:17 +00:00
scripts/local_facts.fact fixed & cleaned
This commit is contained in:
parent
d8f277c59e
commit
dd40abd738
1 changed files with 62 additions and 39 deletions
|
@ -1,27 +1,47 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# 2020-10-19: Displays all errors on purpose, and uses '|| true' to continue.
|
# 2020-10-19: Most of the 12 variables require a command[*] to be run to
|
||||||
|
# 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"
|
||||||
|
PHPLIB_DIR="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"
|
||||||
|
|
||||||
|
|
||||||
# STAGE is for ./iiab-install which runs Ansible with iiab-stages.yml
|
# STAGE is for ./iiab-install which runs Ansible with iiab-stages.yml
|
||||||
# - fresh installs start at STAGE 0
|
# - fresh installs start at STAGE 0
|
||||||
# - interrupted installs record the last completed STAGE (1-9)
|
# - interrupted installs record the last completed STAGE (1-9)
|
||||||
#
|
#
|
||||||
# We initialize to '0' (zero) to cover both situations: (1) where iiab.env does
|
# We initialize it to '0' (zero) to cover both situations: (1) iiab.env doesn't
|
||||||
# not exist and (2) where iiab.env exists but fails to set STAGE=<something>
|
# exist and (2) iiab.env exists but fails to set STAGE=<something> (source
|
||||||
# (source command below tries to use this file, to the STAGE variable)
|
# command below tries to use the file...to set the STAGE variable).
|
||||||
STAGE=0
|
source /etc/iiab/iiab.env || true # Var auto-populated so no if required!
|
||||||
source /etc/iiab/iiab.env || true
|
|
||||||
|
|
||||||
OS="none"
|
if tmp=$(grep ^ID= /etc/*elease); then
|
||||||
OS=$(grep ^ID= /etc/*elease | cut -d= -f2) || true
|
OS=$(echo $tmp | cut -d= -f2)
|
||||||
OS=${OS//\"/} # Remove all '"'
|
OS=${OS//\"/} # Remove all '"'
|
||||||
|
fi
|
||||||
if [ -f /etc/rpi-issue ]; then
|
if [ -f /etc/rpi-issue ]; then
|
||||||
OS="raspbian"
|
OS="raspbian"
|
||||||
fi
|
fi
|
||||||
VERSION_ID="none"
|
|
||||||
VERSION_ID=$(grep ^VERSION_ID= /etc/*elease | cut -d= -f2) || true
|
if tmp=$(grep ^VERSION_ID= /etc/*elease); then
|
||||||
VERSION_ID=${VERSION_ID//\"/} # Remove all '"'
|
VERSION_ID=$(echo $tmp | cut -d= -f2)
|
||||||
VERSION_ID=${VERSION_ID%%.*} # Remove all '.' and stuff to the right of 'em
|
VERSION_ID=${VERSION_ID//\"/} # Remove all '"'
|
||||||
|
VERSION_ID=${VERSION_ID%%.*} # Remove all '.' & stuff to the right of em
|
||||||
|
fi
|
||||||
OS_VER=$OS-$VERSION_ID
|
OS_VER=$OS-$VERSION_ID
|
||||||
|
|
||||||
# Previously supported Linux distributions / versions:
|
# Previously supported Linux distributions / versions:
|
||||||
|
@ -47,14 +67,13 @@ case $OS_VER in
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Get git branch and commit, indicating IIAB version
|
# These next 2 help indicate what version of IIAB
|
||||||
BRANCH="none"
|
tmp=$(git rev-parse --abbrev-ref HEAD) &&
|
||||||
BRANCH=$(git rev-parse --abbrev-ref HEAD) || true
|
IIAB_BRANCH=$tmp
|
||||||
|
|
||||||
COMMIT="none"
|
tmp=$(git rev-parse --verify HEAD) &&
|
||||||
COMMIT=$(git rev-parse --verify HEAD) || true
|
IIAB_COMMIT=$tmp
|
||||||
|
|
||||||
PHPLIB_DIR="none"
|
|
||||||
if [ -d /usr/lib64/php ]; then
|
if [ -d /usr/lib64/php ]; then
|
||||||
PHPLIB_DIR=/usr/lib64/php
|
PHPLIB_DIR=/usr/lib64/php
|
||||||
elif [ -d /usr/lib/php5 ]; then
|
elif [ -d /usr/lib/php5 ]; then
|
||||||
|
@ -63,36 +82,40 @@ elif [ -d /usr/lib/php ]; then
|
||||||
PHPLIB_DIR=/usr/lib/php
|
PHPLIB_DIR=/usr/lib/php
|
||||||
fi
|
fi
|
||||||
|
|
||||||
XO_VERSION="none"
|
tmp=$(cat /proc/device-tree/mfg-data/MN) &&
|
||||||
XO_VERSION=$(cat /proc/device-tree/mfg-data/MN) || true
|
XO_MODEL=$tmp
|
||||||
|
|
||||||
RPI_VERSION="none"
|
tmp=$(cat /proc/device-tree/model) &&
|
||||||
RPI_VERSION=$(cat /proc/device-tree/model) || true
|
RPI_MODEL=$tmp
|
||||||
|
|
||||||
ANSIBLE_VERSION="none"
|
tmp=$(ansible --version) &&
|
||||||
ANSIBLE_VERSION=$(ansible --version | head -n 1 | cut -f 2 -d " ") || true
|
ANSIBLE_VERSION=$(echo $tmp | head -n 1 | cut -f 2 -d " ")
|
||||||
|
|
||||||
DHCPCD="none"
|
# THESE LAST 3 ARE DIFFEENT as "systemctl is-enabled" unhelpfully returns the
|
||||||
DHCPCD=$(systemctl is-enabled dhcpcd) || true
|
# 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.
|
||||||
|
|
||||||
# This check is Debian family only.
|
tmp=$(systemctl is-enabled dhcpcd)
|
||||||
# is_redhat would use NetworkManager as the service name.
|
[[ $tmp = "" ]] || DHCPCD=$tmp
|
||||||
NM="none"
|
|
||||||
NM=$(systemctl is-enabled network-manager) || true
|
# Debian family only, as is_redhat would use NetworkManager as the service name
|
||||||
|
tmp=$(systemctl is-enabled network-manager)
|
||||||
|
[[ $tmp = "" ]] || NETWORK_MANAGER=$tmp
|
||||||
|
|
||||||
|
tmp=$(systemctl is-enabled systemd-networkd)
|
||||||
|
[[ $tmp = "" ]] || SYSTEMD_NETWORKD=$tmp
|
||||||
|
|
||||||
SYSD_NETD="none"
|
|
||||||
SYSD_NETD=$(systemctl is-enabled systemd-networkd) || true
|
|
||||||
|
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
{"phplib_dir" : "$PHPLIB_DIR",
|
{"phplib_dir" : "$PHPLIB_DIR",
|
||||||
"stage" : "$STAGE",
|
"stage" : "$STAGE",
|
||||||
"dhcpcd" : "$DHCPCD",
|
"dhcpcd" : "$DHCPCD",
|
||||||
"network_manager" : "$NM",
|
"network_manager" : "$NETWORK_MANAGER",
|
||||||
"systemd_networkd" : "$SYSD_NETD",
|
"systemd_networkd" : "$SYSTEMD_NETWORKD",
|
||||||
"iiab_branch" : "$BRANCH",
|
"iiab_branch" : "$IIAB_BRANCH",
|
||||||
"iiab_commit" : "$COMMIT",
|
"iiab_commit" : "$IIAB_COMMIT",
|
||||||
"xo_model" : "$XO_VERSION",
|
"xo_model" : "$XO_MODEL",
|
||||||
"rpi_model" : "$RPI_VERSION",
|
"rpi_model" : "$RPI_MODEL",
|
||||||
"ansible_version" : "$ANSIBLE_VERSION",
|
"ansible_version" : "$ANSIBLE_VERSION",
|
||||||
"os" : "$OS",
|
"os" : "$OS",
|
||||||
"os_ver" : "$OS_VER"}
|
"os_ver" : "$OS_VER"}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue