#!/bin/sh -

# Generates password hashes suitable to paste into /etc/shadow.
# Note that openssl password doesn't support SHA* for passwords;
# the best it can do is MD5.  This was found at
#     https://serverfault.com/questions/330069
# ("how-to-create-an-sha-512-hashed-password-for-shadow")
# $Id: sha512password,v 1.1 2016/11/03 01:12:08 wpollock Exp $

if [ $# = 0 ]
then echo "Usage: ${0##*/} <password>" >&2
     exit 1
fi
printf '%s' "$*" | python -c "\
import crypt,random,string
print crypt.crypt(raw_input(), '\$6\$' + \
''.join([random.choice(string.ascii_letters + string.digits) \
for _ in range(16)]))"
