1
0
Fork 0
mirror of https://github.com/iiab/iiab.git synced 2025-02-12 11:12:06 +00:00

Dynamically extract php_version & python_version

This commit is contained in:
root 2022-12-21 19:29:04 -05:00
parent 2408a08aa9
commit cc659d0837
17 changed files with 113 additions and 77 deletions

View file

@ -65,7 +65,7 @@ if [ ! -f /etc/iiab/local_vars.yml ]; then
echo -e "████████████████████████████████████████████████████████████████████████████████\n" >&2
fi
echo -e "\nEXITING: /opt/iiab/iiab/iiab-install REQUIRES /etc/iiab/local_vars.yml\n" >&2
echo -e "\n\e[1mEXITING: /opt/iiab/iiab/iiab-install REQUIRES /etc/iiab/local_vars.yml\e[0m\n" >&2
echo -e "(1) See http://FAQ.IIAB.IO -> What is local_vars.yml and how do I customize it?" >&2
echo -e "(2) SMALL/MEDIUM/LARGE samples are included in /opt/iiab/iiab/vars" >&2
@ -124,7 +124,7 @@ CURR_ANSIBLE_VER=0
#if [[ $(command -v ansible) ]]; then # Also Works! $(...) nests more easily than backticks
#if [[ `which ansible` ]]; then # "which" misses built-in commands like cd, and is RISKY per https://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script
#if [[ `type -P ansible` ]]; then # "type -P" isn't POSIX compliant; it misses built-in commands like "cd"
if [[ `command -v ansible` ]]; then # "command -v" is POSIX compliant; it catches built-in commands like "cd"
if [[ $(command -v ansible) ]]; then # "command -v" is POSIX compliant; it catches built-in commands like "cd"
CURR_ANSIBLE_VER=$(ansible --version | head -1 | cut -f 2- -d " " | sed 's/.* \([^ ]*\)\].*/\1/')
# Above works with 'ansible [core 2.11.0rc2]' -- these old ways do not:
#CURR_ANSIBLE_VER=$(ansible --version | head -1 | awk '{print $2}')
@ -179,14 +179,15 @@ fi
# /etc/iiab/iiab_state.yml is mandatory and must be created here. Background:
# Allow iiab-install to read IIAB_STATE_FILE to not repeat installs of previous
# roles that already completed within the stage.
if [ ! -f $IIAB_STATE_FILE ]; then
#touch $IIAB_STATE_FILE
if [ ! -f $IIAB_STATE_FILE ]; then # touch $IIAB_STATE_FILE
echo -e "\nCreating... $IIAB_STATE_FILE"
cat > $IIAB_STATE_FILE << EOF
# DO *NOT* MANUALLY EDIT THIS, THANKS!
# IIAB does NOT currently support uninstalling apps/services.
EOF
fi
echo -e "\nTRY TO RERUN './iiab-install' IF IT FAILS DUE TO CONNECTIVITY ISSUES ETC!\n"
echo -e "\e[1mRunning local Ansible playbooks...\n...Stage 0 will now run\n...followed by Stages $(($STAGE + 1))-9\n...and then the Network Role.\e[0m\n"

View file

@ -7,13 +7,14 @@
# Higher-level purpose explained at the bottom of:
# https://github.com/iiab/iiab/blob/master/vars/default_vars.yml
- name: "Ansible just ran /etc/ansible/facts.d/local_facts.fact to set 14 vars -- here we extract 5 of those -- iiab_stage: {{ ansible_local.local_facts.stage }}, rpi_model: {{ ansible_local.local_facts.rpi_model }}, devicetree_model: {{ ansible_local.local_facts.devicetree_model }}, os_ver: {{ ansible_local.local_facts.os_ver }}, python_ver: {{ ansible_local.local_facts.python_ver }}"
- name: "Ansible just ran /etc/ansible/facts.d/local_facts.fact to set 15 vars -- here we extract 6 of those -- iiab_stage: {{ ansible_local.local_facts.stage }}, rpi_model: {{ ansible_local.local_facts.rpi_model }}, devicetree_model: {{ ansible_local.local_facts.devicetree_model }}, os_ver: {{ ansible_local.local_facts.os_ver }}, python_version: {{ ansible_local.local_facts.python_version }}, php_version: {{ ansible_local.local_facts.php_version }}"
set_fact:
iiab_stage: "{{ ansible_local.local_facts.stage }}"
rpi_model: "{{ ansible_local.local_facts.rpi_model }}"
devicetree_model: "{{ ansible_local.local_facts.devicetree_model }}"
os_ver: "{{ ansible_local.local_facts.os_ver }}"
python_ver: "{{ ansible_local.local_facts.python_ver }}"
python_version: "{{ ansible_local.local_facts.python_version }}"
php_version: "{{ ansible_local.local_facts.php_version }}"
# Initialize /etc/iiab/iiab.ini writing the 'location' and 'version' sections
# once and only once, to preserve the install date and git hash.
@ -96,8 +97,10 @@
value: "{{ devicetree_model }}"
- option: os_ver
value: "{{ os_ver }}"
- option: python_ver
value: "{{ python_ver }}"
- option: python_version
value: "{{ python_version }}"
- option: php_version
value: "{{ php_version }}"
- option: first_run
value: "{{ first_run }}"
- option: local_tz # e.g. 'EDT' (summer) or 'EST' (winter) after Ansible interprets symlink /etc/localtime -- or 'UTC' if /etc/localtime doesn't exist

