vesta/bin/v-generate-api-key

42 lines
997 B
Bash
Executable File

#!/bin/bash
# info: generate api key
# options: none
#
# The function creates a key file in /usr/local/vesta/data/keys/
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
keygen()
{
< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo;
}
KEYS='/usr/local/vesta/data/keys/'
HASH=$(keygen)
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
if [ ! -d ${KEYS} ]; then
mkdir ${KEYS}
fi
if [[ -e ${KEYS}${HASH} ]] ; then
while [[ -e ${KEYS}${HASH} ]] ; do
HASH=$(keygen)
done
fi
touch ${KEYS}${HASH}
echo ${HASH}
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
exit