From 4a6e853106ba06f7c6e90855b22b826b28fb7a90 Mon Sep 17 00:00:00 2001 From: v0id1st Date: Thu, 9 Oct 2025 23:12:44 +0200 Subject: [PATCH] create nextcloud user --- .gitignore | 1 + add_ssh_key.sh | 16 ++++++++++++++++ add_user.sh | 16 ++++++++++++++-- welcome.txt | 4 ---- welcome_tmp.txt | 9 +++++++++ 5 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 .gitignore create mode 100755 add_ssh_key.sh delete mode 100644 welcome.txt create mode 100644 welcome_tmp.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/add_ssh_key.sh b/add_ssh_key.sh new file mode 100755 index 0000000..646e074 --- /dev/null +++ b/add_ssh_key.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +[ -n "$1" ] && login=$1 || read -p "provide login: " login +[ -n "$2" ] && ssh_key=$2 || read -p "provide ssh key: " ssh_key + +ssh_dir=/home/$login/.ssh +mkdir -p "$ssh_dir" +[ ! -f "$ssh_dir/authorized_keys" ] && touch $ssh_dir/authorized_keys + +# add it to authorized_keys but avoid adding it twice +ak=$ssh_dir/authorized_keys +[ ! grep "$ssh_key" $ak ] && echo "$ssh_key" >> $ak + +# ssh wont work without it +chmod -R 0700 /home/$login/.ssh +chown -R $login:$login $ssh_dir diff --git a/add_user.sh b/add_user.sh index f43e6e2..569ea8e 100755 --- a/add_user.sh +++ b/add_user.sh @@ -2,11 +2,13 @@ # Usage: add_user.sh set -e +source /root/helpers/.env + LOGIN="$1" [ -z "$LOGIN" ] && { echo "Użycie: $0 "; exit 1; } # 1. Użytkownik i hasło -PASS="$(openssl rand -base64 12)" +PASS="$(openssl rand -base64 16 | sed 's/[\/\+\=\\]//g')" adduser -D -s /bin/sh -h /home/$LOGIN -H "$LOGIN" echo "$LOGIN:$PASS" | chpasswd addgroup $LOGIN tildeusers @@ -96,7 +98,17 @@ mkdir -p /home/$LOGIN/.gnupg chmod 0700 /home/$LOGIN/.ssh chmod 0700 /home/$LOGIN/.gnupg -sendmail -f void1st@tylda.org $LOGIN@tylda.org < welcome.txt +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" -H "OCS-APIRequest: true" -u "$NEXTCLOUD_USER:$NEXTCLOUD_PASS" -d key="quota" -d value="250MB" + +cp welcome_tmp.txt welcome.txt + +echo "Login: $LOGIN" >> welcome.txt +echo "Hasło: $PASS" >> welcome.txt + +sendmail -f v0id1st@tylda.org $LOGIN@tylda.org < welcome.txt + +rm -f welcome.txt echo 524288000 > "$USER_CG/memory.max" # 500 MB RAM echo "50000 100000" > "$USER_CG/cpu.max" # 50 % CPU (quota/period μs) diff --git a/welcome.txt b/welcome.txt deleted file mode 100644 index dc6facd..0000000 --- a/welcome.txt +++ /dev/null @@ -1,4 +0,0 @@ -Subject: Witaj na tylda.org! -From: v0id1st@tylda.org - -Siemano :D diff --git a/welcome_tmp.txt b/welcome_tmp.txt new file mode 100644 index 0000000..e99a6a7 --- /dev/null +++ b/welcome_tmp.txt @@ -0,0 +1,9 @@ +Subject: Witaj na tylda.org! +From: v0id1st@tylda.org + +Siemano :D +Witaj na tyldzie, baw się dobrze! Wpadnij się przywitać na IRCa. + +Twoje dane do Nextcloud to (https://cloud.tylda.org) to: + +