common_utils.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/bash
  2. # Copyright Epic Games, Inc. All Rights Reserved.
  3. function log_msg() { #message
  4. if [ ! -z $VERBOSE ]; then
  5. echo $1
  6. fi
  7. }
  8. function print_usage() {
  9. echo "
  10. Usage:
  11. ${0} [--help] [--publicip <IP Address>] [--turn <turn server>] [--stun <stun server>] [cirrus options...]
  12. Where:
  13. --help will print this message and stop this script.
  14. --debug will run all scripts with --inspect
  15. --nosudo will run all scripts without \`sudo\` command useful for when run in containers.
  16. --verbose will enable additional logging
  17. --package-manager <package manager name> specify an alternative package manager to apt-get
  18. "
  19. exit 1
  20. }
  21. function use_args() {
  22. while(($#)) ; do
  23. case "$1" in
  24. --debug ) IS_DEBUG=1; shift;;
  25. --nosudo ) NO_SUDO=1; shift;;
  26. --verbose ) VERBOSE=1; shift;;
  27. --help ) print_usage;;
  28. * ) echo "Unknown command"; shift;;
  29. esac
  30. done
  31. }
  32. function call_setup_sh() {
  33. bash "setup.sh"
  34. }
  35. function start_process() {
  36. if [ ! -z $NO_SUDO ]; then
  37. log_msg "running with sudo removed"
  38. eval $(echo "$@" | sed 's/sudo//g')
  39. else
  40. eval $@
  41. fi
  42. }
  43. function get_version() {
  44. local version=$1
  45. if command -v $version; then
  46. version=$($@)
  47. fi
  48. echo $version | sed -E 's/[^0-9.]//g'
  49. }