View file

@ -72,7 +72,7 @@
dest: /etc/systemd/system/jupyterhub.service
# 2022-07-07: No longer needed, thx to upstream fixes
# - name: Install {{ jupyterhub_venv }}/bin/getsite.py from template, to fetch site_packages path, e.g. {{ jupyterhub_venv }}/lib/python{{ python_ver }}/site-packages
# - name: Install {{ jupyterhub_venv }}/bin/getsite.py from template, to fetch site_packages path, e.g. {{ jupyterhub_venv }}/lib/python{{ python_version }}/site-packages
# template:
# src: getsite.py.j2
# dest: "{{ jupyterhub_venv }}/bin/getsite.py"

View file

@ -55,7 +55,6 @@
extra_args: --no-cache-dir # To avoid caching issues e.g. soon after new releases hit https://pypi.org/project/opwen-email-client/
when: lokole_commit is undefined and lokole_version is undefined
# 2022-12-21: Dynamic callout to Python moved to scripts/local_facts.fact (Python 3 is now a mandatory IIAB pre-req)
# - name: Compile translations
# shell: |
# python_version=$(python3 -c 'from sys import version_info; print("%s.%s" % (version_info.major, version_info.minor));';)
@ -63,11 +62,12 @@
# with_items:
# - "{{ lokole_venv }}/lib/python${python_version}/site-packages/opwen_email_client/webapp"
- name: Compile translations for Python {{ python_ver }}
# 2022-12-21: python_version determined by scripts/local_facts.fact -- to match templates/lokole-nginx.conf.j2
- name: Compile translations for Python {{ python_version }}
shell: |
{{ lokole_venv }}/bin/pybabel compile -d {{ item }}/translations
with_items:
- "{{ lokole_venv }}/lib/python{{ python_ver }}/site-packages/opwen_email_client/webapp"
- "{{ lokole_venv }}/lib/python{{ python_version }}/site-packages/opwen_email_client/webapp"
- name: Create system {{ lokole_user }} user
ansible.builtin.user:

View file

@ -3,11 +3,11 @@
name: supervisor
state: started
# 2022-12-21: python_version determined by scripts/local_facts.fact -- to match templates/lokole-nginx.conf.j2
- name: Create Lokole admin user with password, for http://box{{ lokole_url }} # http://box/lokole
shell: |
while read envvar; do export "$envvar"; done < {{ lokole_run_dir }}/settings.env
python_version=$(python3 -c 'from sys import version_info; print("%s.%s" % (version_info.major, version_info.minor));';)
cd {{ lokole_venv }}/lib/python${python_version}/site-packages/
cd {{ lokole_venv }}/lib/python{{ python_version }}/site-packages/
export FLASK_APP="opwen_email_client.webapp:app"
{{ lokole_venv }}/bin/flask manage createadmin --name='{{ lokole_admin_user }}' --password='{{ lokole_admin_password }}'

View file

