Advertisement
adamchilcott

install.sh

Mar 9th, 2019
501
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 9.59 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. unset IFS
  4. export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH"
  5.  
  6. # Prompt user until they type Y/y or N/n
  7. # Calling:
  8. # prompt_yesno
  9. prompt_yesno() {
  10.     local input=""
  11.  
  12.     while true; do
  13.         printf "%s" "(Y/n): "
  14.         read input
  15.  
  16.         if [ "$input" = "" ] || [ "$input" = "Y" ] || [ "$input" = "y" ]; then
  17.             return 0
  18.         fi
  19.  
  20.         if [ "$input" = "N" ] || [ "$input" = "n" ]; then
  21.             return 1
  22.         fi
  23.     done
  24. }
  25.  
  26. if [ "$BASH_VERSION" = "" ]; then
  27.     echo Required bash scripting environment not detected. You are likely running with /bin/sh. Rerun with /bin/bash?
  28.     if prompt_yesno; then /bin/bash "$0"; fi
  29.     exit 0
  30. fi
  31.  
  32. if [ $UID -ne 0 ]; then
  33.     # Clear out any existing credentials so the user always gets a prompt
  34.     sudo -K
  35.     echo "Type your password below to give ScreenConnect permission to install: "
  36.     echo "(You can also Ctrl-C to exit and re-run the script as root)"
  37.     sudo "$0"
  38.     exit 0
  39. fi
  40.  
  41. INSTALL_SCRIPT_PATH="$(dirname "$0")"
  42. INSTALL_DIRECTORY="$INSTALL_SCRIPT_PATH/Installer"
  43. SCREENCONNECT_DIRECTORY="$INSTALL_SCRIPT_PATH/ScreenConnect"
  44. MIN_UPGRADE_VERSION="5.3"
  45.  
  46. source "$INSTALL_DIRECTORY/functions.sh"
  47.  
  48. echo ""
  49. echo "Welcome to the ScreenConnect Installer"
  50. echo ""
  51. echo "The installer will do these things:"
  52. echo "1) Prompt you for installation options"
  53. echo "2) Display a list of actions to be taken"
  54. echo "3) Prompt you for execution of the actions"
  55. echo "4) Execute the actions"
  56.  
  57. find "$INSTALL_DIRECTORY/Distributions" -name "*.sh" -not -name ".*" | sort > /tmp/distros
  58.  
  59. while read distroFile; do
  60.     source "$distroFile"
  61.  
  62.     if is_distro_valid; then
  63.         break;
  64.     fi
  65. done < /tmp/distros
  66.  
  67. rm /tmp/distros
  68.  
  69. demand_system_compatible
  70.  
  71. # This is filled by the base dependencies function (or whatever a script adds in dependency_check()
  72. # It consists of dependencies that need to be addressed in the form dependency:reason
  73. problematic_dependencies=()
  74. # These actions are used by the build_install_actions script
  75. installer_actions=()
  76. installer_action_descriptions=()
  77.  
  78. # Execute the actual dependency check, this will fill problematic_dependencies
  79. dependency_check
  80.  
  81. # Loop through the missing dependencies and build the installer action and description arrays
  82. for i in ${!problematic_dependencies[*]}
  83. do
  84.     # Each element is dependency:reason
  85.     dependency_parts=($(echo "${problematic_dependencies[$i]}"))
  86.     build_dependency_action "${dependency_parts[0]}"
  87.  
  88.     if [ $? == 1 ]; then
  89.         # Return value of 1 means a build action was added, so remove the element from the array
  90.         unset problematic_dependencies[$i]
  91.     fi
  92. done
  93.  
  94. if [ ${#problematic_dependencies[*]} -gt 0 ]; then
  95.     echo ""
  96.     echo "We were unable to resolve these dependencies:"
  97.  
  98.     is_a_dependency_critical=0
  99.  
  100.     for i in ${!problematic_dependencies[*]}
  101.     do
  102.         echo ${problematic_dependencies[$i]}
  103.         (echo ${problematic_dependencies[$i]} | grep "(critical)" > /dev/null) && is_a_dependency_critical=1
  104.     done
  105.  
  106.     if [ $is_a_dependency_critical -eq 1 ]; then
  107.         echo ""
  108.         echo "One or more critical dependencies could not be resolved. Installation cannot continue."
  109.         exit 1
  110.     fi
  111.  
  112.     echo ""
  113.     echo "None of these are required. Would you like to continue?"
  114.  
  115.     if ! prompt_yesno; then
  116.         echo "Exiting due to unresolved dependencies..."
  117.         exit 1
  118.     fi
  119. fi
  120.  
  121. # Prompt user for options
  122. installation_directory="/opt/ScreenConnect"
  123.  
  124. # Let's use the new lower case one unless the old one exists
  125. # OS X's filesystem is case-insensitive, so a simple test -d $installation_directory won't distinguish between /opt/ScreenConnect and /opt/screenconnect
  126. # However, if you make bash do filename expansion, it will distinguish between them
  127. # Surrounding every non-slash character following a slash with [] will result in /opt/ScreenConnect if it does exist and /[o]pt/[S]creenConnect if it doesn't
  128. # The right-hand expression in the test must be unquoted for this wildcard expansion to happen
  129. if [ $installation_directory != $(echo "$installation_directory" | sed 's,/\([^/]\),/[\1],g') ]; then installation_directory="/opt/screenconnect"; fi
  130.  
  131. while true; do
  132.     echo ""
  133.     echo "Where would you like to install ScreenConnect?"
  134.     printf "%s" "[$installation_directory] "
  135.     read input
  136.  
  137.     if [ "$input" == "" ]; then
  138.         break;
  139.     elif [[ "$input" == "/"* ]]; then
  140.         installation_directory=$input
  141.         break;
  142.     else
  143.         echo ""
  144.         echo "Invalid location"
  145.     fi
  146. done
  147.  
  148. installer="`cd "$(dirname $0)"; pwd`/$(basename $0)" # installer full path
  149. if [[ $installer == $installation_directory/* ]]; then
  150.     echo "The ScreenConnect installation directory cannot contain the installer ('$installer'). Please move the installer or choose a different location to install ScreenConnect and rerun this script."
  151.     exit 1
  152. fi
  153.  
  154. is_upgrade=0
  155.  
  156. if test -d "$installation_directory"; then is_upgrade=1; fi
  157.  
  158. if [ $is_upgrade -eq 1 ]; then
  159.     old_version=$(get_product_version "$installation_directory")
  160.  
  161.     if ! is_version_a_gte_version_b "$old_version" "$MIN_UPGRADE_VERSION"; then
  162.         echo ""
  163.         echo "This package only supports upgrading from ScreenConnect $MIN_UPGRADE_VERSION or higher. Your version was detected as ${old_version}. Please upgrade and rerun this package."
  164.         exit 1
  165.     fi
  166.  
  167.     new_version=$(get_product_version "$SCREENCONNECT_DIRECTORY")
  168.  
  169.     if ! is_version_a_gte_version_b "$new_version" "$old_version"; then
  170.         echo ""
  171.         echo "Detected existing installation at version $old_version. Cannot downgrade to $new_version."
  172.         exit 1
  173.     fi
  174.  
  175.     echo ""
  176.     echo "It appears that there is already an installation at $installation_directory ($old_version)"
  177.     echo "Would you like to upgrade?"
  178.  
  179.     if ! prompt_yesno; then
  180.         echo "Installation directory already exists, and you chose not to upgrade it. Please erase the existing installation to perform a fresh install in $installation_directory or rerun this script and choose to upgrade"
  181.         exit 1
  182.     fi
  183. fi
  184.  
  185. # Setup environment because we have to call mono
  186. export PATH=$installation_directory/App_Runtime/bin:$PATH
  187. export MONO_PATH=$installation_directory/App_Runtime/lib
  188. export MONO_CFG_DIR=$installation_directory/App_Runtime/etc
  189.  
  190. # Find init.d or whatever is appropriate for this distro
  191. initialize_startup_directory_information
  192.  
  193. service_name=""
  194.  
  195. # Stop any running services and remove any existing service startup scripts
  196. # (That point to the install folder) if upgrading
  197. # This also gets the service name
  198. if [ $is_upgrade -eq 1 ]; then
  199.     service_names=()
  200.     get_existing_service_names
  201.  
  202.     if [ ${#service_names[*]} -gt 0 ]; then
  203.         for cur_service_name in ${service_names[*]}
  204.         do
  205.             build_stop_and_remove_service_action "$cur_service_name"
  206.         done
  207.  
  208.         service_name=${service_names[0]}
  209.     fi
  210. fi
  211.  
  212. if [ "$service_name" == "" ]; then
  213.     service_name=$(basename "$installation_directory" | tr "[A-Z]" "[a-z]")
  214. fi
  215.  
  216. # Determining name of init.d script / service name
  217. while true; do
  218.     echo ""
  219.     echo "What would you like as the service name for this ScreenConnect installation?"
  220.     printf "%s" "[$service_name] "
  221.     read input
  222.  
  223.     if ! [[ "$input" =~ ^[a-zA-Z0-9_\-]*$ ]]; then
  224.         echo ""
  225.         echo "Service name can only contain letters, numbers, underscores, and hyphens"
  226.     elif [ "$input" != "" ]; then
  227.         service_name=$input
  228.         break
  229.     else
  230.         break
  231.     fi
  232. done
  233.  
  234. backup_mtime_unprefixed_reference_file_name=Core.dll
  235. backup_mtime_leeway_seconds=60
  236.  
  237. # Build up a list of what we need to do
  238. # Back up files if upgrading
  239. if [ $is_upgrade -eq 1 ]; then
  240.     installer_actions[${#installer_actions[*]}]="make_backup"
  241.     installer_action_descriptions[${#installer_action_descriptions[*]}]="Back up the existing configuration"
  242. fi
  243.  
  244. # Run distribution-specific function to add the build actions to do startup scripts
  245. build_startup_actions
  246.  
  247. mono_executable_file_path=$(get_mono_executable_file_path "$INSTALL_DIRECTORY")
  248.  
  249. if [ "$mono_executable_file_path" = "" ]; then
  250.     echo ""
  251.     echo "Could not find a suitable version of runtime executable for your system. This could be due to an unsupported instruction set. This could also be due to wiping of the execute bits during extraction of the tarball when /tmp is mounted with noexec."
  252.     exit 1
  253. fi
  254.  
  255. # Copy installation files
  256. installer_actions[${#installer_actions[*]}]="copy_installation_files"
  257. installer_action_descriptions[${#installer_action_descriptions[*]}]="Copy files into $installation_directory"
  258.  
  259. # Determine configuration for xsl transform
  260. configuration="Release"
  261. if ls "$SCREENCONNECT_DIRECTORY"/Bin/*.mdb &>/dev/null; then
  262.     configuration="Debug"
  263. fi
  264.  
  265. # Restore backed up files if upgrading
  266. if [ $is_upgrade -eq 1 ]; then
  267.     installer_actions[${#installer_actions[*]}]="restore_backup"
  268.     installer_action_descriptions[${#installer_action_descriptions[*]}]="Restore backed up configuration"
  269. fi
  270.  
  271. # Do the transforms
  272. installer_actions[${#installer_actions[*]}]="transform_configuration_files"
  273. installer_action_descriptions[${#installer_action_descriptions[*]}]="Transform configuration files"
  274.  
  275. # Start screenconnect
  276. build_start_service_action
  277.  
  278. # Confirm the what we're going to do
  279. echo ""
  280. echo "The installation will perform the following actions:"
  281.  
  282. for i in ${!installer_action_descriptions[*]}
  283. do
  284.     echo "- ${installer_action_descriptions[i]}"
  285. done
  286.  
  287. echo ""
  288. echo "Do you want to install ScreenConnect?"
  289.  
  290. if prompt_yesno; then
  291.     echo ""
  292.  
  293.     # Do the install
  294.     for i in ${!installer_actions[*]}
  295.     do
  296.         echo "Running '${installer_action_descriptions[i]}'..."
  297.         eval ${installer_actions[i]}
  298.     done
  299.  
  300.     echo ""
  301.     echo "Installation complete!"
  302.     echo ""
  303.     echo "Trying to figure out the best URL for you to use..."
  304.     echo ""
  305.  
  306.     launch_web_page "$(mono "$installation_directory/Bin/ScreenConnect.Service.exe" launch host)"
  307.  
  308.     echo ""
  309.     exit 0
  310. else
  311.     echo "You chose not to install, your system has not been modified."
  312. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement