Ubuntu Pastebin

Paste from federico at Fri, 27 Jan 2017 21:46:36 +0000

Download as text
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
#!/bin/bash
# Copyright (c) 2015 - 2016 DisplayLink (UK) Ltd.

SELF=$0
COREDIR=/opt/displaylink
LOGSDIR=/var/log/displaylink
PRODUCT="DisplayLink Linux Software"
VERSION=1.2.58
ACTION=default

add_udev_rule()
{
  echo "Adding udev rule for DisplayLink DL-3xxx/5xxx devices"
  create_udev_rules_file /etc/udev/rules.d/99-displaylink.rules
  udevadm control -R
  udevadm trigger
}

remove_udev_rule()
{
  rm -f /etc/udev/rules.d/99-displaylink.rules
  udevadm control -R
  udevadm trigger
}

install_module()
{
  TARGZ="$1"
  MODVER="$2"
  ERRORS="$3"

  SRCDIR="/usr/src/evdi-$MODVER"
  mkdir -p "$SRCDIR"
  if ! tar xf $TARGZ -C "$SRCDIR"; then
    echo "Unable to extract $TARGZ" to "$SRCDIR" > $ERRORS
    return 1
  fi

  echo "Registering EVDI kernel module with DKMS"
  dkms add evdi/$MODVER -q
  if [ $? != 0 -a $? != 3 ]; then
    echo "Unable to add evdi/$MODVER to DKMS source tree." > $ERRORS
    return 2
  fi

  echo "Building EVDI kernel module with DKMS"
  dkms build evdi/$MODVER -q
  if [ $? != 0 ]; then
    echo "Failed to build evdi/$MODVER. Consult /var/lib/dkms/evdi/$MODVER/build/make.log for details." > $ERRORS
    return 3
  fi

  echo "Installing EVDI kernel module to kernel tree"
  dkms install evdi/$MODVER -q
  if [ $? != 0 ]; then
    echo "Failed to install evdi/$MODVER to the kernel tree." > $ERRORS
    return 4
  fi

  echo "EVDI kernel module built successfully"
}

remove_module()
{
  MODVER="$1"
  SRCDIR="/usr/src/evdi-$MODVER"
  dkms remove evdi/$MODVER --all -q
  [ -d "$SRCDIR" ] && rm -rf "$SRCDIR"
}

is_64_bit()
{
  [ "$(getconf LONG_BIT)" == "64" ]
}

add_upstart_script()
{
  cat > /etc/init/dlm.conf <<'EOF'
description "DisplayLink Manager Service"
# Copyright (c) 2015 - 2016 DisplayLink (UK) Ltd.

start on login-session-start
stop on desktop-shutdown

# Restart if process crashes
respawn

# Only attempt to respawn 10 times in 5 seconds
respawn limit 10 5

chdir /opt/displaylink

pre-start script
    . /opt/displaylink/udev.sh

    if [ "$(get_displaylink_dev_count)" = "0" ]; then
        stop
        exit 0
    fi
end script

script
    [ -r /etc/default/displaylink ] && . /etc/default/displaylink
    modprobe evdi
    exec /opt/displaylink/DisplayLinkManager
end script
EOF

  chmod 0644 /etc/init/dlm.conf
}

add_systemd_service()
{
  cat > /lib/systemd/system/dlm.service <<'EOF'
[Unit]
Description=DisplayLink Manager Service
After=display-manager.service
Conflicts=getty@tty7.service

[Service]
ExecStartPre=/sbin/modprobe evdi
ExecStart=/opt/displaylink/DisplayLinkManager
Restart=always
WorkingDirectory=/opt/displaylink
RestartSec=5

EOF

  chmod 0644 /lib/systemd/system/dlm.service
  systemctl enable dlm.service
}

remove_upstart_script()
{
  rm -f /etc/init/dlm.conf
}

remove_systemd_service()
{
  systemctl disable dlm.service
  rm -f /lib/systemd/system/dlm.service
}

add_pm_script()
{
  cat > $COREDIR/suspend.sh <<EOF
#!/bin/bash
# Copyright (c) 2015 - 2016 DisplayLink (UK) Ltd.

suspend_dlm()
{
  #flush any bytes in pipe
  while read -n 1 -t 1 SUSPEND_RESULT < /tmp/PmMessagesPort_out; do : ; done;

  #suspend DisplayLinkManager
  echo "S" > /tmp/PmMessagesPort_in

  if [ -f /tmp/PmMessagesPort_out ]; then
    #wait until suspend of DisplayLinkManager finish
    read -n 1 -t 10 SUSPEND_RESULT < /tmp/PmMessagesPort_out
  fi
}

resume_dlm()
{
  #resume DisplayLinkManager
  echo "R" > /tmp/PmMessagesPort_in
}

EOF

  if [ "$1" = "upstart" ]
  then
    cat >> $COREDIR/suspend.sh <<EOF
case "\$1" in
  thaw)
    resume_dlm
    ;;
  hibernate)
    suspend_dlm
    ;;
  suspend)
    suspend_dlm
    ;;
  resume)
    resume_dlm
    ;;
