up.real 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/command/with-contenv sh
  2. if [ ! -d /data ] ; then
  3. mkdir /data
  4. fi
  5. # normal docker secrets
  6. if [ ! -f /data/id_ed25519.pub ] && [ -r /run/secrets/key_pub ] ; then
  7. cp /run/secrets/key_pub /data/id_ed25519.pub
  8. echo "Public key created from secret"
  9. fi
  10. if [ ! -f /data/id_ed25519 ] && [ -r /run/secrets/key_priv ] ; then
  11. cp /run/secrets/key_priv /data/id_ed25519
  12. echo "Private key created from secret"
  13. fi
  14. # ENV variables
  15. if [ ! -f /data/id_ed25519.pub ] && [ ! "$KEY_PUB" = "" ] ; then
  16. echo -n "$KEY_PUB" > /data/id_ed25519.pub
  17. echo "Public key created from ENV variable"
  18. fi
  19. if [ ! -f /data/id_ed25519 ] && [ ! "$KEY_PRIV" = "" ] ; then
  20. echo -n "$KEY_PRIV" > /data/id_ed25519
  21. echo "Private key created from ENV variable"
  22. fi
  23. # check if both keys provided
  24. if [ -f /data/id_ed25519.pub ] && [ ! -f /data/id_ed25519 ] ; then
  25. echo "Private key missing."
  26. echo "You must provide BOTH the private and the public key."
  27. /run/s6/basedir/bin/halt
  28. exit 1
  29. fi
  30. if [ ! -f /data/id_ed25519.pub ] && [ -f /data/id_ed25519 ] ; then
  31. echo "Public key missing."
  32. echo "You must provide BOTH the private and the public key."
  33. /run/s6/basedir/bin/halt
  34. exit 1
  35. fi
  36. # here we have either no keys or both
  37. # if we have both keys, we fix permissions and ownership
  38. # and check for keypair validation
  39. if [ -f /data/id_ed25519.pub ] && [ -f /data/id_ed25519 ] ; then
  40. chmod 0600 /data/id_ed25519.pub /data/id_ed25519
  41. chown root:root /data/id_ed25519.pub /data/id_ed25519
  42. /usr/bin/rustdesk-utils validatekeypair "$(cat /data/id_ed25519.pub)" "$(cat /data/id_ed25519)" || {
  43. echo "Key pair not valid"
  44. /run/s6/basedir/bin/halt
  45. exit 1
  46. }
  47. fi
  48. # if we have no keypair, hbbs will generate one