|
| 1 | +#!/usr/bin/python |
| 2 | +""" |
| 3 | +
|
| 4 | +Copyright (c) 2018 Intel Corporation All Rights Reserved. |
| 5 | +
|
| 6 | +THESE MATERIALS ARE PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 7 | +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 8 | +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 9 | +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS |
| 10 | +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 11 | +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 12 | +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 13 | +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 14 | +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING |
| 15 | +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THESE |
| 16 | +MATERIALS, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 17 | +
|
| 18 | +File Name: msdk_pre_install.py |
| 19 | +
|
| 20 | +Abstract: Complete install for Intel Visual Analytics, including |
| 21 | + * Intel(R) Media SDK |
| 22 | + * Intel(R) Media driver |
| 23 | + * Libva |
| 24 | + * Drivers |
| 25 | + * Prerequisites |
| 26 | +""" |
| 27 | + |
| 28 | +import os, sys, platform |
| 29 | +import os.path |
| 30 | +import argparse |
| 31 | +import subprocess |
| 32 | +import grp |
| 33 | + |
| 34 | +class diagnostic_colors: |
| 35 | + ERROR = '\x1b[31;1m' # Red/bold |
| 36 | + SUCCESS = '\x1b[32;1m' # green/bold |
| 37 | + RESET = '\x1b[0m' # Reset attributes |
| 38 | + INFO = '\x1b[34;1m' # info |
| 39 | + OUTPUT = '' # command's coutput printing |
| 40 | + STDERR = '\x1b[36;1m' # cyan/bold |
| 41 | + SKIPPED = '\x1b[33;1m' # yellow/bold |
| 42 | + |
| 43 | +class loglevelcode: |
| 44 | + ERROR = 0 |
| 45 | + SUCCESS = 1 |
| 46 | + INFO = 2 |
| 47 | + |
| 48 | +GLOBAL_LOGLEVEL=3 |
| 49 | + |
| 50 | +def print_info( msg, loglevel ): |
| 51 | + global GLOBAL_LOGLEVEL |
| 52 | + |
| 53 | + """ printing information """ |
| 54 | + |
| 55 | + if loglevel==loglevelcode.ERROR and GLOBAL_LOGLEVEL>=0: |
| 56 | + color = diagnostic_colors.ERROR |
| 57 | + msgtype=" [ ERROR ] " |
| 58 | + print( color + msgtype + diagnostic_colors.RESET + msg ) |
| 59 | + elif loglevel==loglevelcode.SUCCESS and GLOBAL_LOGLEVEL>=1: |
| 60 | + color = diagnostic_colors.SUCCESS |
| 61 | + msgtype=" [ OK ] " |
| 62 | + print( color + msgtype + diagnostic_colors.RESET + msg ) |
| 63 | + elif loglevel==loglevelcode.INFO and GLOBAL_LOGLEVEL>=2: |
| 64 | + color = diagnostic_colors.INFO |
| 65 | + msgtype=" [ INFO ] " |
| 66 | + print( color + msgtype + diagnostic_colors.RESET + msg ) |
| 67 | + return |
| 68 | + |
| 69 | +def run_cmd(cmd): |
| 70 | + output="" |
| 71 | + fin=os.popen(cmd+" 2>&1","r") |
| 72 | + for line in fin: |
| 73 | + output+=line |
| 74 | + fin.close() |
| 75 | + return output |
| 76 | + |
| 77 | +def fnParseCommandline(): |
| 78 | + if len(sys.argv) == 1: |
| 79 | + return "-all" |
| 80 | + elif len(sys.argv) > 3: |
| 81 | + return "not support" |
| 82 | + exit(0) |
| 83 | + |
| 84 | + if sys.argv[1] == "-h": |
| 85 | + print "[%s" % sys.argv[0] + " usage]" |
| 86 | + print "\t -h: display help" |
| 87 | + print "\t -all: install all components" |
| 88 | + print "\t -b BUILD_TARGET: build all components" |
| 89 | + print "\t -m : build msdk only" |
| 90 | + |
| 91 | + exit(0) |
| 92 | + |
| 93 | + return sys.argv[1] |
| 94 | + |
| 95 | +if __name__ == "__main__": |
| 96 | + |
| 97 | + WORKING_DIR=run_cmd("pwd").strip() |
| 98 | + msg_tmp = "Working directory: " + WORKING_DIR |
| 99 | + print_info(msg_tmp, loglevelcode.INFO) |
| 100 | + |
| 101 | + BUILD_TARGET="" |
| 102 | + build_msdk = False |
| 103 | + build_all = False |
| 104 | + |
| 105 | + cmd = fnParseCommandline() |
| 106 | + |
| 107 | + if cmd == "-b": |
| 108 | + BUILD_TARGET=sys.argv[2] |
| 109 | + build_all = True |
| 110 | + pre_install = False |
| 111 | + print "BUILD_TARGET=", BUILD_TARGET |
| 112 | + elif cmd == "-m": |
| 113 | + print_info("Build MSDK", loglevelcode.INFO) |
| 114 | + build_msdk = True |
| 115 | + pre_install = False |
| 116 | + else: |
| 117 | + pre_install = True |
| 118 | + |
| 119 | + |
| 120 | + if pre_install == True: |
| 121 | + print "" |
| 122 | + print "************************************************************************" |
| 123 | + print_info("Install required tools and create build environment.", loglevelcode.INFO) |
| 124 | + print "************************************************************************" |
| 125 | + |
| 126 | + # Install the necessary tools |
| 127 | + |
| 128 | + print "Please input the sudo password to proceed\n" |
| 129 | + cmd ="sudo apt-get -y install git libssl-dev dh-autoreconf cmake libgl1-mesa-dev libpciaccess-dev build-essential curl imagemagick unzip yasm libjpeg-dev libavcodec-dev libavutil-dev libavformat-dev;" |
| 130 | + cmd+="sudo apt-get -y install libopencv-dev checkinstall pkg-config libgflags-dev" |
| 131 | + os.system(cmd) |
| 132 | + |
| 133 | + print "" |
| 134 | + print "************************************************************************" |
| 135 | + print_info("Pull all the source code.", loglevelcode.INFO) |
| 136 | + print "************************************************************************" |
| 137 | + |
| 138 | + # Pull all the source code |
| 139 | + print "libva" |
| 140 | + if not os.path.exists("%s/libva"%(WORKING_DIR)): |
| 141 | + cmd = "cd %s; git clone https://github.com/intel/libva.git;"%(WORKING_DIR) |
| 142 | + cmd+= "cd libva;" |
| 143 | + cmd+="git checkout 5f693d9e603e0e83928cec67c30b6ac902d7aa85;" # 04/12/18 |
| 144 | + print cmd |
| 145 | + os.system(cmd); |
| 146 | + |
| 147 | + print "libva-utils" |
| 148 | + if not os.path.exists("%s/libva-utils"%(WORKING_DIR)): |
| 149 | + cmd = "cd %s; git clone https://github.com/intel/libva-utils.git;"%(WORKING_DIR) |
| 150 | + cmd += "cd libva-utils;" |
| 151 | + cmd+="git checkout 8ea1eba433dcbceb0e5dcb54b8e3f984987f7a17; " # 03/20/18 |
| 152 | + print cmd |
| 153 | + os.system(cmd); |
| 154 | + |
| 155 | + print "media-driver" |
| 156 | + if not os.path.exists("%s/media-driver"%(WORKING_DIR)): |
| 157 | + cmd = "cd %s; git clone https://github.com/intel/media-driver.git; "%(WORKING_DIR) |
| 158 | + cmd += "cd media-driver;" |
| 159 | + cmd+= "git checkout 12b7fcded6c74377ecf57eb8258f5e3d55ca722e" # 04/16/18 |
| 160 | + print cmd |
| 161 | + os.system(cmd); |
| 162 | + |
| 163 | + print "gmmlib" |
| 164 | + if not os.path.exists("%s/gmmlib"%(WORKING_DIR)): |
| 165 | + cmd = "cd %s; git clone https://github.com/intel/gmmlib.git; "%(WORKING_DIR) |
| 166 | + cmd += "cd gmmlib;" |
| 167 | + cmd+= "git checkout ebfcfd565031dbd7b45089d9054cd44a501f14a9" # 04/05/18 |
| 168 | + print cmd |
| 169 | + os.system(cmd); |
| 170 | + |
| 171 | + print "MediaSDK" |
| 172 | + if not os.path.exists("%s/MediaSDK"%(WORKING_DIR)): |
| 173 | + cmd = "cd %s; git clone https://github.com/Intel-Media-SDK/MediaSDK.git; "%(WORKING_DIR) |
| 174 | + cmd+= "cd MediaSDK;" |
| 175 | + cmd+= "git checkout f8f6646afcaec410ca037f0176814dd9d7ca4900" # 04/16/18 |
| 176 | + print cmd |
| 177 | + os.system(cmd); |
| 178 | + |
| 179 | + |
| 180 | + if build_all == True: |
| 181 | + print "" |
| 182 | + print "************************************************************************" |
| 183 | + print_info("Build and Install libVA", loglevelcode.INFO) |
| 184 | + print "************************************************************************" |
| 185 | + |
| 186 | + # Build and install libVA including the libVA utils for vainfo. |
| 187 | + # libVA origin:fbf7138389f7d6adb6ca743d0ddf2dbc232895f6 (011118), libVA utils origin: 7b85ff442d99c233fb901a6fe3407d5308971645 (011118) |
| 188 | + cmd ="cd %s/libva; "%(WORKING_DIR) |
| 189 | + cmd+="./autogen.sh --prefix=/usr --libdir=/usr/lib/x86_64-linux-gnu; make -j4; sudo make install" |
| 190 | + print cmd |
| 191 | + os.system(cmd) |
| 192 | + |
| 193 | + cmd ="cd %s/libva-utils; "%(WORKING_DIR) |
| 194 | + cmd+="./autogen.sh --prefix=/usr --libdir=/usr/lib/x86_64-linux-gnu; make -j4; sudo make install" |
| 195 | + print cmd |
| 196 | + os.system(cmd) |
| 197 | + |
| 198 | + print "" |
| 199 | + print "************************************************************************" |
| 200 | + print_info("Build and Install media driver", loglevelcode.INFO) |
| 201 | + print "************************************************************************" |
| 202 | + |
| 203 | + # Build and install media driver |
| 204 | + cmd = "mkdir -p %s/gmmlib/build; "%(WORKING_DIR) |
| 205 | + cmd+= "cd %s/gmmlib/build; "%(WORKING_DIR) |
| 206 | + cmd+= "cmake ../;" |
| 207 | + cmd+= "make -j4;" |
| 208 | + cmd+= "sudo make install;" |
| 209 | + print cmd |
| 210 | + os.system(cmd) |
| 211 | + |
| 212 | + cmd = "mkdir -p %s/media-driver/build; "%(WORKING_DIR) |
| 213 | + cmd+= "cd %s/media-driver/build; "%(WORKING_DIR) |
| 214 | + cmd+= "cmake ../; " |
| 215 | + cmd+= "make -j4; sudo make install" |
| 216 | + print cmd |
| 217 | + os.system(cmd) |
| 218 | + |
| 219 | + if build_all == True or build_msdk == True: |
| 220 | + print "" |
| 221 | + print "************************************************************************" |
| 222 | + print_info("Build and Install Media SDK and samples", loglevelcode.INFO) |
| 223 | + print "************************************************************************" |
| 224 | + |
| 225 | + if not os.path.exists("%s/MediaSDK"%(WORKING_DIR)): |
| 226 | + print "MediaSDK source code doen't exist!" |
| 227 | + sys.exit() |
| 228 | + |
| 229 | + # Build and install Media SDK library and samples |
| 230 | + # MediaSDK origin: 22dae397ae17d29b4734adb0e5a998f32a9c25b2 (022218) |
| 231 | + cmd ="cd %s/MediaSDK; "%(WORKING_DIR) |
| 232 | + cmd+="mkdir -p build; " |
| 233 | + cmd+="cd build; " |
| 234 | + cmd+="cmake ../; " |
| 235 | + cmd+="make -j4; " |
| 236 | + cmd+="sudo make install; " |
| 237 | + print cmd |
| 238 | + os.system(cmd) |
| 239 | + |
| 240 | + if pre_install == True: |
| 241 | + |
| 242 | + if not os.path.exists("%s/MediaSDK"%(WORKING_DIR)): |
| 243 | + print "MediaSDK source code doen't exist!" |
| 244 | + sys.exit() |
| 245 | + |
| 246 | + r=subprocess.check_output("grep -c \"export LIBVA_DRIVER_NAME=iHD\" ~/.bashrc", shell=True) |
| 247 | + |
| 248 | + if r >= 1: |
| 249 | + sys.exit() |
| 250 | + |
| 251 | + print "" |
| 252 | + print "************************************************************************" |
| 253 | + print_info("Set environment variables. ", loglevelcode.INFO) |
| 254 | + print "************************************************************************" |
| 255 | + cmd = "echo 'export MFX_HOME=/opt/intel/mediasdk' >> ~/.bashrc; " |
| 256 | + cmd+= "echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu:/usr/lib' >> ~/.bashrc; " |
| 257 | + cmd+= "echo 'export LIBVA_DRIVERS_PATH=/usr/lib/x86_64-linux-gnu/dri' >> ~/.bashrc; " |
| 258 | + cmd+= "echo 'export LIBVA_DRIVER_NAME=iHD' >> ~/.bashrc" |
| 259 | + print cmd |
| 260 | + os.system(cmd) |
| 261 | + |
| 262 | + cmd = "sudo echo '/usr/lib/x86_64-linux-gnu' > /etc/ld.so.conf.d/libdrm-intel.conf; " |
| 263 | + cmd+= "sudo echo '/usr/lib' >> /etc/ld.so.conf.d/libdrm-intel.conf; " |
| 264 | + cmd+= "sudo ldconfig" |
| 265 | + print cmd |
| 266 | + os.system(cmd) |
| 267 | + |
| 268 | + print "************************************************************************" |
| 269 | + print " Done, all installation, please reboot system !!! " |
| 270 | + print "************************************************************************" |
| 271 | + |
0 commit comments