Dwarf-Therapist icon indicating copy to clipboard operation
Dwarf-Therapist copied to clipboard

Better Launcher Script

Open orbisvicis opened this issue 11 years ago • 2 comments

Idea from https://bugs.launchpad.net/getdeb.net/+bug/1332894 Something like (untested): edit: support dfhack

#!/usr/bin/env bash

dt_data="/usr/share/dwarftherapist"
dt_bin="/usr/bin/DwarfTherapist"
dt_getcap="cap_sys_ptrace=pie"
ptrace_scope="/proc/sys/kernel/yama/ptrace_scope"
root_programs=( kdesudo gksudo sudo )

for name in "${root_programs[@]}"; do
  if root="$(type -P "$name" &>/dev/null)"; then
    break;
  fi
done

if [[ -f "$ptrace_scope" ]] && (("$(cat "$ptrace_scope")" == 1 )); then
  ptrace_protection=true
else
  ptrace_protection=false
fi

if type -P setcap &>/dev/null && setcap -v "$dt_getcap" "$dt_bin" &>/dev/null; then
  dt_setcap=true
else
  dt_setcap=false
fi

cd "$dt_data"

if (($# == 1)) && [[ -x "$1" ]]; then
  "$1" <&0 &
  exec "$dt_bin" &>/dev/null
fi

if $ptrace_protection && ! $dt_setcap; then
  if [[ -n "$root" ]]; then
    $root "$dt_bin"
  else
    printf "Error: %s\n" "Unable to gain root privileges" >&2
    exit 1
  fi
else
  "$dt_bin"
fi;

orbisvicis avatar Jun 22 '14 17:06 orbisvicis

bleh, why don't you just exec DwarfTherapist instead of playing around with the capabilities.

or even better, get DT to exec DF (possibly via command-line option to specify path)

Hello71 avatar Aug 03 '14 14:08 Hello71

... just exec DwarfTherapist instead of playing around with the capabilities

That is exactly what this script does, and no capabilities are being set (only tested).

or even better, get DT to exec DF

This wrapper doesn't provide new functionality iirc; rather it works around edge cases unsupported in the original.

orbisvicis avatar Oct 04 '14 06:10 orbisvicis