black ops scripts

This commit is contained in:
Tilde Black Admin 2019-08-01 12:04:13 +00:00
commit 039dab0a06
6 changed files with 132 additions and 0 deletions

30
assign.sh Executable file
View File

@ -0,0 +1,30 @@
#!/bin/sh
email="$1"
key="$2"
keystore="$HOME/keystore.txt"
if [ -n "$email" ] && [ -n "$key" ]; then
all_users=$(grep /home < /etc/passwd | awk -F: '{print $1}' | gshuf)
# once we find 10 matches quit
matches=1
match_users=$(
printf "%s" "$all_users" | while read -r n; do
if [ $matches -gt 10 ]; then
exit
fi
if [ ! -s "/home/${n}/.ssh/authorized_keys" ]; then
printf "%s " "$n"
matches=$((matches+1))
printf "%s\\n" "$key" > "/home/${n}/.ssh/authorized_keys"
fi
done
)
sed -e "s/USERS/${match_users}/" /etc/templates/assign.tmpl | sendmail "${email}"
{
printf "Email: %s\\n" "$email"
printf "Key: %s\\n" "$key"
printf "Users: %s\\n\\n" "$match_users"
} >> "$keystore"
else
printf "Provide email address and ssh-key as params."
fi

30
docsgen.sh Executable file
View File

@ -0,0 +1,30 @@
#!/bin/sh
set -e
DOC_DIR="$HOME/docs"
cd "${DOC_DIR}" || exit 1
# fetch the latest remote repo changes
git fetch origin master -q 2> /dev/null
# get shas for our local repo and remote repo
remotesha=$(git rev-parse origin/master)
localsha=$(git rev-parse HEAD)
# if shas are different, we need to update
if [ "$remotesha" != "$localsha" ] || [ "$1" = "force" ]; then
# clear all our local changes
git reset --hard HEAD -q
# pull in the latest updates from remote
git pull -q origin master 2> /dev/null
# build the web version
/usr/local/bin/mkdocs build > /dev/null 2> /dev/null
# clear the gopher version
rm /var/gopher/docs/*.md
# copy files to the gopher version
cd "$HOME/docs/docs/" || exit 1
cp ./*.md /var/gopher/docs/
fi

13
gopherroot.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/sh
all_users=$(grep /home < /etc/passwd | awk -F: '{print $1}')
output="/var/gopher/users.gophermap"
printf "iUsers:\\n" > "$output"
printf "%s" "$all_users" | while read -r n; do
if [ -f "/var/gopher/users/${n}/gophermap" ]; then
printf "1~%s\\t/users/%s\\n" "$n" "$n" >> "$output"
fi
done
cat /var/gopher/head.gophermap /var/gopher/users.gophermap > /var/gopher/gophermap

23
remove.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/sh
key="$1"
keystore="$HOME/keystore.txt"
if [ -n "$1" ]; then
all_users=$(grep /home < /etc/passwd | awk -F: '{print $1}')
match_users=$(
printf "%s" "$all_users" | while read -r n; do
if [ -s "/home/${n}/.ssh/authorized_keys" ]; then
if grep -q "$key" "/home/${n}/.ssh/authorized_keys"; then
if [ "$n" != "fox" ]; then
printf "%s " "$n"
printf "DISABLED" > "/home/${n}/.ssh/authorized_keys"
usermod -s /sbin/nologin "${n}"
fi
fi
fi
done
)
printf "DISABLED: %s\\n" "$match_users"
printf "DISABLED: %s\\n" "$match_users" >> "$keystore"
fi

17
restore.sh Executable file
View File

@ -0,0 +1,17 @@
#!/bin/sh
key="$1"
users="$*"
if [ -n "$key" ] && [ -n "$users" ]; then
for n in $users; do
if [ -s "/home/${n}/.ssh/authorized_keys" ]; then
if grep -q "DISABLED" "/home/${n}/.ssh/authorized_keys"; then
if [ "$n" != "fox" ]; then
printf "%s\\n" "$key" > "/home/${n}/.ssh/authorized_keys"
printf "%s restored\\n" "$n"
usermod -s /bin/ksh "${n}"
fi
fi
fi
done
fi

19
webroot.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/sh
all_users=$(grep /home < /etc/passwd | awk -F: '{print $1}' | sort)
output="/var/www/htdocs/users.partial"
printf "<h3>Users:</h3>\\n" > "$output"
printf "<ul>\\n" >> "$output"
printf "%s" "$all_users" | while read -r n; do
if [ -f "/var/www/htdocs/users/${n}/index.html" ]; then
printf "<li><a href='/users/%s'>~%s</a></li>\\n" "$n" "$n" >> "$output"
fi
done
printf "</ul>\\n" >> "$output"
cat /var/www/htdocs/head.partial \
/var/www/htdocs/intro.partial \
/var/www/htdocs/users.partial \
/var/www/htdocs/foot.partial > /var/www/htdocs/index.html