@ -1,9 +1,9 @@
location = {{ lokole_url }}/favicon.ico {
alias {{ lokole_venv }}/lib/python{{ python_ver }}/site-packages/opwen_email_client/webapp/static/favicon.ico;
alias {{ lokole_venv }}/lib/python{{ python_version }}/site-packages/opwen_email_client/webapp/static/favicon.ico;
}
location ~ ^{{ lokole_url }}/static/(.*)$ {
alias {{ lokole_venv }}/lib/python{{ python_ver }}/site-packages/opwen_email_client/webapp/static/$1;
alias {{ lokole_venv }}/lib/python{{ python_version }}/site-packages/opwen_email_client/webapp/static/$1;
}
location {{ lokole_url }}/ {

55
runrole
View file

@ -15,7 +15,7 @@ PLAYBOOK=run-one-role.yml
if [ ! -f $PLAYBOOK ]; then
echo "Exiting: IIAB Playbook not found."
echo "Please run this in /opt/iiab/iiab (top level of the git repo)."
echo "Please run this in /opt/iiab/iiab (top level of git repo)."
exit 1
fi
@ -28,28 +28,48 @@ if [ $# -eq 0 ] || [ "$2" == "--reinstall" ] || [ "$3" == "--reinstall" ]; then
exit 0
fi
# 2020-08-05: yes /etc/iiab/iiab_state.yml is necessary, but we DON'T
# want to encourage sloppy operators to delete/touch this file.
#
# (The iiab_state.yml file should always be created by ./iiab-install,
# for IIAB's Ansible roles that then auto-populate this file.)
#
# FYI ./iiab-network and ./iiab-configure likewise warn operators (IN RED!)
# if they try to run without the existence of /etc/iiab/iiab_state.yml :
#
# ERROR! vars file /etc/iiab/iiab_state.yml was not found
#
# Needed for Stages 1-3 if not installed yet
#if [ ! -f $IIAB_STATE_FILE ]; then
# touch $IIAB_STATE_FILE
#fi
if [ "$1" == "--reinstall" ]; then
ARGS="$ARGS\"reinstall\":True," # Needs boolean not string so use JSON list
REINSTALL=true
shift
fi
# 4 snippets to guide -> bootstrap -> accelerate role debugging on bare OS's:
mkdir -p /etc/iiab # -p avoids errors, effectively like '|| true'
if [ ! -f /etc/iiab/local_vars.yml ]; then
echo -e "\n\e[1mEXITING: /opt/iiab/iiab/iiab-install REQUIRES /etc/iiab/local_vars.yml\e[0m\n" >&2
echo -e "(1) See http://FAQ.IIAB.IO -> What is local_vars.yml and how do I customize it?" >&2
echo -e "(2) SMALL/MEDIUM/LARGE samples are included in /opt/iiab/iiab/vars" >&2
echo -e "(3) NO TIME FOR DETAILS? RUN INTERNET-IN-A-BOX'S FRIENDLY 1-LINE INSTALLER:\n" >&2
echo -e ' https://download.iiab.io\n' >&2
exit 1
fi
# In comparison, ./iiab-network and ./iiab-configure warn operators (IN RED)
# if run without the existence of /etc/iiab/iiab_state.yml
if [ ! -f $IIAB_STATE_FILE ]; then # touch $IIAB_STATE_FILE
echo -e "\n\e[1mCreating... $IIAB_STATE_FILE\e[0m"
cat > $IIAB_STATE_FILE << EOF
# DO *NOT* MANUALLY EDIT THIS, THANKS!
# IIAB does NOT currently support uninstalling apps/services.
EOF
fi
if ! [[ $(command -v ansible) ]]; then
echo -e "\n\e[1mPlease install Ansible, by running:\n\nsudo /opt/iiab/iiab/scripts/ansible\e[0m\n"
exit 1
fi
mkdir -p /etc/ansible/facts.d
cp scripts/local_facts.fact /etc/ansible/facts.d/local_facts.fact
ROLE_VAR=$1 # Ansible role name & var name sometimes differ :/
if [ $1 == "calibre-web" ]; then
ROLE_VAR=calibreweb
@ -105,6 +125,7 @@ if ! $INSTALL; then
ARGS="$ARGS\"${ROLE_VAR}_install\":True,"
fi
if [ $# -eq 2 ]; then
export ANSIBLE_LOG_PATH="$2"
else

View file

@ -13,14 +13,15 @@ STAGE=0
OS="none"
VERSION_ID="none" # Temp var, for: OS_VER="$OS-$VERSION_ID"
OS_VER="none"
PYTHON_VER="none"
IIAB_REMOTE_URL="none"
IIAB_BRANCH="none"
IIAB_COMMIT="none"
IIAB_REMOTE_URL="none"
IIAB_RECENT_TAG="none"
IIAB_COMMIT="none"
RPI_MODEL="none"
DEVICETREE_MODEL="none"
ANSIBLE_VERSION="none"
PYTHON_VERSION="none"
PHP_VERSION="none"
DHCPCD="none" # The last 3 conditioned on string output not RC. SEE BELOW.
NETWORK_MANAGER="none"
SYSTEMD_NETWORKD="none"
@ -90,6 +91,7 @@ case $OS_VER in
;;
esac
# These next 4 help indicate what version of IIAB
tmp=$(git rev-parse --abbrev-ref HEAD) &&
IIAB_BRANCH=$tmp
@ -102,11 +104,12 @@ tmp=$(git config branch.$IIAB_BRANCH.remote) && {
fi
}
tmp=$(git describe --tags --abbrev=0) &&
IIAB_RECENT_TAG=$tmp
tmp=$(git rev-parse --verify HEAD) &&
IIAB_COMMIT=$tmp
tmp=$(git describe --tags --abbrev=0) &&
IIAB_RECENT_TAG=$tmp
grep -iq raspberry /proc/device-tree/model &&
RPI_MODEL=$(grep -ai raspberry /proc/device-tree/model | tr -d '\0')
@ -119,6 +122,7 @@ grep -iq raspberry /proc/device-tree/model &&
tmp=$(tr -d '\0' < /proc/device-tree/model) &&
DEVICETREE_MODEL=$tmp
tmp=$(ansible --version) &&
ANSIBLE_VERSION=$(echo "$tmp" | head -1 | cut -f 2- -d " " | sed 's/.* \([^ ]*\)\].*/\1/')
# Above works with 'ansible [core 2.11.0rc2]' -- these old ways do not:
@ -126,12 +130,18 @@ tmp=$(ansible --version) &&
#ANSIBLE_VERSION=$(echo "$tmp" | head -1 | sed -e 's/.* //')
if tmp=$(python3 -c 'from sys import version_info; print("%s.%s" % (version_info.major, version_info.minor));'); then
PYTHON_VER=$tmp
PYTHON_VERSION=$tmp
else
echo -e "\e[1m\nPython 3 is REQUIRED for Internet-in-a-Box. You might want to run:\n\nsudo apt install python3\n\e[0m"
exit 1
fi
tmp=$(apt list php) &&
PHP_VERSION=$(echo $tmp | grep -Po '[0-9]+\.[0-9]+' | head -1)
# Extracts the first (topmost, leftmost) MAJOR.MINOR, even if not yet installed
# Safer than: echo $tmp | grep php | head -1 | sed 's/.*://; s/[^0-9.].*//')
# https://stackoverflow.com/questions/16675179/how-to-use-sed-to-extract-substring/16675391#16675391
# THE LAST 3 BELOW ARE DIFFERENT as "systemctl is-enabled" unhelpfully returns
# the same error code (i.e. 1) REGARDLESS whether the service is (A) disabled
@ -157,17 +167,18 @@ tmp=$(systemctl is-enabled systemd-networkd)
# https://en.wikipedia.org/wiki/Here_document
cat <<EOF
{"stage" : "$STAGE",
"dhcpcd" : "$DHCPCD",
"network_manager" : "$NETWORK_MANAGER",
"systemd_networkd" : "$SYSTEMD_NETWORKD",
"iiab_remote_url" : "$IIAB_REMOTE_URL",
"os" : "$OS",
"os_ver" : "$OS_VER",
"iiab_branch" : "$IIAB_BRANCH",
"iiab_commit" : "$IIAB_COMMIT",
"iiab_remote_url" : "$IIAB_REMOTE_URL",
"iiab_recent_tag" : "$IIAB_RECENT_TAG",
"iiab_commit" : "$IIAB_COMMIT",
"rpi_model" : "$RPI_MODEL",
"devicetree_model" : "$DEVICETREE_MODEL",
"ansible_version" : "$ANSIBLE_VERSION",
"os" : "$OS",
"os_ver" : "$OS_VER",
"python_ver" : "$PYTHON_VER"}
"python_version" : "$PYTHON_VERSION",
"php_version" : "$PHP_VERSION",
"dhcpcd" : "$DHCPCD",
"network_manager" : "$NETWORK_MANAGER",
"systemd_networkd" : "$SYSTEMD_NETWORKD"}
EOF

View file

@ -7,8 +7,8 @@ is_debian_11: True
proxy: squid
proxy_user: proxy
apache_service: apache2
apache_conf_dir: apache2/sites-available
apache_user: www-data
apache_conf_dir: apache2/sites-available
apache_log_dir: /var/log/apache2
apache_log: /var/log/apache2/access.log
smb_service: smbd
@ -17,7 +17,7 @@ systemctl_program: /bin/systemctl
mysql_service: mariadb
sshd_package: openssh-server
sshd_service: ssh
php_version: "7.4"
# postgresql_version: 13
systemd_location: /lib/systemd/system
# python_ver: "3.9"
# php_version: "7.4"
# postgresql_version: 13
# python_version: "3.9"

View file

@ -7,8 +7,8 @@ is_debian_12: True
proxy: squid
proxy_user: proxy
apache_service: apache2
apache_conf_dir: apache2/sites-available
apache_user: www-data
apache_conf_dir: apache2/sites-available
apache_log_dir: /var/log/apache2
apache_log: /var/log/apache2/access.log
smb_service: smbd
@ -17,7 +17,7 @@ systemctl_program: /bin/systemctl
mysql_service: mariadb
sshd_package: openssh-server
sshd_service: ssh
php_version: "8.1"
# postgresql_version: 15
systemd_location: /lib/systemd/system
# python_ver: "3.10"
# php_version: "8.1"
# postgresql_version: 15
# python_version: "3.10"

View file

@ -19,7 +19,7 @@ systemctl_program: /bin/systemctl
mysql_service: mariadb
sshd_package: openssh-server
sshd_service: ssh
php_version: "7.4"
# postgresql_version: 12
systemd_location: /lib/systemd/system
# python_ver: "3.8"
# php_version: "7.4"
# postgresql_version: 12
# python_version: "3.8"

View file

@ -19,7 +19,7 @@ systemctl_program: /bin/systemctl
mysql_service: mariadb
sshd_package: openssh-server
sshd_service: ssh
php_version: "8.1"
# postgresql_version: 14
systemd_location: /lib/systemd/system
# python_ver: "3.10"
# php_version: "8.1"
# postgresql_version: 14
# python_version: "3.10"

View file

@ -9,8 +9,8 @@ is_raspbian_11: True
proxy: squid
proxy_user: proxy
apache_service: apache2
apache_conf_dir: apache2/sites-available
apache_user: www-data
apache_conf_dir: apache2/sites-available
apache_log_dir: /var/log/apache2
apache_log: /var/log/apache2/access.log
smb_service: smbd
@ -19,7 +19,7 @@ systemctl_program: /bin/systemctl
mysql_service: mariadb
sshd_package: ssh
sshd_service: ssh
php_version: "7.4"
# postgresql_version: 13
systemd_location: /lib/systemd/system
# python_ver: "3.9"
# php_version: "7.4"
# postgresql_version: 13
# python_version: "3.9"

View file

@ -17,7 +17,7 @@ systemctl_program: /bin/systemctl
mysql_service: mariadb
sshd_package: openssh-server
sshd_service: ssh
php_version: "7.4"
postgresql_version: 12
systemd_location: /lib/systemd/system
python_ver: "3.8"
# php_version: "7.4"
# postgresql_version: 12
# python_ver: "3.8"

View file

@ -17,7 +17,7 @@ systemctl_program: /bin/systemctl
mysql_service: mariadb
sshd_package: openssh-server
sshd_service: ssh
php_version: "8.1"
# postgresql_version: 14
systemd_location: /lib/systemd/system
# python_ver: "3.10"
# php_version: "8.1"
# postgresql_version: 14
# python_version: "3.10"

View file

@ -17,7 +17,7 @@ systemctl_program: /bin/systemctl
mysql_service: mariadb
sshd_package: openssh-server
sshd_service: ssh
php_version: "8.1"
# postgresql_version: 14
systemd_location: /lib/systemd/system
# python_ver: "3.10"
# php_version: "8.1"
# postgresql_version: 14
# python_version: "3.10"

View file

@ -17,7 +17,7 @@ systemctl_program: /bin/systemctl
mysql_service: mariadb
sshd_package: openssh-server
sshd_service: ssh
php_version: "8.1"
# postgresql_version: 14
systemd_location: /lib/systemd/system
# python_ver: "3.10"
# php_version: "8.1"
# postgresql_version: 14
# python_version: "3.10"