first commit
This commit is contained in:
commit
1530450313
165 changed files with 8443 additions and 0 deletions
29
scripts/adduser.sh
Executable file
29
scripts/adduser.sh
Executable file
|
|
@ -0,0 +1,29 @@
|
|||
#!/bin/bash
|
||||
|
||||
USERS_FILE="../data/users.json"
|
||||
|
||||
# Ввод логина
|
||||
read -p "Enter username: " username
|
||||
read -s -p "Enter password: " password
|
||||
echo
|
||||
|
||||
# SHA-256 хэш
|
||||
hash=$(echo -n "$password" | sha256sum | awk '{print $1}')
|
||||
|
||||
# Создаём пустой массив, если файл отсутствует или пустой
|
||||
if [[ ! -s "$USERS_FILE" ]]; then
|
||||
echo "[]" > "$USERS_FILE"
|
||||
fi
|
||||
|
||||
# Проверка существующего пользователя
|
||||
if jq --exit-status ".[] | select(.Login==\"$username\")" "$USERS_FILE" >/dev/null; then
|
||||
# Обновляем пароль
|
||||
jq --arg u "$username" --arg h "$hash" 'map(if .Login==$u then .PasswordHash=$h else . end)' "$USERS_FILE" > tmp.json
|
||||
mv tmp.json "$USERS_FILE"
|
||||
echo "✅ Updated password for user '$username'"
|
||||
else
|
||||
# Добавляем нового пользователя
|
||||
jq --arg u "$username" --arg h "$hash" '. + [{"Login":$u,"PasswordHash":$h}]' "$USERS_FILE" > tmp.json
|
||||
mv tmp.json "$USERS_FILE"
|
||||
echo "✅ Added new user '$username'"
|
||||
fi
|
||||
Loading…
Add table
Add a link
Reference in a new issue