2021-08-20 13:16:14 -05:00
|
|
|
#!/usr/bin/env bash
|
2020-04-23 08:55:32 -05:00
|
|
|
|
2021-12-11 00:03:35 -06:00
|
|
|
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
|
|
|
|
|
2020-04-23 08:55:32 -05:00
|
|
|
SUDO=''
|
2021-12-11 00:03:35 -06:00
|
|
|
if [ ! -w "$CONFIGDIR" ]; then
|
2020-04-24 09:59:00 -05:00
|
|
|
if (( $EUID != 0 )); then
|
|
|
|
if hash sudo 2>/dev/null; then
|
|
|
|
SUDO='sudo'
|
|
|
|
else
|
|
|
|
echo "Run the script as root."
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-04-23 08:55:32 -05:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2021-12-11 00:03:35 -06:00
|
|
|
if [ -f $CONFIGDIR/proof_key ]; then
|
|
|
|
echo "$CONFIGDIR/proof_key exists already."
|
2020-04-23 08:55:32 -05:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if hash ssh-keygen 2>/dev/null; then
|
2021-12-11 00:03:35 -06:00
|
|
|
$SUDO ssh-keygen -t rsa -N "" -m PEM -f $CONFIGDIR/proof_key
|
2020-04-23 08:55:32 -05:00
|
|
|
if [ $? -ne 0 ] ; then
|
|
|
|
exit $?
|
2021-12-11 00:03:35 -06:00
|
|
|
fi
|
2021-11-15 10:04:57 -06:00
|
|
|
if id -u cool >/dev/null 2>&1; then
|
2021-12-11 00:03:35 -06:00
|
|
|
$SUDO chown cool: $CONFIGDIR/proof_key
|
2020-04-23 08:55:32 -05:00
|
|
|
else
|
2021-11-18 06:08:14 -06:00
|
|
|
echo "User cool does not exist. Please reinstall coolwsd package, or in case of manual installation from source, create the cool user manually."
|
2020-04-23 08:55:32 -05:00
|
|
|
fi
|
|
|
|
else
|
2021-12-11 00:03:35 -06:00
|
|
|
echo "ssh-keygen command not found. Please install openssh client tools."
|
2020-04-23 08:55:32 -05:00
|
|
|
exit 127
|
|
|
|
fi
|
|
|
|
|