Advertisement
Guest User

KSP Linux Launch Script

a guest
Sep 18th, 2016
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.50 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. WINWIDTH=1919
  4. WINHEIGHT=1069
  5. BINARY=KSP.x86_64
  6.  
  7. # change dir to script location
  8. cd "$(dirname "$(readlink -f "$0")")"
  9.  
  10. printf "Still can not learn locales while reading settings? setting LC_ALL=C\n"
  11. LANG=C
  12. LC_ALL=C
  13. export LC_ALL
  14. export LANG
  15. unset LANGUAGE
  16.  
  17. printf "Fixing weird permissions from game archive.\n"
  18. find . -type f -exec chmod 644 "{}" \;
  19. find . -type d -exec chmod 755 "{}" \;
  20. chmod 755 KSP.x86  KSP.x86_64  Launcher.x86  Launcher.x86_64 "${BINARY}" "$(basename "$0")"
  21.  
  22. {
  23.    [ -x "$(which xwininfo)" ] || { printf "xwininfo not found, aborting window geometry guard!\n" >&2 ; exit 1 ; }
  24.    STOPDATE="$(date +%s -d "180 seconds")"
  25.    printf "Starting window geometry guard...\n"
  26.    while [ "$(date +%s)" -lt "$STOPDATE" ] > /dev/null
  27.    do
  28.        WIDTH="$(xwininfo -name "Kerbal Space Program" 2>/dev/null | grep -o 'Width:[[:space:]]*[0-9]\+' | grep -o '[0-9]\+')"
  29.        HEIGHT="$(xwininfo -name "Kerbal Space Program" 2>/dev/null | grep -o 'Height:[[:space:]]*[0-9]\+' | grep -o '[0-9]\+')"
  30.        [ "${WIDTH:-0}" -gt "$(( $WINWIDTH *4 ))" ] && { printf "Window geometry is freaky (${WIDTH}x${HEIGHT}), killing KSP!\n" >&2 ; killall -9 "${BINARY}" ; exit 0 ; }
  31.        [ "${HEIGHT:-0}" -gt "$(( $WINHEIGHT * 4 ))" ] && { printf "Window geometry is freaky (${WIDTH}x${HEIGHT}), killing KSP!\n" >&2 ; killall -9 "${BINARY}" ; exit 0 ; }
  32.        [ "$WIDTH" != "$PREVWIDTH" -o "$HEIGHT" != "$PREVHEIGHT" ] && printf "Window geometry changed from ${PREVWIDTH:-NA}x${PREVHEIGHT:-NA} to ${WIDTH}x${HEIGHT}\n"
  33.        PREVWIDTH=$WIDTH
  34.        PREVHEIGHT=$HEIGHT
  35.        sleep 0.2
  36.        pidof "${BINARY}" >/dev/null || break
  37.    done
  38.    printf "Window geometry guard no longer needed.\n"
  39. } &
  40.  
  41. {
  42.    STOPDATE="$(date +%s -d "2 seconds")"
  43.    until pidof "${BINARY}" > /dev/null || [ "$(date +%s)" -ge "$STOPDATE" ]
  44.    do
  45.        printf "Waiting for \"${BINARY}\" process to appear...\n"
  46.        sleep .1
  47.    done
  48.    if pidof "${BINARY}" > /dev/null
  49.    then
  50.        printf "Bumping KSP OOM killer score in case it goes berserk and chews up all the memory at once.\nCurrent OOM score: $(cat /proc/$(pgrep "${BINARY}")/oom_score)\n"
  51.        echo 15 > "/proc/$(pgrep "${BINARY}")/oom_adj"
  52.        printf "New OOM score: $(cat /proc/$(pgrep "${BINARY}")/oom_score)\n"
  53.    fi
  54. } &
  55.  
  56. printf "Launching. Hold on to yer helmets and pray the Kraken!\n"
  57. exec ./"${BINARY}" -screen-fullscreen 0 -screen-width $WINWIDTH -screen-height $WINHEIGHT -force-glcore -force-gfxdirect
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement