mirror of https://git.envs.net/envs/ops.git
update ops:
- rename envs_user_update* to envs_user_info* - users_info.json : only print ssh-pubkey then user has enabled
This commit is contained in:
parent
79dd4e7eed
commit
b96786bb16
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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 "<?php
|
|
@ -0,0 +1,8 @@
|
|||
#
|
||||
# generates user_updates.php , users_info.json, gemini's index.gmi
|
||||
# (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_info.sh >/dev/null 2>&1
|
|
@ -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
|
Loading…
Reference in New Issue