First commit!

let's hope I don't fry gitea
This commit is contained in:
jmjl 2022-07-17 16:28:16 +00:00
commit 22e91cd555
7 changed files with 158 additions and 0 deletions

2
README.md Normal file
View file

@ -0,0 +1,2 @@
# Tools
This is a repository containing some internal tools that we use at [tilde.green](https://tilde.green)

3
bin/gitea_adm Executable file
View file

@ -0,0 +1,3 @@
#!/bin/sh
[ "$1" = "" ] && exit 1
exec sudo -u git /opt/git/gitea $@

70
bin/makeuser Executable file
View file

@ -0,0 +1,70 @@
#!/bin/sh
# ---------------------------------------------------------------------------
# makeuser - tilde.green new user creation
# Usage: makeuser [-h|--help] <username> <email> "<pubkey>"
# ---------------------------------------------------------------------------
# taken from https://tildegit.org/team/makeuser
PROGNAME=${0##*/}
VERSION="0.2"
error_exit() {
printf "%s: %s\n" "$PROGNAME" "${1:-"Unknown Error"}" >&2
exit 1
}
usage() {
printf "usage: %s %s [-h|--help] <username> <email> \"<pubkey>\"\n" "$PROGNAME" "$VERSION"
}
case $1 in
-h | --help)
usage; exit ;;
-* | --*)
usage; error_exit "unknown option $1" ;;
*)
if [ $# -ne 3 ]; then
error_exit "not enough args"
fi
if id "$1" > /dev/null 2>&1; then
exit 0
fi
printf "adding new user %s\n" "$1"
newpw=$(pwgen -1B 20)
#sudo useradd -m -g 100 -s /bin/bash "$1" \
sudo useradd -m -s /bin/bash "$1" \
|| error_exit "couldn't add user"
printf "%s:%s\n" "$1" "$newpw" | sudo chpasswd
sudo chmod 755 "/home/$1"
printf "sending welcome mail\n"
sed -e "s/newusername/$1/g" \
-e "s/newpassword/$newpw/" \
-e "s/newtoemail/$2/" \
/opt/makeuser/welcome-email.tmpl \
| sendmail "$1" "$2" root@tilde.green
printf "adding ssh pubkey\n"
#sudo mkdir "/home/$1/.ssh"
#sudo chmod 775 "/home/$1/.ssh"
printf "%s\n" "$3" | sudo tee "/home/$1/.ssh/authorized_keys"
#sudo chmod 664 "/home/$1/.ssh/authorized_keys"
#sudo chown $1:$1 "/home/$1/.ssh" -R
#printf "\nannouncing new user on mastodon\n"
#/usr/local/bin/toot "welcome new user ~$1!"
printf "cleanup current signup\n"
sudo sed -i"" "/\b$1\b/d" /var/signups_current
printf "fix sorting in /etc/passwd\n"
sudo pwck -s
printf "applying disk quota\n"
# 1.5Gib -> 1536Mib
sudo setquota -u "$1" 1G 1536M 0 0 /
;;
esac

2
bin/nextcloud_adm Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
exec sudo -u www-data php /home/cloud/nextcloud/console.php $@

3
bin/publish-page Executable file
View file

@ -0,0 +1,3 @@
#!/bin/bash
sudo rm -fr /var/www/html
sudo cp /var/www/green-testing/ /var/www/html/ -r

7
bin/rgit Executable file
View file

@ -0,0 +1,7 @@
#!/bin/sh
# Thanks to xwindows
[ "$SUDO_USER" = "" ] && { sudo -u git rgit; exit $?; }
/opt/git/gitea admin user create --username "$SUDO_USER" --email "$SUDO_USER@tilde.green" --random-password --random-password-length 25
R=$?
[ "$R" = "0" ] && echo "You can login on https://git.tilde.green/user/login"
exit $R

71
bin/uam Executable file
View file

@ -0,0 +1,71 @@
#!/bin/sh
# jan6's script
exec 3<&0
r1b(){
unset -v c;
if [ -t 0 ];then
stty_bak=$(stty -g);
stty -icanon min 1 time 0 -echo;
fi;
c="$(dd bs=1 count=1 2>/dev/null; echo .)";c="${c%.}";
if [ -t 0 ];then
stty "${stty_bak}";
fi;
printf '%s\n' "${c}" ;
# unset -v c;
};
#file="${1:-list.txt}"
file="${1:-/var/signups}"
grep -v '^[[:blank:]]*#' "${file}"|
while read -r i;do
ix="$(echo "${i}"|sed 's/\"/\\"/g')"
printf "\n%s\n\n%s\n\n%s\n\n" \
"-------" \
"${i}" \
"(a)ccept, (d)elete, (c)omment, (i)gnore?"
#read -r c <&3
c="$(r1b <&3)"
case "${c}" in
(i)echo "skipping!";continue;;
(a|c)
case "${c}" in
(a)
echo "accepting ${i}"
eval "${i}";;
(c)
echo "commenting ${i}";;
esac
t="$(mktemp)"
cp "${file}" "${t}" &&
awk "{
if(\$0 == \"${ix}\")"'{
print "#"$0
}else{
print $0
};}' >"${t}" <"${file}" &&
(cat "${t}" >"${file}"||echo "modified file in ${t}")&&
rm "$t"
;;
(d)
echo "really delete? (y/n)"
if [ "$(r1b <&3)" != "y" ];then
echo "skipping!"
continue
fi
echo "DELETING ${i}"
t="$(mktemp)"
cp "${file}" "${t}" &&
awk "{
if(\$0 == \"${ix}\")"'{
}else{
print $0
};}' >"${t}" <"${file}" &&
(cat "${t}" >"${file}"||echo "modified file in ${t}")&&
rm -f "$t"
;;
(*)echo "skipping!";continue;;
esac
#echo "${c} ${i}"
done