myvesta/bin/v-generate-api-key
2021-02-08 22:32:34 +01:00

43 lines
1018 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}
chmod 0770 ${KEYS}
fi
if [[ -e ${KEYS}${HASH} ]] ; then
while [[ -e ${KEYS}${HASH} ]] ; do
HASH=$(keygen)
done
fi
touch ${KEYS}${HASH}
echo ${HASH}
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
exit