fill_teams.sh: add a new option to generate password
This commit is contained in:
parent
a1c94d582d
commit
4de0c64672
|
@ -2,6 +2,7 @@
|
|||
|
||||
BASEURL="http://127.0.0.1:8081/admin"
|
||||
GEN_CERTS=0
|
||||
GEN_PASSWD=0
|
||||
EXTRA_TEAMS=0
|
||||
CSV_SPLITER=","
|
||||
CSV_COL_LASTNAME=1
|
||||
|
@ -16,6 +17,7 @@ usage() {
|
|||
echo " -S -csv-spliter SEP CSV separator (default: $CSV_SPLITER)"
|
||||
echo " -e -extra-teams NBS Number of extra teams to generate (default: ${EXTRA_TEAMS})"
|
||||
echo " -c -generate-certificate Should team certificates be generated? (default: no)"
|
||||
echo " -p -generate-password Should generate team password to teams.pass? (default: no)"
|
||||
}
|
||||
|
||||
# Parse options
|
||||
|
@ -33,6 +35,8 @@ do
|
|||
shift;;
|
||||
-c|-generate-certificates)
|
||||
GEN_CERTS=1;;
|
||||
-p|-generate-password)
|
||||
GEN_PASSWD=1;;
|
||||
*)
|
||||
echo "Unknown option '$1'"
|
||||
usage
|
||||
|
@ -41,8 +45,7 @@ do
|
|||
shift
|
||||
done
|
||||
|
||||
[ "$#" -lt 1 ] && { usage; exit 1; }
|
||||
PART_FILE="$1"
|
||||
[ "$#" -lt 1 ] && [ "${EXTRA_TEAMS}" -eq 0 ] && { usage; exit 1; }
|
||||
|
||||
new_team() {
|
||||
head -n "$1" team-names.txt | tail -1 | sed -E 's/^.*\|\[\[([^|]+\|)?([^|]+)\]\][^|]*\|([A-Fa-f0-9]{1,2})\|([A-Fa-f0-9]{1,2})\|([A-Fa-f0-9]{1,2})\|([0-9]{1,3})\|([0-9]{1,3})\|([0-9]{1,3})\|.*$/\6 \7 \8 \2/' |
|
||||
|
@ -59,6 +62,19 @@ new_team() {
|
|||
|
||||
COLOR=$((($R*256 + $G) * 256 + $B))
|
||||
|
||||
[ "${GEN_PASSWD}" -eq 1 ] && {
|
||||
PASSWD=$(pwgen -B -y 12)
|
||||
cat >> teams.pass <<EOF
|
||||
${N}:${PASSWD}
|
||||
EOF
|
||||
NP=$(echo $N | cut -d : -f 1 | tr '[:upper:]âéêè' '[:lower:]aeee')
|
||||
SALT="$(openssl rand -base64 3)"
|
||||
HASHED="{SSHA}$(echo -n $PASS$SALT | openssl dgst -binary -sha1 | sed 's#$#'"$SALT"'#' | base64)"
|
||||
cat >> htpasswd <<EOF
|
||||
${NP}:${HASHED}
|
||||
EOF
|
||||
}
|
||||
|
||||
curl -s -d "{\"name\": \"$N\",\"color\": $COLOR}" "${BASEURL}/api/teams/"
|
||||
done | grep -Eo '"id":[0-9]+,' | grep -Eo "[0-9]+"
|
||||
}
|
||||
|
@ -80,6 +96,9 @@ do
|
|||
echo
|
||||
done
|
||||
|
||||
[ "$#" -lt 1 ] && exit 0
|
||||
PART_FILE="$1"
|
||||
|
||||
TMAX=`cat "$PART_FILE" | cut -d "${CSV_SPLITER}" -f $CSV_COL_TEAM | sort | uniq | wc -l`
|
||||
TMAX=$(($TMAX + $TNUM))
|
||||
cat "$PART_FILE" | cut -d "${CSV_SPLITER}" -f $CSV_COL_TEAM | sort | uniq | while read TEAMID
|
||||
|
|
Loading…
Reference in New Issue
Block a user