From 8f0bb179905068fda72eebc1972fbdb63bf6d0a5 Mon Sep 17 00:00:00 2001 From: A Holt Date: Wed, 6 Jul 2022 02:39:29 -0400 Subject: [PATCH 1/2] Uncover IIAB_REMOTE_URL in 1 of 2 places (for both repos) --- roles/0-init/tasks/create_iiab_ini.yml | 4 ++-- roles/0-init/tasks/main.yml | 4 ++-- scripts/iiab-summary | 18 ++++++++++++++++-- scripts/local_facts.fact | 13 +++++++++---- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/roles/0-init/tasks/create_iiab_ini.yml b/roles/0-init/tasks/create_iiab_ini.yml index f27cb2e38..239ce570d 100644 --- a/roles/0-init/tasks/create_iiab_ini.yml +++ b/roles/0-init/tasks/create_iiab_ini.yml @@ -29,8 +29,8 @@ value: "{{ ansible_architecture }}" - option: iiab_base_ver value: "{{ iiab_base_ver }}" - - option: iiab_remote - value: "{{ ansible_local.local_facts.iiab_remote }}" + - option: iiab_remote_url + value: "{{ ansible_local.local_facts.iiab_remote_url }}" - option: iiab_branch value: "{{ ansible_local.local_facts.iiab_branch }}" - option: iiab_commit diff --git a/roles/0-init/tasks/main.yml b/roles/0-init/tasks/main.yml index b7d128124..cf5482144 100644 --- a/roles/0-init/tasks/main.yml +++ b/roles/0-init/tasks/main.yml @@ -68,8 +68,8 @@ value: "{{ iiab_base_ver }}" - option: iiab_revision value: "{{ iiab_revision }}" - - option: iiab_remote - value: "{{ ansible_local.local_facts.iiab_remote }}" + - option: iiab_remote_url + value: "{{ ansible_local.local_facts.iiab_remote_url }}" - option: runtime_branch value: "{{ ansible_local.local_facts.iiab_branch }}" - option: runtime_commit diff --git a/scripts/iiab-summary b/scripts/iiab-summary index 40f423584..f1b7179a5 100755 --- a/scripts/iiab-summary +++ b/scripts/iiab-summary @@ -12,7 +12,14 @@ COMMITS1=$(git log "$TAG1..HEAD" --oneline | wc -l) PR_COUNT1=$(git log "$TAG1..HEAD" --oneline --grep='Merge pull request' | wc -l) COMMIT_MSG1=$(git log --format=%B -1 | head -1) BRANCH1=$(git branch --show-current) -REMOTE_URL1=$(git config remote.$(git config branch.$BRANCH1.remote).url) +REMOTE_URL1="none" +tmp=$(git config branch.$BRANCH1.remote) && { + if [[ $tmp =~ ^"https://" ]]; then + REMOTE_URL1=$tmp + else + REMOTE_URL1=$(git config remote.$tmp.url) + fi +} git config --global --add safe.directory /opt/iiab/iiab-admin-console # Nec below, if non-root cd /opt/iiab/iiab-admin-console @@ -22,7 +29,14 @@ COMMITS2=$(git log "$TAG2..HEAD" --oneline | wc -l) PR_COUNT2=$(git log "$TAG2..HEAD" --oneline --grep='Merge pull request' | wc -l) COMMIT_MSG2=$(git log --format=%B -1 | head -1) BRANCH2=$(git branch --show-current) -REMOTE_URL2=$(git config remote.$(git config branch.$BRANCH2.remote).url) +REMOTE_URL2="none" +tmp=$(git config branch.$BRANCH2.remote) && { + if [[ $tmp =~ ^"https://" ]]; then + REMOTE_URL2=$tmp + else + REMOTE_URL2=$(git config remote.$tmp.url) + fi +} echo "$(grep install_date /etc/iiab/iiab.ini) Current TZ: $(date +%Z)" echo diff --git a/scripts/local_facts.fact b/scripts/local_facts.fact index a0471c95a..3c50c360e 100755 --- a/scripts/local_facts.fact +++ b/scripts/local_facts.fact @@ -12,7 +12,7 @@ STAGE=0 OS="none" VERSION_ID="none" # This var's combined with the above, before being output -IIAB_REMOTE="none" +IIAB_REMOTE_URL="none" IIAB_BRANCH="none" IIAB_COMMIT="none" IIAB_RECENT_TAG="none" @@ -91,8 +91,13 @@ esac tmp=$(git rev-parse --abbrev-ref HEAD) && IIAB_BRANCH=$tmp -tmp=$(git config remote.$(git config branch.$IIAB_BRANCH.remote).url) && - IIAB_REMOTE=$tmp +tmp=$(git config branch.$IIAB_BRANCH.remote) && { + if [[ $tmp =~ ^"https://" ]]; then + IIAB_REMOTE_URL=$tmp + else + IIAB_REMOTE_URL=$(git config remote.$tmp.url) + fi +} tmp=$(git rev-parse --verify HEAD) && IIAB_COMMIT=$tmp @@ -145,7 +150,7 @@ cat < Date: Wed, 6 Jul 2022 05:53:19 -0400 Subject: [PATCH 2/2] Toughen up iiab-apps-to-be-installed, iiab-summary, iiab-diagnostics --- scripts/iiab-apps-to-be-installed | 16 +++++++++--- scripts/iiab-diagnostics | 41 ++++++++---------------------- scripts/iiab-diagnostics.README.md | 2 +- scripts/iiab-summary | 3 ++- 4 files changed, 27 insertions(+), 35 deletions(-) diff --git a/scripts/iiab-apps-to-be-installed b/scripts/iiab-apps-to-be-installed index e44baee93..84b6e2f11 100755 --- a/scripts/iiab-apps-to-be-installed +++ b/scripts/iiab-apps-to-be-installed @@ -8,6 +8,11 @@ iiab_var_value() { [[ $v2 != "" ]] && echo $v2 || echo $v1 # [ "$v2" ] ALSO WORKS } +# https://askubuntu.com/questions/1250974/user-root-cant-write-to-file-in-tmp-owned-by-someone-else-in-20-04-but-can-in +# https://unix.stackexchange.com/questions/503111/group-permissions-for-root-not-working-in-tmp +[[ $(id -un) == "root" ]] && + rm -f /tmp/iiab-apps-list /tmp/iiab-apps-to-be-installed + # 2022-06-18: 40 apps (list not quite complete) #grep -l _installed: /opt/iiab/iiab/roles/*/tasks/install.yml | cut -d/ -f6 > /tmp/iiab-apps-list @@ -17,6 +22,13 @@ iiab_var_value() { # 2022-06-18: 50 apps (list long but ok!) -- adds these 10: dansguardian, dhcpd, iiab_admin, minetest, named, pylibs, squid, wondershaper, www_base, www_options grep -hro '[A-Za-z_][A-Za-z_]*_installed: True' --exclude-dir=0-DEPRECATED-ROLES /opt/iiab/iiab/roles | sed 's/_installed: True$//' | sort | uniq > /tmp/iiab-apps-list +# Non-root CANNOT rm files from /tmp, but CAN write to them (unlike root!!) +# This ALSO creates the file (useful when "Apps2B" == 0, for iiab-summary etc) +truncate -s 0 /tmp/iiab-apps-to-be-installed + +# So other (non-root) users CAN later write to these, even if they CAN'T chmod! +chmod 777 /tmp/iiab-apps-list /tmp/iiab-apps-to-be-installed 2>/dev/null + while read app; do if [[ $app == "calibre-web" ]]; then app=calibreweb @@ -27,8 +39,6 @@ while read app; do # echo ${app}_install: $(iiab_var_value ${app}_install) if [[ $(iiab_var_value ${app}_install) =~ ^[Tt]rue$ ]] && ! grep -q "${app}_installed: True" /etc/iiab/iiab_state.yml; then - echo $app + echo $app | tee -a /tmp/iiab-apps-to-be-installed fi done < /tmp/iiab-apps-list - -rm /tmp/iiab-apps-list # So a non-root user can later run this cleanly! diff --git a/scripts/iiab-diagnostics b/scripts/iiab-diagnostics index 957111ad1..f447fb3d1 100755 --- a/scripts/iiab-diagnostics +++ b/scripts/iiab-diagnostics @@ -127,45 +127,26 @@ function cat_tail() { # $1 = path/filename; $2 = # of lines, for tail # START BUILDING UP THE FILE THAT'LL CONTAIN THE DIAGNOSTICS! echo -e "\nCompiling diagnostics..." -echo -e "\n 0. Filename Header + Git Hashes + Raspberry Pi Model + OS" +echo -e "\n 0. HW + SW Quick Summary" echo "This is: $outfile" >> $outfile echo >> $outfile -echo -e "\n\n\n\n0. GIT INFO + RASPBERRY PI MODEL + OS" >> $outfile -echo >> $outfile -echo "iiab commit: $HASH1" >> $outfile -echo " remote: $REMOTE_URL1" >> $outfile -echo " branch: $BRANCH1" >> $outfile -printf "%4s merged PR's since recent tag: $TAG_COMMITS1\n" $PR_COUNT1 >> $outfile -echo >> $outfile -echo "iiab-admin-console commit: $HASH2" >> $outfile -echo " remote: $REMOTE_URL2" >> $outfile -echo " branch: $BRANCH2" >> $outfile -printf "%4s merged PR's since recent tag: $TAG_COMMITS2\n" $PR_COUNT2 >> $outfile -echo >> $outfile -cat_file /etc/iiab/pr-list-pulled -cat_file /proc/device-tree/model # Should be identical to /sys/firmware/devicetree/base/model -cat_file /etc/rpi-issue -echo "-IIAB-EXPLANATION-OF-THE-ABOVE-------------------------------------------------" >> $outfile +echo -e "\n\n\n\n0. HW + SW Quick Summary" >> $outfile echo >> $outfile +/opt/iiab/iiab/scripts/iiab-summary >> $outfile if [ -f /etc/rpi-issue ]; then echo "stage2 = Raspberry Pi OS Lite" >> $outfile echo "stage4 = Raspberry Pi OS with desktop" >> $outfile echo "stage5 = Raspberry Pi OS with desktop + recommended software" >> $outfile - echo >> $outfile echo "SEE https://github.com/RPi-Distro/pi-gen#stage-anatomy" >> $outfile -else - echo "(This is NOT Raspberry Pi OS!)" >> $outfile + echo >> $outfile +fi +if [ -s /tmp/iiab-apps-to-be-installed ]; then + echo "iiab-apps-to-be-installed :" >> $outfile + cat /tmp/iiab-apps-to-be-installed >> $outfile + echo >> $outfile fi -echo >> $outfile -cat_file /etc/issue.net -cat_file /etc/debian_version -cat_cmd 'dpkg --print-architecture' 'RaspiOS-on-PC shows: i386' -cat_cmd 'dpkg --print-foreign-architectures' 'RaspiOS-on-PC shows: amd64' -cat_cmd 'systemctl is-active display-manager.service' 'Graphical Desktop?' -cat_cmd 'grep "^openvpn_" /etc/iiab/local_vars.yml' -cat_cmd 'iiab-apps-to-be-installed' 'IIAB Apps to be installed' -echo -e '\n\n 1. Files Specially Requested: (from "iiab-diagnostics PATH/FILE1 PATH/FILE2")\n' +echo -e '\n 1. Files Specially Requested: (from "iiab-diagnostics PATH/FILE1 PATH/FILE2")\n' echo -e '\n\n\n\n1. FILES SPECIALLY REQUESTED (FROM "iiab-diagnostics PATH/FILE1 PATH/FILE2")\n' >> $outfile for f in "$@"; do cat_file $f @@ -277,7 +258,7 @@ echo echo -e "\e[1m" #if [ "$ans" == "" ] || [ "$ans" == "y" ] || [ "$ans" == "Y" ]; then -if ! [[ $ans =~ ^[nN]$ ]]; then +if ! [[ $ans =~ ^[nNqQ]$ ]]; then echo -ne "PUBLISHING TO URL... " #pastebinit -b dpaste.com < $outfile pastebinit -b sprunge.us < $outfile # Run 'pastebinit -l' to list other possible pastebin site URLs diff --git a/scripts/iiab-diagnostics.README.md b/scripts/iiab-diagnostics.README.md index 1dacfe807..63d0edc59 100644 --- a/scripts/iiab-diagnostics.README.md +++ b/scripts/iiab-diagnostics.README.md @@ -68,4 +68,4 @@ But first off, the file is compiled by harvesting 1 + 6 kinds of things: ## Source Code -Please look over the bottom of [iiab-diagnostics](iiab-diagnostics) (lines 127-261 especially) to learn more about which common IIAB files and commands make this rapid troubleshooting possible. +Please look over the bottom of [iiab-diagnostics](iiab-diagnostics) (lines 127-242 especially) to learn more about which common IIAB files and commands make this rapid troubleshooting possible. diff --git a/scripts/iiab-summary b/scripts/iiab-summary index f1b7179a5..ffd9ac45c 100755 --- a/scripts/iiab-summary +++ b/scripts/iiab-summary @@ -76,7 +76,8 @@ fi # landscape-sysinfo --sysinfo-plugins=Disk,Temperature,Load # Like: uptime -p #fi echo -echo "$(df -h /) ZIMs: $(ls /library/zims/content/ | wc -l) OER2Go: $(ls /library/www/html/modules/ | wc -l) Apps2B: $(/opt/iiab/iiab/scripts/iiab-apps-to-be-installed | wc -l)" +/opt/iiab/iiab/scripts/iiab-apps-to-be-installed > /dev/null +echo "$(df -h /) ZIMs: $(ls /library/zims/content/ | wc -l) OER2Go: $(ls /library/www/html/modules/ | wc -l) Apps2B: $(cat /tmp/iiab-apps-to-be-installed | wc -l)" echo echo $(ip -o link show | awk -F': ' '{print $2}') # Better order than: ls -rt /sys/class/net grep "^openvpn_enabled:" /etc/iiab/local_vars.yml