2023-10-11 15:39:52 +02:00
|
|
|
#!/bin/bash
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
|
2023-10-11 19:20:52 +02:00
|
|
|
set -e
|
|
|
|
|
2023-10-11 15:39:52 +02:00
|
|
|
SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
2023-10-11 18:05:11 +02:00
|
|
|
source $SELF_DIR/../cascading-pr-lib.sh
|
2023-10-11 19:20:52 +02:00
|
|
|
TMPDIR=/tmp/cascading-pr
|
2023-10-11 15:39:52 +02:00
|
|
|
|
|
|
|
function push_self() {
|
|
|
|
local host_port=$1
|
|
|
|
|
|
|
|
forgejo-test-helper.sh push_self_action http://root:admin1234@$host_port root cascading-pr vTest
|
|
|
|
}
|
|
|
|
|
2023-10-11 19:20:52 +02:00
|
|
|
function user_login() {
|
|
|
|
local username=$1
|
|
|
|
(
|
|
|
|
export DOT=$TMPDIR/$username
|
|
|
|
forgejo-curl.sh logout
|
|
|
|
forgejo-curl.sh --user $username --password "${options[password]}" login ${options[url]}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function user_curl() {
|
|
|
|
local username=$1
|
|
|
|
shift
|
|
|
|
(
|
|
|
|
export DOT=$TMPDIR/$username
|
|
|
|
forgejo-curl.sh "$@"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function create_user() {
|
|
|
|
local username="$1" email="$2"
|
|
|
|
forgejo-curl.sh api_json -X DELETE --data-raw '{"purge":true}' ${options[url]}/api/v1/admin/users/$username >& /dev/null || true
|
|
|
|
forgejo-curl.sh api_json --data-raw '{"username":"'$username'","email":"'$email'","password":"'${options[password]}'","must_change_password":false}' ${options[url]}/api/v1/admin/users
|
|
|
|
user_login $username
|
|
|
|
}
|
|
|
|
|
2023-10-11 15:39:52 +02:00
|
|
|
function run() {
|
2023-10-11 18:05:11 +02:00
|
|
|
push_self ${options[host_port]}
|
2023-10-11 15:39:52 +02:00
|
|
|
|
2023-10-11 19:20:52 +02:00
|
|
|
create_user user1 user1@example.com
|
|
|
|
create_user user2 user2@example.com
|
|
|
|
|
2023-10-11 15:39:52 +02:00
|
|
|
echo do something
|
|
|
|
}
|
|
|
|
|
|
|
|
function main() {
|
|
|
|
local command=run
|
2023-10-11 18:05:11 +02:00
|
|
|
options[host_port]=$(cat forgejo-ip):3000
|
2023-10-11 19:20:52 +02:00
|
|
|
options[url]=http://${options[host_port]}
|
2023-10-11 18:05:11 +02:00
|
|
|
options[token]=$(cat forgejo-token)
|
2023-10-11 19:20:52 +02:00
|
|
|
options[password]=admin1234
|
2023-10-11 15:39:52 +02:00
|
|
|
|
|
|
|
while true; do
|
|
|
|
case "$1" in
|
|
|
|
--verbose)
|
|
|
|
shift
|
|
|
|
verbose
|
|
|
|
;;
|
|
|
|
--debug)
|
|
|
|
shift
|
|
|
|
debug
|
|
|
|
;;
|
2023-10-11 15:50:12 +02:00
|
|
|
--host_port)
|
|
|
|
shift
|
2023-10-11 18:05:11 +02:00
|
|
|
options[host_port]=$1
|
2023-10-11 15:50:12 +02:00
|
|
|
;;
|
|
|
|
--url)
|
|
|
|
shift
|
2023-10-11 18:05:11 +02:00
|
|
|
options[url]=$1
|
2023-10-11 15:50:12 +02:00
|
|
|
;;
|
|
|
|
--token)
|
|
|
|
shift
|
2023-10-11 18:05:11 +02:00
|
|
|
options[token]=$1
|
2023-10-11 15:50:12 +02:00
|
|
|
;;
|
2023-10-11 15:39:52 +02:00
|
|
|
*)
|
2023-10-11 18:05:11 +02:00
|
|
|
"${1:-run}"
|
2023-10-11 15:39:52 +02:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
${MAIN:-main} "${@}"
|