Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | INST_ARCH=$(uname -m | sed -e "s/i[3-6]86/ix86/" -e "s/x86[-_]64/x86_64/") |
| 4 | SDK_ARCH=$(echo @SDK_ARCH@ | sed -e "s/i[3-6]86/ix86/" -e "s/x86[-_]64/x86_64/") |
| 5 | |
| 6 | verlte () { |
| 7 | [ "$1" = "`printf "$1\n$2" | sort -V | head -n1`" ] |
| 8 | } |
| 9 | |
| 10 | verlt() { |
| 11 | [ "$1" = "$2" ] && return 1 || verlte $1 $2 |
| 12 | } |
| 13 | |
| 14 | verlt `uname -r` @OLDEST_KERNEL@ |
| 15 | if [ $? = 0 ]; then |
| 16 | echo "Error: The SDK needs a kernel > @OLDEST_KERNEL@" |
| 17 | exit 1 |
| 18 | fi |
| 19 | |
| 20 | if [ "$INST_ARCH" != "$SDK_ARCH" ]; then |
| 21 | # Allow for installation of ix86 SDK on x86_64 host |
| 22 | if [ "$INST_ARCH" != x86_64 -o "$SDK_ARCH" != ix86 ]; then |
| 23 | echo "Error: Installation machine not supported!" |
| 24 | exit 1 |
| 25 | fi |
| 26 | fi |
| 27 | |
| 28 | DEFAULT_INSTALL_DIR="@SDKPATH@" |
| 29 | SUDO_EXEC="" |
| 30 | target_sdk_dir="" |
| 31 | answer="" |
| 32 | relocate=1 |
| 33 | savescripts=0 |
| 34 | verbose=0 |
| 35 | while getopts ":yd:nDRS" OPT; do |
| 36 | case $OPT in |
| 37 | y) |
| 38 | answer="Y" |
| 39 | ;; |
| 40 | d) |
| 41 | target_sdk_dir=$OPTARG |
| 42 | ;; |
| 43 | n) |
| 44 | prepare_buildsystem="no" |
| 45 | ;; |
| 46 | D) |
| 47 | verbose=1 |
| 48 | ;; |
| 49 | R) |
| 50 | relocate=0 |
| 51 | savescripts=1 |
| 52 | ;; |
| 53 | S) |
| 54 | savescripts=1 |
| 55 | ;; |
| 56 | *) |
| 57 | echo "Usage: $(basename $0) [-y] [-d <dir>]" |
| 58 | echo " -y Automatic yes to all prompts" |
| 59 | echo " -d <dir> Install the SDK to <dir>" |
| 60 | echo "======== Extensible SDK only options ============" |
| 61 | echo " -n Do not prepare the build system" |
| 62 | echo "======== Advanced DEBUGGING ONLY OPTIONS ========" |
| 63 | echo " -S Save relocation scripts" |
| 64 | echo " -R Do not relocate executables" |
| 65 | echo " -D use set -x to see what is going on" |
| 66 | exit 1 |
| 67 | ;; |
| 68 | esac |
| 69 | done |
| 70 | |
| 71 | echo "@SDK_TITLE@ installer version @SDK_VERSION@" |
| 72 | echo "===========================================================" |
| 73 | |
| 74 | if [ $verbose = 1 ] ; then |
| 75 | set -x |
| 76 | fi |
| 77 | |
| 78 | @SDK_PRE_INSTALL_COMMAND@ |
| 79 | |
| 80 | # SDK_EXTENSIBLE is exposed from the SDK_PRE_INSTALL_COMMAND above |
| 81 | if [ "$SDK_EXTENSIBLE" = "1" ]; then |
| 82 | DEFAULT_INSTALL_DIR="@SDKEXTPATH@" |
| 83 | fi |
| 84 | |
| 85 | if [ "$target_sdk_dir" = "" ]; then |
| 86 | if [ "$answer" = "Y" ]; then |
| 87 | target_sdk_dir="$DEFAULT_INSTALL_DIR" |
| 88 | else |
| 89 | read -e -p "Enter target directory for SDK (default: $DEFAULT_INSTALL_DIR): " target_sdk_dir |
| 90 | [ "$target_sdk_dir" = "" ] && target_sdk_dir=$DEFAULT_INSTALL_DIR |
| 91 | fi |
| 92 | fi |
| 93 | |
| 94 | eval target_sdk_dir=$(echo "$target_sdk_dir"|sed 's/ /\\ /g') |
| 95 | if [ -d "$target_sdk_dir" ]; then |
| 96 | target_sdk_dir=$(cd "$target_sdk_dir"; pwd) |
| 97 | else |
| 98 | target_sdk_dir=$(readlink -m "$target_sdk_dir") |
| 99 | fi |
| 100 | |
| 101 | if [ "$SDK_EXTENSIBLE" = "1" ]; then |
| 102 | # We're going to be running the build system, additional restrictions apply |
| 103 | if echo "$target_sdk_dir" | grep -q '[+\ @]'; then |
| 104 | echo "The target directory path ($target_sdk_dir) contains illegal" \ |
| 105 | "characters such as spaces, @ or +. Abort!" |
| 106 | exit 1 |
| 107 | fi |
| 108 | else |
| 109 | if [ -n "$(echo $target_sdk_dir|grep ' ')" ]; then |
| 110 | echo "The target directory path ($target_sdk_dir) contains spaces. Abort!" |
| 111 | exit 1 |
| 112 | fi |
| 113 | fi |
| 114 | |
| 115 | if [ -e "$target_sdk_dir/environment-setup-@REAL_MULTIMACH_TARGET_SYS@" ]; then |
| 116 | echo "The directory \"$target_sdk_dir\" already contains a SDK for this architecture." |
| 117 | printf "If you continue, existing files will be overwritten! Proceed[y/N]? " |
| 118 | |
| 119 | default_answer="n" |
| 120 | else |
| 121 | printf "You are about to install the SDK to \"$target_sdk_dir\". Proceed[Y/n]? " |
| 122 | |
| 123 | default_answer="y" |
| 124 | fi |
| 125 | |
| 126 | if [ "$answer" = "" ]; then |
| 127 | read answer |
| 128 | [ "$answer" = "" ] && answer="$default_answer" |
| 129 | else |
| 130 | echo $answer |
| 131 | fi |
| 132 | |
| 133 | if [ "$answer" != "Y" -a "$answer" != "y" ]; then |
| 134 | echo "Installation aborted!" |
| 135 | exit 1 |
| 136 | fi |
| 137 | |
| 138 | # Try to create the directory (this will not succeed if user doesn't have rights) |
| 139 | mkdir -p $target_sdk_dir >/dev/null 2>&1 |
| 140 | |
| 141 | # if don't have the right to access dir, gain by sudo |
| 142 | if [ ! -x $target_sdk_dir -o ! -w $target_sdk_dir -o ! -r $target_sdk_dir ]; then |
| 143 | if [ "$SDK_EXTENSIBLE" = "1" ]; then |
| 144 | echo "Unable to access \"$target_sdk_dir\", will not attempt to use" \ |
| 145 | "sudo as as extensible SDK cannot be used as root." |
| 146 | exit 1 |
| 147 | fi |
| 148 | |
| 149 | SUDO_EXEC=$(which "sudo") |
| 150 | if [ -z $SUDO_EXEC ]; then |
| 151 | echo "No command 'sudo' found, please install sudo first. Abort!" |
| 152 | exit 1 |
| 153 | fi |
| 154 | |
| 155 | # test sudo could gain root right |
| 156 | $SUDO_EXEC pwd >/dev/null 2>&1 |
| 157 | [ $? -ne 0 ] && echo "Sorry, you are not allowed to execute as root." && exit 1 |
| 158 | |
| 159 | # now that we have sudo rights, create the directory |
| 160 | $SUDO_EXEC mkdir -p $target_sdk_dir >/dev/null 2>&1 |
| 161 | fi |
| 162 | |
| 163 | payload_offset=$(($(grep -na -m1 "^MARKER:$" $0|cut -d':' -f1) + 1)) |
| 164 | |
| 165 | printf "Extracting SDK..." |
| 166 | tail -n +$payload_offset $0| $SUDO_EXEC tar xj -C $target_sdk_dir |
| 167 | echo "done" |
| 168 | |
| 169 | printf "Setting it up..." |
| 170 | # fix environment paths |
| 171 | for env_setup_script in `ls $target_sdk_dir/environment-setup-*`; do |
| 172 | $SUDO_EXEC sed -e "s:@SDKPATH@:$target_sdk_dir:g" -i $env_setup_script |
| 173 | done |
| 174 | |
| 175 | @SDK_POST_INSTALL_COMMAND@ |
| 176 | |
| 177 | # delete the relocating script, so that user is forced to re-run the installer |
| 178 | # if he/she wants another location for the sdk |
| 179 | if [ $savescripts = 0 ] ; then |
| 180 | $SUDO_EXEC rm -f ${env_setup_script%/*}/relocate_sdk.py ${env_setup_script%/*}/relocate_sdk.sh |
| 181 | fi |
| 182 | |
| 183 | echo "SDK has been successfully set up and is ready to be used." |
| 184 | echo "Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g." |
| 185 | echo " \$ . $target_sdk_dir/environment-setup-@REAL_MULTIMACH_TARGET_SYS@" |
| 186 | |
| 187 | exit 0 |
| 188 | |
| 189 | MARKER: |