From b96786bb16299ec462cc41fde31dfd10c9c1842f Mon Sep 17 00:00:00 2001 From: creme Date: Sun, 16 Feb 2020 12:48:57 +0100 Subject: [PATCH] update ops: - rename envs_user_update* to envs_user_info* - users_info.json : only print ssh-pubkey then user has enabled --- bin/envs.net/envs_gemini_genpage.sh | 7 +-- bin/envs.net/envs_sysinfo.sh | 17 +++---- ...envs_user_updated.sh => envs_user_info.sh} | 50 ++++++++++++------- ...d_genpage.pl => envs_user_info_genpage.pl} | 3 +- etc/cron.d/envs_user_info | 8 +++ etc/cron.d/envs_user_updated_genpage | 8 --- 6 files changed, 51 insertions(+), 42 deletions(-) rename bin/envs.net/{envs_user_updated.sh => envs_user_info.sh} (84%) rename bin/envs.net/{envs_user_updated_genpage.pl => envs_user_info_genpage.pl} (89%) create mode 100644 etc/cron.d/envs_user_info delete mode 100644 etc/cron.d/envs_user_updated_genpage diff --git a/bin/envs.net/envs_gemini_genpage.sh b/bin/envs.net/envs_gemini_genpage.sh index a8e4016..c9cdc32 100755 --- a/bin/envs.net/envs_gemini_genpage.sh +++ b/bin/envs.net/envs_gemini_genpage.sh @@ -1,12 +1,11 @@ #!/usr/bin/env bash # # envs.net - generate index.gmi -# - this script is called by /usr/local/bin/envs.net/envs_user_updated.sh +# - this script is called by /usr/local/bin/envs.net/envs_user_info.sh # [ "$(id -u)" -ne 0 ] && printf 'Please run as root!\n' && exit 1 -### userlist() { mapfile -t users < <(jq -Mr '.data.users|keys[]' /var/www/envs.net/users_info.json) @@ -20,9 +19,6 @@ userlist() { done } -# -# INDEX.GMI -# cat << EOM >> /tmp/index.gmi_tmp welcome on envs.net - gemini $(figlet -f smslant envs.net) @@ -36,7 +32,6 @@ we are linux lovers, sysadmins, programmer and users who like build webpages, write blogs, chat online, play cool console games and so much more. you wish to join with an small user space? -join the team today! => https://envs.net/signup/ signup for a envs.net account (html) visit us in gopher and html lands for more info. diff --git a/bin/envs.net/envs_sysinfo.sh b/bin/envs.net/envs_sysinfo.sh index 702315a..df0cc4f 100755 --- a/bin/envs.net/envs_sysinfo.sh +++ b/bin/envs.net/envs_sysinfo.sh @@ -43,7 +43,12 @@ misc=(aria2 bc busybox burrow byobu clinte gfu goaccess hugo jekyll mariadb-clie pandoc pelican screen sqlite3 tmux todotxt-cli twtxt txtnish zola) readarray -t sorted_misc < <(printf '%s\n' "${misc[@]}" | sort) -### + +# +# SYSINFO.JSON +# +JSON_FILE="$WWW_PATH/sysinfo.json" +TMP_JSON='/tmp/sysinfo.json_tmp' custom_pkg_desc() { local pkg="$1" @@ -67,13 +72,6 @@ custom_pkg_desc() { esac } - -# -# SYSINFO.JSON -# -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 @@ -291,9 +289,8 @@ print_category() { if [ "$category" = 'services' ]; then for pkg in "${arr[@]}"; do - # check service is in json + # check service in sysinfo.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 diff --git a/bin/envs.net/envs_user_updated.sh b/bin/envs.net/envs_user_info.sh similarity index 84% rename from bin/envs.net/envs_user_updated.sh rename to bin/envs.net/envs_user_info.sh index 2b88f60..a7f00c1 100755 --- a/bin/envs.net/envs_user_updated.sh +++ b/bin/envs.net/envs_user_info.sh @@ -1,16 +1,15 @@ #!/usr/bin/env bash # -# envs.net - generate the following static sites +# envs.net - this script generates the following static sites # - users_info.json # - user_updates.php -# - gemini index.gmi +# - gemini's index.gmi # -# this script is called by /etc/cron.d/envs_sysinfo +# this script is called by /etc/cron.d/envs_user_info # WWW_PATH='/var/www/envs.net' DOMAIN="envs.net" - [ "$(id -u)" -ne 0 ] && printf 'Please run as root!\n' && exit 1 # @@ -18,6 +17,8 @@ DOMAIN="envs.net" # TMP_JSON='/tmp/users_info.json_tmp' +clear_lastline() { sed -i '$ s/,$//' "$TMP_JSON" ; } + cat << EOM > "$TMP_JSON" { "timestamp": "$(date +'%s')", @@ -182,7 +183,7 @@ EOM # end of user def. array # remove trailing ',' on last user entry unset field_in_progress - sed -i '$ s/,$//' "$TMP_JSON" + clear_lastline cat << EOM >> "$TMP_JSON" ], EOM @@ -192,24 +193,39 @@ EOM done fi # ssh - cat << EOM >> "$TMP_JSON" + # only print ssh-pubkey then user has enabled + if [ -f "$INFO_FILE" ]; then + ssh_pubkey="$(sed -n '/^ssh_pubkey=/{s#^.*=##;p}' "$INFO_FILE")" + case "$ssh_pubkey" in + y|Y|1 ) + cat << EOM >> "$TMP_JSON" "ssh-pubkey": [ EOM - 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" + 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 + clear_lastline - # close user ssh pubkey array ']' and user part. '},' - cat << EOM >> "$TMP_JSON" + # close user ssh pubkey array + cat << EOM >> "$TMP_JSON" ] +EOM + ;; + *) clear_lastline ;; + esac + else + # remove trailing ',' for the last user entry + clear_lastline + fi + # close user part. + cat << EOM >> "$TMP_JSON" }, EOM # EOF done - # remove trailing ',' on last user entry - sed -i '$ s/,$//' "$TMP_JSON" + # remove trailing ',' for last user + clear_lastline cat << EOM >> "$TMP_JSON" } @@ -227,14 +243,14 @@ chown root:www-data "$WWW_PATH"/users_info.json # LIST="$(stat --format=%Z\ %n /home/*/public_html/* | grep -v updated | grep -v your_index_template.php | grep -v cgi-bin | sort -r)" -echo "$LIST" | perl /usr/local/bin/envs.net/envs_user_updated_genpage.pl > /tmp/user_updates.php_tmp +echo "$LIST" | perl /usr/local/bin/envs.net/envs_user_info_genpage.pl > /tmp/user_updates.php_tmp mv /tmp/user_updates.php_tmp "$WWW_PATH"/user_updates.php chown root:www-data "$WWW_PATH"/user_updates.php # -# gemini index.gmi +# gemini's index.gmi # /usr/local/bin/envs.net/envs_gemini_genpage.sh diff --git a/bin/envs.net/envs_user_updated_genpage.pl b/bin/envs.net/envs_user_info_genpage.pl similarity index 89% rename from bin/envs.net/envs_user_updated_genpage.pl rename to bin/envs.net/envs_user_info_genpage.pl index 838fede..0bbd9b7 100755 --- a/bin/envs.net/envs_user_updated_genpage.pl +++ b/bin/envs.net/envs_user_info_genpage.pl @@ -1,7 +1,8 @@ #!/usr/bin/perl # +# envs.net - this script generates the user_updates.php # source from pgadey (ctrl-c.club) -# url: https://github.com/pgadey/bin/blob/master/ctrl-c.club +# url: https://github.com/pgadey/bin/blob/master/ctrl-c.club/updated.pl # print "/dev/null 2>&1 diff --git a/etc/cron.d/envs_user_updated_genpage b/etc/cron.d/envs_user_updated_genpage deleted file mode 100644 index 154d107..0000000 --- a/etc/cron.d/envs_user_updated_genpage +++ /dev/null @@ -1,8 +0,0 @@ -# -# generate user_updates.php , users_info.json -# (once per hour) -# -SHELL=/bin/sh -PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin - -0 * * * * root /usr/local/bin/envs.net/envs_user_updated.sh >/dev/null 2>&1