splintermind / Dwarf-Therapist

Maintained branch of the original Dwarf Therapist for Dwarf Fortress.
Other
404 stars 71 forks source link

Better Launcher Script #20

Open orbisvicis opened 10 years ago

orbisvicis commented 10 years ago

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;
Hello71 commented 10 years ago

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)

orbisvicis commented 10 years ago

... 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.