changes for json pretty print output

This commit is contained in:
creme 2020-01-18 15:27:32 +01:00
parent 3842c7ce05
commit 69074c62c9
Signed by: creme
GPG Key ID: C147C3B7FBDF08D0
2 changed files with 367 additions and 394 deletions

View File

@ -12,7 +12,7 @@ DOMAIN='envs.net'
# define packages by category for sysinfo.php Page
services=(0x0 bbj cryptpad getwtxt gitea gophernicus jetforce mariadb-server matrix nginx openssh-server
privatebin riot-web searx termbin tt-rss thelounge znc)
privatebin riot-web searx termbin tt-rss thelounge znc)
readarray -t sorted_services < <(printf '%s\n' "${services[@]}" | sort)
@ -29,43 +29,43 @@ readarray -t sorted_inet_clients < <(printf '%s\n' "${inet_clients[@]}" | sort)
coding_pkg=(cargo clang clisp clojure crystal default-jdk default-jre elixir erlang flex
g++ gcc gcl gdc gforth ghc go golang guile-2.2 inform lua5.1 lua5.2 lua5.3 mono-complete
nasm nim nodejs octave perl php picolisp ponyc python python2.7 python3 racket ruby rustc scala tcl yasm vlang)
g++ gcc gcl gdc gforth ghc go golang guile-2.2 inform lua5.1 lua5.2 lua5.3 mono-complete
nasm nim nodejs octave perl php picolisp ponyc python python2.7 python3 racket ruby rustc scala tcl yasm vlang)
readarray -t sorted_coding_pkg < <(printf '%s\n' "${coding_pkg[@]}" | sort)
coding_tools=(ack bison build-essential cl-launch cvs devscripts ecl gawk git gron initscripts jq latex-mk latexmk
make mawk mercurial rake ripgrep sbcl shellcheck subversion texlive-full virtualenv yarn)
make mawk mercurial rake ripgrep sbcl shellcheck subversion texlive-full virtualenv yarn)
readarray -t sorted_coding_tools < <(printf '%s\n' "${coding_tools[@]}" | sort)
misc=(aria2 bc busybox burrow byobu clinte gfu goaccess hugo jekyll mariadb-client mandoc mathomatic mathtex mkdocs
pandoc pelican screen sqlite3 tmux todotxt-cli twtxt txtnish zola)
pandoc pelican screen sqlite3 tmux todotxt-cli twtxt txtnish zola)
readarray -t sorted_misc < <(printf '%s\n' "${misc[@]}" | sort)
###
custom_pkg_desc() {
local pkg="$1"
case "$pkg" in
# packages
av98) pkg_desc='Command line gemini client. High speed, low drag';;
bombadillo) pkg_desc='Bombadillo is a non-web browser for the terminal';;
burrow) pkg_desc='a helper for building and managing a gopher hole';;
clinte) pkg_desc='a community notices system';;
crystal) pkg_desc='Compiler for the Crystal language';;
gfu) pkg_desc='A utility for formatting gophermaps';;
go) pkg_desc='tool for managing Go source code';;
goaccess) pkg_desc='fast web log analyzer and interactive viewer';;
meli) pkg_desc='terminal mail user agent';;
micro) pkg_desc='a new modern terminal-based text editor';;
pb) pkg_desc='a helper utility for using 0x0 pastebin services';;
twtxt) pkg_desc='Decentralised, minimalist microblogging service for hackers';;
txtnish) pkg_desc='A twtxt client with minimal dependencies';;
vf1) pkg_desc='Command line gopher client. High speed, low drag.';;
vlang) pkg_desc='Simple, fast, safe, compiled programming language';;
zola) pkg_desc='single-binary static site generator written in rust';;
esac
local pkg="$1"
case "$pkg" in
# packages
av98) pkg_desc='Command line gemini client. High speed, low drag';;
bombadillo) pkg_desc='Bombadillo is a non-web browser for the terminal';;
burrow) pkg_desc='a helper for building and managing a gopher hole';;
clinte) pkg_desc='a community notices system';;
crystal) pkg_desc='Compiler for the Crystal language';;
gfu) pkg_desc='A utility for formatting gophermaps';;
go) pkg_desc='tool for managing Go source code';;
goaccess) pkg_desc='fast web log analyzer and interactive viewer';;
meli) pkg_desc='terminal mail user agent';;
micro) pkg_desc='a new modern terminal-based text editor';;
pb) pkg_desc='a helper utility for using 0x0 pastebin services';;
twtxt) pkg_desc='Decentralised, minimalist microblogging service for hackers';;
txtnish) pkg_desc='A twtxt client with minimal dependencies';;
vf1) pkg_desc='Command line gopher client. High speed, low drag.';;
vlang) pkg_desc='Simple, fast, safe, compiled programming language';;
zola) pkg_desc='single-binary static site generator written in rust';;
esac
}
@ -76,145 +76,145 @@ JSON_FILE="$WWW_PATH/sysinfo.json"
TMP_JSON='/tmp/sysinfo.json_tmp'
print_pkg_version() {
local pkg_version
for pkg in $(dpkg-query -f '${binary:Package}\n' -W); do
pkg_version="$(dpkg-query -f '${Version}\n' -W "$pkg")"
local pkg_version
for pkg in $(dpkg-query -f '${binary:Package}\n' -W); do
pkg_version="$(dpkg-query -f '${Version}\n' -W "$pkg")"
printf '\t\t\t"%s": "%s",\n' "$pkg" "$pkg_version"
done
printf ' "%s": "%s",\n' "$pkg" "$pkg_version"
done
}
cat<<EOM > "$TMP_JSON"
{
"timestamp": "$(date +'%s')",
"data": {
"info": {
"name": "envs",
"description": "envs.net is a minimalist, non-commercial shared linux system and will always be free to use.",
"located": "germany",
"maintainer": "Sven Kinne (~creme) - creme@envs.net",
"website": "https://$DOMAIN",
"signup_url": "https://$DOMAIN/signup/",
"gopher": "gopher://envs.net/",
"email": "hostmaster@$DOMAIN",
"admin_email": "sudoers@$DOMAIN",
"user_count": $(find /home -mindepth 1 -maxdepth 1 | wc -l)
},
"SSHFP": {
"RSA": "SHA256:7dB470mfzlyhhtqmjnXciIxp+jWLACiYKC3EE/Z0lFg",
"ECDSA": "SHA256:U0C6SKGXUflve16m2l4KWBdLLARW6O8TiGWZsXAU2i4",
"ED25519": "SHA256:V+mXTsRJ+jfJMxxPlD/28dpWouuns3Wuqwppv6ykVC8"
},
"system": {
"os": "$(lsb_release -sd)",
"uptime": "$(cat /proc/uptime)",
"uname": "$(uname -a)",
"board": "$(hostnamectl status | awk '/Chassis/ {print $2}')",
"cpuinfo": "$(awk '/system type|model name/{gsub(/^.*:[ ]*/,"");print $0;exit}' /proc/cpuinfo)",
"cpucount": "$(grep -c ^processor /proc/cpuinfo)"
},
"services": {
"0x0": {
"desc": "the null pointer - file hosting and url shortener",
"version": "-",
"url": "https://envs.sh/"
},
"bbj": {
"desc": "bulletin butter & jelly: an http bulletin board server for small communities",
"version": "-",
"url": "https://bbj.envs.net/"
},
"cryptpad": {
"desc": "collaborative real time editing",
"version": "$(curl -s https://pad."$DOMAIN"/api/config | awk '/ver=/ {print $2}' | sed -e 's/"ver=//' -e '$ s/"$//')",
"url": "https://pad.envs.net/"
},
"getwtxt": {
"desc": "a twtxt registry service",
"version": "$(curl -s https://twtxt."$DOMAIN"/api/plain/version | sed 's/getwtxt v//')",
"url": "https://twtxt.envs.net/"
},
"gitea": {
"desc": "a painless self-hosted git service written in go",
"version": "$(lxc-attach -n gitea -- bash -c "gitea --version | awk '{print \$3}'")",
"url": "https://git.envs.net/"
},
"gophernicus": {
"desc": "a modern full-featured (and hopefully) secure gopher daemon",
"version": "$(/usr/sbin/gophernicus -v | sed 's/Gophernicus\///' | awk '{print $1}')",
"url": "gopher://envs.net/"
},
"jetforce": {
"desc": "an tcp server for the gemini protocol",
"version": "$(/usr/local/bin/jetforce -V | awk '{printf $2}')",
"url": "gemini://envs.net/"
},
"matrix": {
"desc": "an open network for secure, decentralized communication",
"version": "$(curl -s https://matrix."$DOMAIN"/_synapse/admin/v1/server_version | jq -Mr .server_version)",
"url": "https://matrix.envs.net/"
},
"privatebin": {
"desc": "a pastebin service",
"version": "$(lxc-attach -n pb -- bash -c "awk '/Current version:/ {print \$3}' /var/www/PrivateBin/README.md | sed '$ s/*$//'")",
"url": "https://pb.envs.net/"
},
"riot-web": {
"desc": "a universal secure chat app for matrix (web-client)",
"version": "$(lxc-attach -n matrix -- bash -c "dpkg-query -f '\${Version}\n' -W riot-web")",
"url": "https://matrix.envs.net/"
},
"searx": {
"desc": "privacy-respecting metasearch engine",
"version": "$(curl -s https://searx."$DOMAIN"/config | jq -Mr .version)",
"url": "https://searx.envs.net/"
},
"termbin": {
"desc": "a command line pastebin",
"version": "-",
"url": "https://tb.envs.net/"
},
"thelounge": {
"desc": "a self-hosted web irc client",
"version": "$(sudo -u thelounge /srv/thelounge/.yarn/bin/thelounge -v | sed 's/v//')",
"url": "https://webirc.envs.net/"
},
"tt-rss": {
"desc": "tiny tiny rss - web-based news feed (rss/atom) aggregator",
"version": "$(lxc-attach -n rss -- bash -c "dpkg -s tt-rss | awk '/Version:/ {print \$2}' | head -n1")",
"url": "https://rss.envs.net/"
},
"znc": {
"desc": "advanced modular irc bouncer",
"version": "$(dpkg -s znc | awk '/Version:/ {print $2}' | head -n1)",
"url": "https://znc.envs.net/"
}
},
"packages": {
"av98": "$(/usr/local/bin/av98 --version | awk '{print $2}')",
"bombadillo": "$(/usr/local/bin/bombadillo -v | awk '/Bombadillo/ {print $2}')",
"burrow": "$(/usr/local/bin/burrow -v | sed 's/v//')",
"clinte": "$(/usr/local/bin/clinte -V | awk '/clinte/ {print $2}')",
"gfu": "$(/usr/local/bin/gfu -v | sed '/version/s/.*version \([^ ][^ ]*\)[ ]*.*/\1/')",
"go": "$(sed 's/go//' /usr/local/go/VERSION)",
"goaccess": "$(/usr/bin/goaccess -V | awk '/GoAccess/ {print $3}')",
"meli": "$(/usr/local/bin/meli --version | awk '/meli/ {printf $2}')",
"micro": "$(/usr/local/bin/micro -version | awk '/Version/ {print $2}')",
"pb": "$(/usr/local/bin/pb -v)",
"twtxt": "$(/usr/local/bin/twtxt --version | awk '/version/ {printf $3}')",
"txtnish": "$(/usr/local/bin/txtnish -V)",
"vf1": "$(/usr/local/bin/vf1 --version | awk '/VF-1/ {print $2}')",
"vlang": "$(/usr/local/bin/v --version | awk '/V/ {print $2}')",
"zola": "$(/usr/local/bin/zola -V | awk '/zola/ {print $2}')",
"timestamp": "$(date +'%s')",
"data": {
"info": {
"name": "envs",
"description": "envs.net is a minimalist, non-commercial shared linux system and will always be free to use.",
"located": "germany",
"maintainer": "Sven Kinne (~creme) - creme@envs.net",
"website": "https://$DOMAIN",
"signup_url": "https://$DOMAIN/signup/",
"gopher": "gopher://envs.net/",
"email": "hostmaster@$DOMAIN",
"admin_email": "sudoers@$DOMAIN",
"user_count": $(find /home -mindepth 1 -maxdepth 1 | wc -l)
},
"SSHFP": {
"RSA": "SHA256:7dB470mfzlyhhtqmjnXciIxp+jWLACiYKC3EE/Z0lFg",
"ECDSA": "SHA256:U0C6SKGXUflve16m2l4KWBdLLARW6O8TiGWZsXAU2i4",
"ED25519": "SHA256:V+mXTsRJ+jfJMxxPlD/28dpWouuns3Wuqwppv6ykVC8"
},
"system": {
"os": "$(lsb_release -sd)",
"uptime": "$(cat /proc/uptime)",
"uname": "$(uname -a)",
"board": "$(hostnamectl status | awk '/Chassis/ {print $2}')",
"cpuinfo": "$(awk '/system type|model name/{gsub(/^.*:[ ]*/,"");print $0;exit}' /proc/cpuinfo)",
"cpucount": "$(grep -c ^processor /proc/cpuinfo)"
},
"services": {
"0x0": {
"desc": "the null pointer - file hosting and url shortener",
"version": "-",
"url": "https://envs.sh/"
},
"bbj": {
"desc": "bulletin butter & jelly: an http bulletin board server for small communities",
"version": "-",
"url": "https://bbj.envs.net/"
},
"cryptpad": {
"desc": "collaborative real time editing",
"version": "$(curl -s https://pad."$DOMAIN"/api/config | awk '/ver=/ {print $2}' | sed -e 's/"ver=//' -e '$ s/"$//')",
"url": "https://pad.envs.net/"
},
"getwtxt": {
"desc": "a twtxt registry service",
"version": "$(curl -s https://twtxt."$DOMAIN"/api/plain/version | sed 's/getwtxt v//')",
"url": "https://twtxt.envs.net/"
},
"gitea": {
"desc": "a painless self-hosted git service written in go",
"version": "$(lxc-attach -n gitea -- bash -c "gitea --version | awk '{print \$3}'")",
"url": "https://git.envs.net/"
},
"gophernicus": {
"desc": "a modern full-featured (and hopefully) secure gopher daemon",
"version": "$(/usr/sbin/gophernicus -v | sed 's/Gophernicus\///' | awk '{print $1}')",
"url": "gopher://envs.net/"
},
"jetforce": {
"desc": "an tcp server for the gemini protocol",
"version": "$(/usr/local/bin/jetforce -V | awk '{printf $2}')",
"url": "gemini://envs.net/"
},
"matrix": {
"desc": "an open network for secure, decentralized communication",
"version": "$(curl -s https://matrix."$DOMAIN"/_synapse/admin/v1/server_version | jq -Mr .server_version)",
"url": "https://matrix.envs.net/"
},
"privatebin": {
"desc": "a pastebin service",
"version": "$(lxc-attach -n pb -- bash -c "awk '/Current version:/ {print \$3}' /var/www/PrivateBin/README.md | sed '$ s/*$//'")",
"url": "https://pb.envs.net/"
},
"riot-web": {
"desc": "a universal secure chat app for matrix (web-client)",
"version": "$(lxc-attach -n matrix -- bash -c "dpkg-query -f '\${Version}\n' -W riot-web")",
"url": "https://matrix.envs.net/"
},
"searx": {
"desc": "privacy-respecting metasearch engine",
"version": "$(curl -s https://searx."$DOMAIN"/config | jq -Mr .version)",
"url": "https://searx.envs.net/"
},
"termbin": {
"desc": "a command line pastebin",
"version": "-",
"url": "https://tb.envs.net/"
},
"thelounge": {
"desc": "a self-hosted web irc client",
"version": "$(sudo -u thelounge /srv/thelounge/.yarn/bin/thelounge -v | sed 's/v//')",
"url": "https://webirc.envs.net/"
},
"tt-rss": {
"desc": "tiny tiny rss - web-based news feed (rss/atom) aggregator",
"version": "$(lxc-attach -n rss -- bash -c "dpkg -s tt-rss | awk '/Version:/ {print \$2}' | head -n1")",
"url": "https://rss.envs.net/"
},
"znc": {
"desc": "advanced modular irc bouncer",
"version": "$(dpkg -s znc | awk '/Version:/ {print $2}' | head -n1)",
"url": "https://znc.envs.net/"
}
},
"packages": {
"av98": "$(/usr/local/bin/av98 --version | awk '{print $2}')",
"bombadillo": "$(/usr/local/bin/bombadillo -v | awk '/Bombadillo/ {print $2}')",
"burrow": "$(/usr/local/bin/burrow -v | sed 's/v//')",
"clinte": "$(/usr/local/bin/clinte -V | awk '/clinte/ {print $2}')",
"gfu": "$(/usr/local/bin/gfu -v | sed '/version/s/.*version \([^ ][^ ]*\)[ ]*.*/\1/')",
"go": "$(sed 's/go//' /usr/local/go/VERSION)",
"goaccess": "$(/usr/bin/goaccess -V | awk '/GoAccess/ {print $3}')",
"meli": "$(/usr/local/bin/meli --version | awk '/meli/ {printf $2}')",
"micro": "$(/usr/local/bin/micro -version | awk '/Version/ {print $2}')",
"pb": "$(/usr/local/bin/pb -v)",
"twtxt": "$(/usr/local/bin/twtxt --version | awk '/version/ {printf $3}')",
"txtnish": "$(/usr/local/bin/txtnish -V)",
"vf1": "$(/usr/local/bin/vf1 --version | awk '/VF-1/ {print $2}')",
"vlang": "$(/usr/local/bin/v --version | awk '/V/ {print $2}')",
"zola": "$(/usr/local/bin/zola -V | awk '/zola/ {print $2}')",
$(print_pkg_version)
EOM
# remove trailing ',' on last line
sed -i '$ s/,$//' "$TMP_JSON"
# remove trailing ',' on last line
sed -i '$ s/,$//' "$TMP_JSON"
cat<<EOM >> "$TMP_JSON"
}
}
}
}
}
EOM
@ -226,72 +226,72 @@ chown root:www-data "$JSON_FILE"
# SYSINFO.PHP
#
print_pkg_info() {
local pkg="$1"
local pkg="$1"
local pkg_version
pkg_version="$(jq -Mr '.data.packages."'"$pkg"'"|select (.!=null)' "$JSON_FILE")"
[ -z "$pkg_version" ] && pkg_version='n.a.'
local pkg_version
pkg_version="$(jq -Mr '.data.packages."'"$pkg"'"|select (.!=null)' "$JSON_FILE")"
[ -z "$pkg_version" ] && pkg_version='n.a.'
local pkg_desc
custom_pkg_desc "$pkg"
[ -z "$pkg_desc" ] && pkg_desc="$(apt-cache show "$pkg" | awk '/Description-en/ {print substr($0, index($0,$2))}' | head -1)"
[ -z "$pkg_desc" ] && pkg_desc="$(apt-cache search ^"$pkg"$ | awk '{print substr($0, index($0,$3))}')"
[ -z "$pkg_desc" ] && pkg_desc='n.a.'
# remove description-en string
pkg_desc="${pkg_desc//Description-en: /}"
# replace double qoutes with single qoute
pkg_desc="${pkg_desc//\"/\'}"
# string to lowercase
pkg_desc="${pkg_desc,,}"
local pkg_desc
custom_pkg_desc "$pkg"
[ -z "$pkg_desc" ] && pkg_desc="$(apt-cache show "$pkg" | awk '/Description-en/ {print substr($0, index($0,$2))}' | head -1)"
[ -z "$pkg_desc" ] && pkg_desc="$(apt-cache search ^"$pkg"$ | awk '{print substr($0, index($0,$3))}')"
[ -z "$pkg_desc" ] && pkg_desc='n.a.'
# remove description-en string
pkg_desc="${pkg_desc//Description-en: /}"
# replace double qoutes with single qoute
pkg_desc="${pkg_desc//\"/\'}"
# string to lowercase
pkg_desc="${pkg_desc,,}"
printf '\t<tr> <td>%s</td> <td>%s</td> <td>%s</td> </tr>\n' "$pkg" "$pkg_version" "$pkg_desc"
printf '\t<tr> <td>%s</td> <td>%s</td> <td>%s</td> </tr>\n' "$pkg" "$pkg_version" "$pkg_desc"
}
print_pkg_info_services() {
local pkg="$1"
local pkg="$1"
local pkg_desc
pkg_desc="$(jq -Mr '.data.services."'"$pkg"'".desc|select (.!=null)' "$JSON_FILE")"
local pkg_desc
pkg_desc="$(jq -Mr '.data.services."'"$pkg"'".desc|select (.!=null)' "$JSON_FILE")"
local pkg_version
pkg_version="$(jq -Mr '.data.services."'"$pkg"'".version|select (.!=null)' "$JSON_FILE")"
local pkg_version
pkg_version="$(jq -Mr '.data.services."'"$pkg"'".version|select (.!=null)' "$JSON_FILE")"
local s_url
s_url="$(jq -Mr '.data.services."'"$pkg"'".url|select (.!=null)' "$JSON_FILE")"
local s_url
s_url="$(jq -Mr '.data.services."'"$pkg"'".url|select (.!=null)' "$JSON_FILE")"
printf '\t<tr> <td><a href="%s" target="_blank">%s</a></td> <td>%s</td> <td>%s</td> </tr>\n' "$s_url" "$pkg" "$pkg_version" "$pkg_desc"
printf '\t<tr> <td><a href="%s" target="_blank">%s</a></td> <td>%s</td> <td>%s</td> </tr>\n' "$s_url" "$pkg" "$pkg_version" "$pkg_desc"
}
print_category() {
local category="$1"
shift
local arr=("$@")
local category="$1"
shift
local arr=("$@")
if [ "$category" = 'services' ]; then
printf '<details open=""><summary class="menu" id="%s"><strong>&#35; %s</strong></summary>\n' "$category" "${category//_/ }"
else
printf '<details><summary class="menu" id="%s"><strong>&#35; %s</strong></summary>\n' "$category" "${category//_/ }"
fi
if [ "$category" = 'services' ]; then
printf '<details open=""><summary class="menu" id="%s"><strong>&#35; %s</strong></summary>\n' "$category" "${category//_/ }"
else
printf '<details><summary class="menu" id="%s"><strong>&#35; %s</strong></summary>\n' "$category" "${category//_/ }"
fi
printf '<table id="table_pkg">\n'
printf '<tr> <th width="140px">Package</th> <th width="280px">Version</th> <th>Description</th></tr>\n'
printf '<table id="table_pkg">\n'
printf '<tr> <th width="140px">Package</th> <th width="280px">Version</th> <th>Description</th></tr>\n'
if [ "$category" = 'services' ]; then
for pkg in "${arr[@]}"; do
# check service is in json
s_in_j="$(jq -Mr '.data.services."'"$pkg"'"|select (.!=null)' "$JSON_FILE")"
if [ "$category" = 'services' ]; then
for pkg in "${arr[@]}"; do
# check service is in json
s_in_j="$(jq -Mr '.data.services."'"$pkg"'"|select (.!=null)' "$JSON_FILE")"
if [ -n "$s_in_j" ]; then
print_pkg_info_services "$pkg"
else
print_pkg_info "$pkg"
fi
done
else
for pkg in "${arr[@]}"; do print_pkg_info "$pkg"; done
fi
if [ -n "$s_in_j" ]; then
print_pkg_info_services "$pkg"
else
print_pkg_info "$pkg"
fi
done
else
for pkg in "${arr[@]}"; do print_pkg_info "$pkg"; done
fi
printf '</table></details>\n'
printf '</table></details>\n'
}
@ -306,13 +306,13 @@ include 'header.php';
?>
<body id="body" class="dark-mode">
<div>
<div>
<div class="button_back">
<pre class="clean"><strong><a href="/">&lt; back</a></strong></pre>
</div>
<div class="button_back">
<pre class="clean"><strong><a href="/">&lt; back</a></strong></pre>
</div>
<div id="main" style="padding-bottom: 4em;">
<div id="main" style="padding-bottom: 4em;">
<div class="block">
<pre>
<h1><em>sysinfo</em></h1>
@ -332,19 +332,19 @@ probably! send an email with your suggestion to <a href="mailto:sudoers@$DOMAIN"
</pre>
<br />
$(print_category 'services' "${sorted_services[@]}")
<br />
<p></p>
$(print_category 'shells' "${sorted_shells[@]}")
<br />
<p></p>
$(print_category 'editors' "${sorted_editors[@]}")
<br />
<p></p>
$(print_category 'online_browser_and_clients' "${sorted_inet_clients[@]}")
<br />
<p></p>
$(print_category 'coding_packages' "${sorted_coding_pkg[@]}")
<br />
<p></p>
$(print_category 'coding_tools' "${sorted_coding_tools[@]}")
<br />
<p></p>
$(print_category 'misc' "${sorted_misc[@]}")
</div>
</div>
<?php include 'footer.php'; ?>

