6 Commits

Author SHA1 Message Date
4901af38b4 move all add user steps to functions 2026-06-09 14:34:07 +02:00
bb253b3700 shellcheck: quote params 2026-06-09 13:38:55 +02:00
0f53834083 move functions above all 2026-06-09 13:38:37 +02:00
9b1f96ba81 gemini & tmux setup separated into functions 2026-06-09 13:36:55 +02:00
efae942441 source is aliast for . and is not POSIX compliant 2026-06-09 13:31:50 +02:00
8026ba05fe make neomitt setup a function 2026-06-09 13:30:12 +02:00

View File

@@ -2,51 +2,51 @@
# Usage: add_user.sh <login> # Usage: add_user.sh <login>
set -e set -e
source /root/helpers/.env . /root/helpers/.env
LOGIN="$1" LOGIN="$1"
[ -z "$LOGIN" ] && { echo "Użycie: $0 <login>"; exit 1; } [ -z "$LOGIN" ] && { echo "Użycie: $0 <login>"; exit 1; }
# 1. Użytkownik i hasło setup_user() {
adduser -D -s /bin/sh -h "/home/$LOGIN" -H "$LOGIN"
addgroup "$LOGIN" tildeusers
PASS="$(openssl rand -base64 16 | sed 's/[\/\+\=\\]//g')" PASS="$(openssl rand -base64 16 | sed 's/[\/\+\=\\]//g')"
adduser -D -s /bin/sh -h /home/$LOGIN -H "$LOGIN" echo "$LOGIN":"$PASS" | chpasswd
echo "$LOGIN:$PASS" | chpasswd
addgroup $LOGIN tildeusers
# 2. Dataset ZFS (quota 200MB) zfs create -o mountpoint="/home/$LOGIN" -o quota=200M "tank/ROOT/homes/$LOGIN"
zfs create -o mountpoint=/home/$LOGIN -o quota=200M tank/ROOT/homes/$LOGIN chown "$LOGIN":"$LOGIN" "/home/$LOGIN"
chown $LOGIN:$LOGIN /home/$LOGIN
cat "export EDITOR=nvim" >> /home/$LOGIN/.ashrc
mkdir -p /home/$LOGIN/Maildir/Inbox/cur # neomutt had issues with default vi
mkdir -p /home/$LOGIN/Maildir/Inbox/new cat "export EDITOR=nvim" >> "/home/$LOGIN/.ashrc"
mkdir -p /home/$LOGIN/Maildir/Inbox/tmp
mkdir -p /home/$LOGIN/Maildir/Sent/cur # set cgroup
mkdir -p /home/$LOGIN/Maildir/Sent/new CG_ROOT=/sys/fs/cgroup/users
mkdir -p /home/$LOGIN/Maildir/Sent/tmp mkdir -p "$CG_ROOT"
# upewnij się, że kontrolery włączone w parent „users”
echo "+cpu +memory" > "$CG_ROOT/cgroup.subtree_control" 2>/dev/null || true
mkdir -p /home/$LOGIN/Maildir/Drafts/cur USER_CG="$CG_ROOT/$LOGIN"
mkdir -p /home/$LOGIN/Maildir/Drafts/new mkdir "$USER_CG"
mkdir -p /home/$LOGIN/Maildir/Drafts/tmp
mkdir -p /home/$LOGIN/Maildir/Trash/cur # set default folders for ssh & gnu and set them private
mkdir -p /home/$LOGIN/Maildir/Trash/new mkdir -m 0700 "/home/$LOGIN/.ssh"
mkdir -p /home/$LOGIN/Maildir/Trash/tmp mkdir -m 0700 "/home/$LOGIN/.gnupg"
}
chmod -R 0700 /home/$LOGIN/Maildir setup_neomutt () {
for dir in "Inbox" "Sent" "Drafts" "Trash"; do
for subdir in "cur" "new" "tmp"; do
mkdir -p "/home/$LOGIN/Maildir/$dir/$subdir"
done
done
cp -r /root/helpers/public_html /home/$LOGIN/ chmod -R 0700 /home/"$LOGIN"/Maildir
sed -i "s/<<USER>>/$LOGIN/g" /home/$LOGIN/public_html/index.php }
sed -i "s/<<USER>>/$LOGIN/g" /home/$LOGIN/public_html/parts/header.php
sed -i "s/<<USER>>/$LOGIN/g" /home/$LOGIN/public_html/blog/index.php
mkdir -p /home/$LOGIN/.config/weechat/ setup_tmux () {
mkdir -p "/home/$LOGIN/.config/tmux"
cp /root/helpers/irc.conf /home/$LOGIN/.config/weechat cat << EOF > "/home/$LOGIN/.config/tmux/tmux.conf"
mkdir -p /home/$LOGIN/.config/tmux
cat << EOF > /home/$LOGIN/.config/tmux/tmux.conf
set -g mouse on set -g mouse on
setw -g mode-keys vi setw -g mode-keys vi
bind -n F1 select-window -t 0 bind -n F1 select-window -t 0
@@ -65,52 +65,81 @@ set-hook -g client-attached "send-keys -t main:2 '/usr/local/bin/tylda-motd.sh'
EOF EOF
cat << EOF > /home/$LOGIN/.profile cat << EOF > "/home/$LOGIN/.profile"
if [ -z "\$TMUX" ]; then if [ -z "\$TMUX" ]; then
exec tmux attach -t main || exec tmux new -s main exec tmux attach -t main || exec tmux new -s main
fi fi
EOF EOF
}
setup_gemini () {
# 3. Cgroup v2
CG_ROOT=/sys/fs/cgroup/users
mkdir -p "$CG_ROOT"
# upewnij się, że kontrolery włączone w parent „users”
echo "+cpu +memory" > "$CG_ROOT/cgroup.subtree_control" 2>/dev/null || true
USER_CG="$CG_ROOT/$LOGIN"
mkdir "$USER_CG"
# gemini
gmi="/home/$LOGIN/public_gemini/" gmi="/home/$LOGIN/public_gemini/"
mkdir -p $gmi mkdir -p "$gmi"
ln -s $gmi /srv/gemini/~$LOGIN ln -s "$gmi" "/srv/gemini/~$LOGIN"
cat <<EOF > $gmi/index.gmi cat <<EOF > "$gmi/index.gmi"
# $LOGIN # $LOGIN
EOF EOF
# end gemini }
mkdir -p /home/$LOGIN/.ssh setup_html () {
mkdir -p /home/$LOGIN/.gnupg cp -r /root/helpers/public_html "/home/$LOGIN/"
touch /home/$LOGIN/public_html/.webring sed -i "s/<<USER>>/$LOGIN/g" "/home/$LOGIN/"public_html/index.php
sed -i "s/<<USER>>/$LOGIN/g" "/home/$LOGIN/"public_html/parts/header.php
sed -i "s/<<USER>>/$LOGIN/g" "/home/$LOGIN/"public_html/blog/index.php
chmod 0700 /home/$LOGIN/.ssh touch "/home/$LOGIN/public_html/.webring"
chmod 0700 /home/$LOGIN/.gnupg }
chown -R $LOGIN:$LOGIN /home/$LOGIN/ setup_nextcloud () {
curl -X POST https://cloud.tylda.org/ocs/v1.php/cloud/users \
-d userid="$LOGIN" \
-d password="$PASS" \
-H "OCS-APIRequest: true" \
-u "$NEXTCLOUD_USER:$NEXTCLOUD_PASS"
curl -X POST https://cloud.tylda.org/ocs/v1.php/cloud/users -d userid="$LOGIN" -d password="$PASS" -H "OCS-APIRequest: true" -u "$NEXTCLOUD_USER:$NEXTCLOUD_PASS" curl -X PUT "https://cloud.tylda.org/ocs/v1.php/cloud/users/$LOGIN" \
curl -X PUT "https://cloud.tylda.org/ocs/v1.php/cloud/users/$LOGIN" -H "OCS-APIRequest: true" -u "$NEXTCLOUD_USER:$NEXTCLOUD_PASS" -d key="quota" -d value="250MB" -H "OCS-APIRequest: true" \
-u "$NEXTCLOUD_USER:$NEXTCLOUD_PASS" \
-d key="quota" \
-d value="250MB"
}
setup_weechat () {
mkdir -p "/home/$LOGIN/.config/weechat/"
cp /root/helpers/irc.conf "/home/$LOGIN/.config/weechat"
}
send_welcome_mail () {
cp welcome_tmp.txt welcome.txt cp welcome_tmp.txt welcome.txt
echo "Login: $LOGIN" >> welcome.txt echo "Login: $LOGIN" >> welcome.txt
echo "Hasło: $PASS" >> welcome.txt echo "Hasło: $PASS" >> welcome.txt
sendmail -f v0id1st@tylda.org $LOGIN@tylda.org < welcome.txt sendmail -f v0id1st@tylda.org "$LOGIN@tylda.org" << EOF
Subject: Witaj na tylda.org!
From: v0id1st@tylda.org
rm -f welcome.txt Siemano :D
Witaj na tyldzie, baw się dobrze! Wpadnij się przywitać na IRCa.
Twoje dane do Nextcloud to (https://cloud.tylda.org) to:
Login: $LOGIN
Hasło: $PASS
EOF
}
setup_user
setup_neomutt
setup_tmux
setup_gemini
setup_html
setup_weechat
setup_nextcloud
chown -R "$LOGIN":"$LOGIN" "/home/$LOGIN/"
send_welcome_mail
echo 524288000 > "$USER_CG/memory.max" # 500MB RAM echo 524288000 > "$USER_CG/memory.max" # 500MB RAM
echo "50000 100000" > "$USER_CG/cpu.max" # 50% CPU (quota/period μs) echo "50000 100000" > "$USER_CG/cpu.max" # 50% CPU (quota/period μs)