This commit is contained in:
2025-09-18 13:29:43 +02:00
commit 164a89ea3e
14 changed files with 673 additions and 0 deletions

89
add_user.sh Executable file
View File

@@ -0,0 +1,89 @@
#!/bin/sh
# Usage: add_user.sh <login>
set -e
LOGIN="$1"
[ -z "$LOGIN" ] && { echo "Użycie: $0 <login>"; exit 1; }
# 1. Użytkownik i hasło
PASS="$(openssl rand -base64 12)"
adduser -D -s /bin/sh -h /home/$LOGIN -H "$LOGIN"
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
chown $LOGIN:$LOGIN /home/$LOGIN
mkdir -p /home/$LOGIN/Maildir/Inbox/cur
mkdir -p /home/$LOGIN/Maildir/Inbox/new
mkdir -p /home/$LOGIN/Maildir/Inbox/tmp
mkdir -p /home/$LOGIN/Maildir/Sent/cur
mkdir -p /home/$LOGIN/Maildir/Sent/new
mkdir -p /home/$LOGIN/Maildir/Sent/tmp
mkdir -p /home/$LOGIN/Maildir/Drafts/cur
mkdir -p /home/$LOGIN/Maildir/Drafts/new
mkdir -p /home/$LOGIN/Maildir/Drafts/tmp
mkdir -p /home/$LOGIN/Maildir/Trash/cur
mkdir -p /home/$LOGIN/Maildir/Trash/new
mkdir -p /home/$LOGIN/Maildir/Trash/tmp
cp -r /root/helpers/public_html /home/$LOGIN/
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/
cp irc.conf /home/$LOGIN/.config/weechat
cat << EOF > /home/$LOGIN/.tmux.conf
set -g mouse on
setw -g mode-keys vi
bind -n F1 select-window -t 0
bind -n F2 select-window -t 1
bind -n F3 select-window -t 2
bind -n F12 detach
EOF
cat << EOF > /home/$LOGIN/.profile
if [ -z "$TMUX" ]; then
if ! tmux has-session -t main 2>/dev/null; then
tmux new-session -d -s main -n Mail 'neomutt'
tmux new-window -t main:1 -n IRC 'weechat'
tmux new-window -t main:2 -n Shell 'ash'
fi
# Uruchom motd tylko gdy user wchodzi do Shell okno 2
tmux send-keys -t main:2 '/usr/local/bin/tylda-motd.sh' C-m
tmux select-window -t main:0
exec tmux attach-session -t main
fi
EOF
chown -R $LOGIN:$LOGIN /home/$LOGIN/
# 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"
sendmail -f void@tylda.org $LOGIN@tylda.org < welcome.txt
echo 524288000 > "$USER_CG/memory.max" # 500MB RAM
echo "50000 100000" > "$USER_CG/cpu.max" # 50% CPU (quota/period μs)
echo "===== NOWE KONTO ====="
echo "login : $LOGIN"
echo "hasło : $PASS"
echo "RAM : 500MB"
echo "CPU : 50%"