953cfea064
Signed-off-by: Gleb Popov <6yearold@gmail.com> Change-Id: I97c882291954eb9bf876121ebf0878b507e4d060
46 lines
1.1 KiB
Bash
Executable file
46 lines
1.1 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
if [ "$1" == "-h" ]; then
|
|
echo "Usage: coolwsd-generate-proof-key [-h] [CONFIGDIR]"
|
|
echo "CONFIGDIR defaults to /etc/coolwsd"
|
|
exit 0
|
|
fi
|
|
|
|
if [ "$1" ]; then
|
|
CONFIGDIR="$1"
|
|
else
|
|
CONFIGDIR="/etc/coolwsd"
|
|
fi
|
|
|
|
SUDO=''
|
|
if [ ! -w "$CONFIGDIR" ]; then
|
|
if (( $EUID != 0 )); then
|
|
if hash sudo 2>/dev/null; then
|
|
SUDO='sudo'
|
|
else
|
|
echo "Run the script as root."
|
|
exit 1
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
if [ -f $CONFIGDIR/proof_key ]; then
|
|
echo "$CONFIGDIR/proof_key exists already."
|
|
exit 0
|
|
fi
|
|
|
|
if hash ssh-keygen 2>/dev/null; then
|
|
$SUDO ssh-keygen -t rsa -N "" -m PEM -f $CONFIGDIR/proof_key
|
|
if [ $? -ne 0 ] ; then
|
|
exit $?
|
|
fi
|
|
if id -u cool >/dev/null 2>&1; then
|
|
$SUDO chown cool: $CONFIGDIR/proof_key
|
|
else
|
|
echo "User cool does not exist. Please reinstall coolwsd package, or in case of manual installation from source, create the cool user manually."
|
|
fi
|
|
else
|
|
echo "ssh-keygen command not found. Please install openssh client tools."
|
|
exit 127
|
|
fi
|
|
|