View File

@ -27,227 +27,200 @@ TMP_JSON='/tmp/users_info.json_tmp'
cat << EOM > "$TMP_JSON"
{
"timestamp": "$(date +'%s')",
"data": {
"info": {
"name": "envs",
"description": "envs.net is a minimalist, non-commercial shared linux system and will always be free to use.",
"located": "germany",
"maintainer": "Sven Kinne (~creme) - creme@envs.net",
"website": "https://$DOMAIN",
"signup_url": "https://$DOMAIN/signup/",
"gopher": "gopher://envs.net/",
"email": "hostmaster@$DOMAIN",
"admin_email": "sudoers@$DOMAIN",
"user_count": $(find /home -mindepth 1 -maxdepth 1 | wc -l)
},
"users": {
"timestamp": "$(date +'%s')",
"data": {
"info": {
"name": "envs",
"description": "envs.net is a minimalist, non-commercial shared linux system and will always be free to use.",
"located": "germany",
"maintainer": "Sven Kinne (~creme) - creme@envs.net",
"website": "https://$DOMAIN",
"signup_url": "https://$DOMAIN/signup/",
"gopher": "gopher://envs.net/",
"email": "hostmaster@$DOMAIN",
"admin_email": "sudoers@$DOMAIN",
"user_count": $(find /home -mindepth 1 -maxdepth 1 | wc -l)
},
"users": {
EOM
# user header
for USERNAME in /home/*
do
USER_HOME="$USERNAME"
USERNAME="${USERNAME/\/home\//}"
INFO_FILE="$USER_HOME/.envs"
for USERNAME in /home/*
do
USER_HOME="$USERNAME"
USERNAME="${USERNAME/\/home\//}"
INFO_FILE="$USER_HOME/.envs"
cat << EOM >> "$TMP_JSON"
"$USERNAME": {
"home": "$USER_HOME",
"email": "$USERNAME@$DOMAIN",
cat << EOM >> "$TMP_JSON"
"$USERNAME": {
"home": "$USER_HOME",
"email": "$USERNAME@$DOMAIN",
EOM
# desc / irc / matrix
if [ -f "$INFO_FILE" ]; then
# desc
desc="$(sed -n '/^desc=/{s#^.*=##;p}' "$INFO_FILE")"
if [ -z "$desc" ] || [ "$desc" == 'a short describtion or message' ]; then
cat << EOM >> "$TMP_JSON"
"desc": "",
if [ -f "$INFO_FILE" ]; then
desc="$(sed -n '/^desc=/{s#^.*=##;p}' "$INFO_FILE")"
if [ -z "$desc" ] || [ "$desc" == 'a short describtion or message' ]; then
cat << EOM >> "$TMP_JSON"
"desc": "",
EOM
else
cat << EOM >> "$TMP_JSON"
"desc": "$desc",
else
cat << EOM >> "$TMP_JSON"
"desc": "$desc",
EOM
fi
# irc
irc="$(sed -n '/^irc=/{s#^.*=##;p}' "$INFO_FILE")"
if [ -z "$irc" ]; then
cat << EOM >> "$TMP_JSON"
"irc": "",
fi
else
cat << EOM >> "$TMP_JSON"
"desc": "",
EOM
else
cat << EOM >> "$TMP_JSON"
"irc": "$irc",
EOM
fi
# matrix
matrix="$(sed -n '/^matrix=/{s#^.*=##;p}' "$INFO_FILE")"
if [ -z "$matrix" ]; then
cat << EOM >> "$TMP_JSON"
"matrix": "",
EOM
else
cat << EOM >> "$TMP_JSON"
"matrix": "$matrix",
EOM
fi
# end desc / irc / matrix
else
cat << EOM >> "$TMP_JSON"
"desc": "",
"irc": "",
"matrix": "",
EOM
fi
fi
# website
if [ -f "$USER_HOME"/public_html/index.php ] || [ "$(test -f "$USER_HOME"/public_html/index.*htm*; echo $?)" -eq 0 ]; then
cat << EOM >> "$TMP_JSON"
"website": "https://$DOMAIN/~$USERNAME/",
if [ -f "$USER_HOME"/public_html/index.php ] || [ "$(test -f "$USER_HOME"/public_html/index.*htm*; echo $?)" -eq 0 ]; then
cat << EOM >> "$TMP_JSON"
"website": "https://$DOMAIN/~$USERNAME/",
EOM
else
cat << EOM >> "$TMP_JSON"
"website": "",
else
cat << EOM >> "$TMP_JSON"
"website": "",
EOM
fi
fi
# gopher
if [ -f "$USER_HOME"/public_gopher/gophermap ]; then
cat << EOM >> "$TMP_JSON"
"gopher": "gopher://$DOMAIN/1/~$USERNAME/",
"gopherproxy": "https://gopher.$DOMAIN/$DOMAIN/1/~$USERNAME/",
if [ -f "$USER_HOME"/public_gopher/gophermap ]; then
cat << EOM >> "$TMP_JSON"
"gopher": "gopher://$DOMAIN/1/~$USERNAME/",
"gopherproxy": "https://gopher.$DOMAIN/$DOMAIN/1/~$USERNAME/",
EOM
else
cat << EOM >> "$TMP_JSON"
"gopher": "",
"gopherproxy": "",
else
cat << EOM >> "$TMP_JSON"
"gopher": "",
"gopherproxy": "",
EOM
fi
fi
# gemini
if [ -f "$USER_HOME"/public_gemini/index.gmi ]; then
cat << EOM >> "$TMP_JSON"
"gemini": "gemini://$DOMAIN/~$USERNAME/",
if [ -f "$USER_HOME"/public_gemini/index.gmi ]; then
cat << EOM >> "$TMP_JSON"
"gemini": "gemini://$DOMAIN/~$USERNAME/",
EOM
fi
fi
# blog
if [ "$(find "$USER_HOME"/public_html/blog/ -maxdepth 1 2>/dev/null | wc -l)" -ge 3 ]; then
cat << EOM >> "$TMP_JSON"
"blog": "https://$DOMAIN/~$USERNAME/blog/",
if [ "$(find "$USER_HOME"/public_html/blog/ -maxdepth 1 2>/dev/null | wc -l)" -ge 3 ]; then
cat << EOM >> "$TMP_JSON"
"blog": "https://$DOMAIN/~$USERNAME/blog/",
EOM
else
cat << EOM >> "$TMP_JSON"
"blog": "",
else
cat << EOM >> "$TMP_JSON"
"blog": "",
EOM
fi
fi
# twtwt
if [ -f "$USER_HOME"/public_html/twtxt.txt ]; then
cat << EOM >> "$TMP_JSON"
"twtxt": "https://$DOMAIN/~$USERNAME/twtxt.txt",
if [ -f "$USER_HOME"/public_html/twtxt.txt ]; then
cat << EOM >> "$TMP_JSON"
"twtxt": "https://$DOMAIN/~$USERNAME/twtxt.txt",
EOM
else
cat << EOM >> "$TMP_JSON"
"twtxt": "",
else
cat << EOM >> "$TMP_JSON"
"twtxt": "",
EOM
fi
fi
# user custom infos from .envs file (max. 10 entrys)
if [ -f "$INFO_FILE" ]; then
count_entry='0' # use to limit entrys
count_field_entry='0' # use to separat array line by line
if [ -f "$INFO_FILE" ]; then
count_entry='0' # use to limit entrys
count_field_entry='0' # use to separat array line by line
unset field_exists; declare -a field_exists=() # contains field names to limit entrys
unset field_is_array; declare -a field_is_array=() # contains array fields to printf correct json entrys
unset line_to_set; declare -A line_to_set # contains user info lines
unset field_exists; declare -a field_exists=() # contains field names to limit entrys
unset field_is_array; declare -a field_is_array=() # contains array fields to printf correct json entrys
unset line_to_set; declare -A line_to_set # contains user info lines
# check 'INFO_FILE' and add entrys to 'line_to_set' array
while read -r LINE ; do
if [[ -n "$LINE" ]] && ! [[ "$LINE" = '#'* ]] && ! [[ "$LINE" = 'desc='* ]] && \
! [[ "$LINE" = 'irc='* ]] && ! [[ "$LINE" = 'matrix='* ]]; then
user_field="${LINE//=*/}"
user_value="${LINE//*=/}"
# check 'INFO_FILE' and add entrys to 'line_to_set' array
while read -r LINE ; do
if [[ -n "$LINE" ]] && ! [[ "$LINE" = '#'* ]] && ! [[ "$LINE" = 'desc='* ]]; then
user_field="${LINE//=*/}"
user_value="${LINE//*=/}"
if ! [[ ":${field_exists[*]}:" =~ $user_field ]]; then
# entry will be a single line
count_entry="$(( "$count_entry" + 1 ))"; [ "$count_entry" -le '10' ] || continue
field_exists+=( "$user_field" )
line_to_set["$user_field","$count_field_entry"]+="$user_value"
else
# entry will be a array
if ! [[ ":${field_is_array[*]}:" =~ $user_field ]]; then
field_is_array+=( "$user_field" )
fi
count_field_entry="$(( "$count_field_entry" +1 ))"
line_to_set["$user_field","$count_field_entry"]+="$user_value"
fi
fi
done <<< "$(tac "$INFO_FILE")" # read file from buttom
if ! [[ ":${field_exists[*]}:" =~ $user_field ]]; then
# entry will be a single line
count_entry="$(( "$count_entry" + 1 ))"; [ "$count_entry" -le '10' ] || continue
field_exists+=( "$user_field" )
line_to_set["$user_field","$count_field_entry"]+="$user_value"
else
# entry will be a array
if ! [[ ":${field_is_array[*]}:" =~ $user_field ]]; then
field_is_array+=( "$user_field" )
fi
count_field_entry="$(( "$count_field_entry" +1 ))"
line_to_set["$user_field","$count_field_entry"]+="$user_value"
fi
fi
done <<< "$(tac "$INFO_FILE")" # read file from buttom
# add users custom entrys from line_to_set (single lines before arrays)
#
# single line entrys
for field in "${!line_to_set[@]}"; do
field_name="${field//,*/}"
# add users custom entrys from line_to_set (single lines before arrays)
#
# single line entrys
for field in "${!line_to_set[@]}"; do
field_name="${field//,*/}"
if ! [[ ":${field_is_array[*]}:" =~ $field_name ]]; then
cat << EOM >> "$TMP_JSON"
"$field_name": "${line_to_set[$field]}",
if ! [[ ":${field_is_array[*]}:" =~ $field_name ]]; then
cat << EOM >> "$TMP_JSON"
"$field_name": "${line_to_set[$field]}",
EOM
fi
done
#
# array line entrys
field_in_progress=''
fi
done
#
# array line entrys
field_in_progress=''
for field in "${!line_to_set[@]}"; do
field_name="${field//,*/}"
field_count="${field//*,/}"
for field in "${!line_to_set[@]}"; do
field_name="${field//,*/}"
field_count="${field//*,/}"
if [[ ":${field_is_array[*]}:" =~ $field_name ]]; then
# begin of user def. array
if ! [ "$field_in_progress" = "$field_name" ]; then
field_in_progress="$field_name"
if [[ ":${field_is_array[*]}:" =~ $field_name ]]; then
# begin of user def. array
if ! [ "$field_in_progress" = "$field_name" ]; then
field_in_progress="$field_name"
cat << EOM >> "$TMP_JSON"
"$field_name": [
"${line_to_set[$field]}",
cat << EOM >> "$TMP_JSON"
"$field_name": [
"${line_to_set[$field]}",
EOM
else
# continue user def. array
cat << EOM >> "$TMP_JSON"
"${line_to_set[$field]}",
else
# continue user def. array
cat << EOM >> "$TMP_JSON"
"${line_to_set[$field]}",
EOM
if [ "$field_count" -eq '0' ]; then
# end of user def. array
# remove trailing ',' on last user entry
unset field_in_progress
sed -i '$ s/,$//' "$TMP_JSON"
cat << EOM >> "$TMP_JSON"
],
if [ "$field_count" -eq '0' ]; then
# end of user def. array
# remove trailing ',' on last user entry
unset field_in_progress
sed -i '$ s/,$//' "$TMP_JSON"
cat << EOM >> "$TMP_JSON"
],
EOM
fi
fi
fi
done
fi
fi
fi
fi
done
fi
# ssh
cat << EOM >> "$TMP_JSON"
"ssh-pubkey": [
cat << EOM >> "$TMP_JSON"
"ssh-pubkey": [
EOM
while read -r LINE ; do
[[ "$LINE" == 'ssh'* ]] && printf '\t\r\t\r\t\r\t\r\t"%s",\n' "$LINE" >> "$TMP_JSON"
done < "$USER_HOME"/.ssh/authorized_keys
# remove trailing ',' for the last pubkey
sed -i '$ s/,$//' "$TMP_JSON"
while read -r LINE ; do
[[ "$LINE" == 'ssh'* ]] && printf ' "%s",\n' "$LINE" >> "$TMP_JSON"
done < "$USER_HOME"/.ssh/authorized_keys
# remove trailing ',' for the last pubkey
sed -i '$ s/,$//' "$TMP_JSON"
# close user ssh pubkey array ']' and user part. '},'
cat << EOM >> "$TMP_JSON"
]
},
# close user ssh pubkey array ']' and user part. '},'
cat << EOM >> "$TMP_JSON"
]
},
EOM
# EOF
done
# remove trailing ',' on last user entry
sed -i '$ s/,$//' "$TMP_JSON"
done
# remove trailing ',' on last user entry
sed -i '$ s/,$//' "$TMP_JSON"
cat << EOM >> "$TMP_JSON"
}
}
cat << EOM >> "$TMP_JSON"
}
}
}
EOM