esac

EOF
  elif [ "$1" = "systemd" ]
  then
    cat >> $COREDIR/suspend.sh <<EOF
case "\$1/\$2" in
  pre/*)
    suspend_dlm
    ;;
  post/*)
    resume_dlm
    ;;
esac

EOF
  fi

  chmod 0755 $COREDIR/suspend.sh
  if [ "$1" = "upstart" ]
  then
    ln -s $COREDIR/suspend.sh /etc/pm/sleep.d/displaylink.sh
  elif [ "$1" = "systemd" ]
  then
    ln -s $COREDIR/suspend.sh /lib/systemd/system-sleep/displaylink.sh
  fi
}

remove_pm_scripts()
{
  rm -f /etc/pm/sleep.d/displaylink.sh
  rm -f /lib/systemd/system-sleep/displaylink.sh
}

cleanup()
{
  rm -rf $COREDIR
  rm -rf $LOGSDIR
  rm -f /usr/bin/displaylink-installer
  rm -f ~/.dl.xml
  rm -f /root/.dl.xml
}

install()
{
  echo "Installing"
  mkdir -p $COREDIR
  mkdir -p $LOGSDIR
  chmod 0755 $COREDIR
  chmod 0755 $LOGSDIR

  cp -f $SELF $COREDIR
  ln -sf "$COREDIR/$(basename $SELF)" /usr/bin/displaylink-installer

  local ERRORS=$(mktemp)
  echo "Configuring EVDI DKMS module"
  install_module "evdi-$VERSION-src.tar.gz" "$VERSION" "$ERRORS"
  local success=$?

  local error="$(< $ERRORS)"
  rm -f $ERRORS
  if [ 0 -ne $success ]; then
    echo "ERROR (code $success): $error." >&2
    cleanup
    exit 1
  fi

  is_64_bit && ARCH="x64" || ARCH="x86"
  local UBULONGREL=`lsb_release -r`
  [[ $UBULONGREL =~ "16.04" ]] && UBUREL="ubuntu-1604" || UBUREL="ubuntu-1404"
  local DLM="$ARCH-$UBUREL/DisplayLinkManager"
  echo "Installing $DLM"
  [ -x $DLM ] && mv -f $DLM $COREDIR

  echo "Installing libraries"
  local LIBEVDI="$ARCH-$UBUREL/libevdi.so"
  local LIBUSB="$ARCH-$UBUREL/libusb-1.0.so.0.1.0"

  [ -f $LIBEVDI ] && mv -f $LIBEVDI $COREDIR
  [ -f $LIBUSB ] && mv -f $LIBUSB $COREDIR
  ln -sf $COREDIR/libusb-1.0.so.0.1.0 $COREDIR/libusb-1.0.so.0
  ln -sf $COREDIR/libusb-1.0.so.0.1.0 $COREDIR/libusb-1.0.so

  chmod 0755 $COREDIR/DisplayLinkManager
  chmod 0755 $COREDIR/libevdi.so
  chmod 0755 $COREDIR/libusb*.so*

  echo "Installing firmware packages"
  mv -f *.spkg $COREDIR
  chmod 0644 $COREDIR/*.spkg

  echo "Installing license file"
  mv -f LICENSE $COREDIR
  chmod 0644 $COREDIR/LICENSE

  source udev-installer.sh
  displaylink_bootstrap_script=$COREDIR/udev.sh
  create_bootstrap_file $SYSTEMINITDAEMON $displaylink_bootstrap_script
  add_udev_rule

  if [ "upstart" == "$SYSTEMINITDAEMON" ]; then
    add_upstart_script
    add_pm_script "upstart"
  elif [ "systemd" == "$SYSTEMINITDAEMON" ]; then
    add_systemd_service
    add_pm_script "systemd"
  fi
  $displaylink_bootstrap_script START
}

uninstall()
{
  echo "Uninstalling"

  echo "Removing EVDI from kernel tree, DKMS, and removing sources."
  remove_module $VERSION

  if [ "upstart" == "$SYSTEMINITDAEMON" ]; then
    echo "Stopping DLM upstart job"
    stop dlm
    remove_upstart_script
  elif [ "systemd" == "$SYSTEMINITDAEMON" ]; then
    echo "Stopping DLM systemd service"
    systemctl stop dlm.service
    remove_systemd_service
  fi

  echo "Removing suspend-resume hooks"
  remove_pm_scripts

  echo "Removing udev rule"
  remove_udev_rule

  echo "Removing Core folder"
  cleanup

  echo -e "\nUninstallation steps complete."
  if [ -f /sys/devices/evdi/version ]; then
    echo "Please note that the evdi kernel module is still in the memory."
    echo "A reboot is required to fully complete the uninstallation process."
  fi
}

missing_requirement()
{
  echo "Unsatisfied dependencies. Missing component: $1." >&2
  echo "This is a fatal error, cannot install $PRODUCT." >&2
  exit 1
}

version_lt()
{
  local left=$(echo $1 | cut -d. -f-2)
  local right=$(echo $2 | cut -d. -f-2)
  local greater=$(echo -e "$left\n$right" | sort -Vr | head -1)
  [ "$greater" != "$left" ] && return $true
  return $false
}

check_requirements()
{
  # DKMS
  which dkms >/dev/null || missing_requirement "DKMS"

  # Required kernel version
  KVER=$(uname -r)
  KVER_MIN="3.14"
  version_lt "$KVER" "$KVER_MIN" && missing_requirement "Kernel version $KVER is too old. At least $KVER_MIN is required"

  # Linux headers
  [ ! -f "/lib/modules/$KVER/build/Kconfig" ] && missing_requirement "Linux headers for running kernel, $KVER"
}

usage()
{
  echo
  echo "Installs $PRODUCT, version $VERSION."
  echo "Usage: $SELF [ install | uninstall ]"
  echo
  echo "If no argument is given, a quick compatibility check is performed but nothing is installed."
  exit 1
}

detect_init_daemon()
{
    INIT=$(readlink /proc/1/exe)
    if [ "$INIT" == "/sbin/init" ]; then
        INIT=$(/sbin/init --version)
    fi

    [ -z "${INIT##*upstart*}" ] && SYSTEMINITDAEMON="upstart"
    [ -z "${INIT##*systemd*}" ] && SYSTEMINITDAEMON="systemd"

    if [ -z "$SYSTEMINITDAEMON" ]; then
        echo "ERROR: the installer script is unable to find out how to start DisplayLinkManager service automatically on your system." >&2
        echo "Please set an environment variable SYSTEMINITDAEMON to 'upstart' or 'systemd' before running the installation script to force one of the options." >&2
        echo "Installation terminated." >&2
        exit 1
    fi
}

detect_distro()
{
  if which lsb_release >/dev/null; then
    local R=$(lsb_release -d -s)
    echo "Distribution discovered: $R"
    [ -z "${R##Ubuntu 14.*}" ] && return
    [ -z "${R##Ubuntu 15.*}" ] && return
    [ -z "${R##Ubuntu 16.04*}" ] && return
  else
    echo "WARNING: This is not an officially supported distribution." >&2
    echo "Please use DisplayLink Forum for getting help if you find issues." >&2
  fi
}

ensure_not_running()
{
  if [ -f /sys/devices/evdi/version ]; then
    local V=$(< /sys/devices/evdi/version)
    echo "WARNING: Version $V of EVDI kernel module is already running." >&2
    if [ -d $COREDIR ]; then
      echo "Please uninstall all other versions of $PRODUCT before attempting to install." >&2
    else
      echo "Please reboot before attempting to re-install $PRODUCT." >&2
    fi
    echo "Installation terminated." >&2
    exit 1
  fi
}

if [ $(id -u) != 0 ]; then
  echo "You need to be root to use this script." >&2
  exit 1
fi

echo "$PRODUCT $VERSION install script called: $*"
[ -z "$SYSTEMINITDAEMON" ] && detect_init_daemon || echo "Trying to use the forced init system: $SYSTEMINITDAEMON"
detect_distro
check_requirements

while [ -n "$1" ]; do
  case "$1" in
    install)
      ACTION="install"
      ;;

    uninstall)
      ACTION="uninstall"
      ;;
    *)
      usage
      ;;
  esac
  shift
done

if [ "$ACTION" == "install" ]; then
  ensure_not_running
  install
elif [ "$ACTION" == "uninstall" ]; then
  uninstall
fi
Download as text