Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- WINWIDTH=1919
- WINHEIGHT=1069
- BINARY=KSP.x86_64
- # change dir to script location
- cd "$(dirname "$(readlink -f "$0")")"
- printf "Still can not learn locales while reading settings? setting LC_ALL=C\n"
- LANG=C
- LC_ALL=C
- export LC_ALL
- export LANG
- unset LANGUAGE
- printf "Fixing weird permissions from game archive.\n"
- find . -type f -exec chmod 644 "{}" \;
- find . -type d -exec chmod 755 "{}" \;
- chmod 755 KSP.x86 KSP.x86_64 Launcher.x86 Launcher.x86_64 "${BINARY}" "$(basename "$0")"
- {
- [ -x "$(which xwininfo)" ] || { printf "xwininfo not found, aborting window geometry guard!\n" >&2 ; exit 1 ; }
- STOPDATE="$(date +%s -d "180 seconds")"
- printf "Starting window geometry guard...\n"
- while [ "$(date +%s)" -lt "$STOPDATE" ] > /dev/null
- do
- WIDTH="$(xwininfo -name "Kerbal Space Program" 2>/dev/null | grep -o 'Width:[[:space:]]*[0-9]\+' | grep -o '[0-9]\+')"
- HEIGHT="$(xwininfo -name "Kerbal Space Program" 2>/dev/null | grep -o 'Height:[[:space:]]*[0-9]\+' | grep -o '[0-9]\+')"
- [ "${WIDTH:-0}" -gt "$(( $WINWIDTH *4 ))" ] && { printf "Window geometry is freaky (${WIDTH}x${HEIGHT}), killing KSP!\n" >&2 ; killall -9 "${BINARY}" ; exit 0 ; }
- [ "${HEIGHT:-0}" -gt "$(( $WINHEIGHT * 4 ))" ] && { printf "Window geometry is freaky (${WIDTH}x${HEIGHT}), killing KSP!\n" >&2 ; killall -9 "${BINARY}" ; exit 0 ; }
- [ "$WIDTH" != "$PREVWIDTH" -o "$HEIGHT" != "$PREVHEIGHT" ] && printf "Window geometry changed from ${PREVWIDTH:-NA}x${PREVHEIGHT:-NA} to ${WIDTH}x${HEIGHT}\n"
- PREVWIDTH=$WIDTH
- PREVHEIGHT=$HEIGHT
- sleep 0.2
- pidof "${BINARY}" >/dev/null || break
- done
- printf "Window geometry guard no longer needed.\n"
- } &
- {
- STOPDATE="$(date +%s -d "2 seconds")"
- until pidof "${BINARY}" > /dev/null || [ "$(date +%s)" -ge "$STOPDATE" ]
- do
- printf "Waiting for \"${BINARY}\" process to appear...\n"
- sleep .1
- done
- if pidof "${BINARY}" > /dev/null
- then
- 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"
- echo 15 > "/proc/$(pgrep "${BINARY}")/oom_adj"
- printf "New OOM score: $(cat /proc/$(pgrep "${BINARY}")/oom_score)\n"
- fi
- } &
- printf "Launching. Hold on to yer helmets and pray the Kraken!\n"
- 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