Skip to content

Instantly share code, notes, and snippets.

@hasufell
Last active December 10, 2015 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hasufell/6d85b0c4d234641fc112 to your computer and use it in GitHub Desktop.
Save hasufell/6d85b0c4d234641fc112 to your computer and use it in GitHub Desktop.
From: Julian Ospald <hasufell@gentoo.org>
Date: Wed Jan 9 14:23:55 UTC 2013
Subject: POSIX compliance
--- steam
+++ steam
@@ -1,10 +1,11 @@
-#!/bin/bash
+#!/bin/sh
#
# This is the Steam script that typically resides in /usr/bin
# It will create the Steam bootstrap if necessary and then launch steam.
# Get the full name of this script
-export STEAMSCRIPT="$(cd "${0%/*}" && echo "$PWD")/${0##*/}"
+STEAMSCRIPT="$(cd "${0%/*}" && echo "$PWD")/${0##*/}"
+export STEAMSCRIPT
# This version number is incremented when there is a critical fix that
# end users need to pick up immediately.
@@ -15,44 +16,61 @@
# steamrepo@list.valvesoftware.com
# You can subscribe to this list at:
# https://list.valvesoftware.com/mailman/listinfo/steamrepo
-export STEAMSCRIPT_VERSION=0
+STEAMSCRIPT_VERSION=0
+export STEAMSCRIPT_VERSION
# Set up domain for script localization
-export TEXTDOMAIN=steam
+TEXTDOMAIN=steam
+export TEXTDOMAIN
-function show_message()
+if command -v gettext.sh >/dev/null; then
+ GETTEXT_FOUND=1
+ . gettext.sh
+fi
+
+_gettextecho()
+{
+ if [ $GETTEXT_FOUND = 1 ] ; then
+ echo "$(eval_gettext "$1")"
+ else
+ echo "$1"
+ fi
+}
+
+
+show_message()
{
style=$1
shift
if ! zenity "$style" --text="$*" 2>/dev/null; then
case "$style" in
--error)
- title=$"Error"
+ title="$(_gettextecho "Error")"
;;
--warning)
- title=$"Warning"
+ title="$(_gettextecho "Warning")"
;;
*)
- title=$"Note"
+ title="$(_gettextecho "Note")"
;;
esac
# Save the prompt in a temporary file because it can have newlines in it
tmpfile="$(mktemp || echo "/tmp/steam_message.txt")"
- echo -e "$*" >"$tmpfile"
- xterm -T "$title" -e "cat $tmpfile; echo -n 'Press enter to continue: '; read input"
+ printf "%b$*" >"$tmpfile"
+ xterm -T "$title" -e "cat $tmpfile; printf 'Press enter to continue: '; read input"
rm -f "$tmpfile"
fi
}
-function detect_platform()
+detect_platform()
{
# Maybe be smarter someday
# Right now this is the only platform we have a bootstrap for, so hard-code it.
echo ubuntu12_32
}
-function setup_variables()
+setup_variables()
{
STEAMPACKAGE="${0##*/}"
STEAMCONFIG=~/.steam
@@ -60,7 +78,8 @@
STEAMBOOTSTRAP=steam.sh
LAUNCHSTEAMDIR="$(readlink -e -q "$STEAMDATALINK")"
LAUNCHSTEAMPLATFORM="$(detect_platform)"
- LAUNCHSTEAMBOOTSTRAPFILE="/usr/lib/$STEAMPACKAGE/bootstraplinux_$LAUNCHSTEAMPLATFORM.tar.xz"
+ [ -z $LAUNCHSTEAMBOOTSTRAPFILE ] && LAUNCHSTEAMBOOTSTRAPFILE="/usr/lib/$STEAMPACKAGE/bootstraplinux_$LAUNCHSTEAMPLATFORM.tar.xz"
+ [ -z $DESKTOPFILE ] && DESKTOPFILE="/usr/share/applications/$STEAMPACKAGE.desktop"
# Get the default data path
STEAM_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
@@ -74,18 +93,18 @@
DEFAULTSTEAMDIR="$STEAM_DATA_HOME/SteamBeta"
;;
*)
- echo $"Unknown Steam package '$STEAMPACKAGE'"
+ _gettextecho "Unknown Steam package '$STEAMPACKAGE'"
exit 1
;;
esac
# Create the config directory if needed
- if [[ ! -d "$STEAMCONFIG" ]]; then
+ if [ ! -d "$STEAMCONFIG" ]; then
mkdir "$STEAMCONFIG"
fi
}
-function install_bootstrap()
+install_bootstrap()
{
STEAMDIR="$1"
@@ -93,11 +112,12 @@
omask="$(umask)"
umask 0077
- echo $"Setting up Steam content in $STEAMDIR"
+ _gettextecho "Setting up Steam content in $STEAMDIR"
+
mkdir -p "$STEAMDIR"
cd "$STEAMDIR"
if ! tar xJf "$LAUNCHSTEAMBOOTSTRAPFILE" ; then
- echo $"Failed to extract $LAUNCHSTEAMBOOTSTRAPFILE, aborting installation."
+ _gettextecho "Failed to extract $LAUNCHSTEAMBOOTSTRAPFILE, aborting installation."
exit 1
fi
rm -f "$STEAMDATALINK" && ln -s "$STEAMDIR" "$STEAMDATALINK"
@@ -106,25 +126,27 @@
# put the Steam icon on the user's desktop
# try to read ~/.config/user-dirs.dirs to get the current desktop configuration
# http://www.freedesktop.org/wiki/Software/xdg-user-dirs
- test -f "${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs" && source "${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs"
+ if test -f "${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs" ; then
+ . "${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs"
+ fi
DESKTOP_DIR="${XDG_DESKTOP_DIR:-$HOME/Desktop}"
- cp "/usr/share/applications/$STEAMPACKAGE.desktop" "$DESKTOP_DIR"
+ cp "${DESKTOPFILE}" "$DESKTOP_DIR"
chmod +x "$DESKTOP_DIR/$STEAMPACKAGE.desktop"
# Restore the umask
umask "$omask"
}
-function repair_bootstrap()
+repair_bootstrap()
{
rm -f "$STEAMDATALINK" && ln -s "$1" "$STEAMDATALINK"
setup_variables
}
-function check_bootstrap()
+check_bootstrap()
{
- if [[ -n "$1" && -x "$1/$STEAMBOOTSTRAP" ]]; then
+ if [ -n "$1" ] && [ -x "$1/$STEAMBOOTSTRAP" ]; then
# Looks good...
return 0
else
@@ -138,23 +160,23 @@
if ! check_bootstrap "$LAUNCHSTEAMDIR"; then
# See if we just need to recreate the data link
if check_bootstrap "$DEFAULTSTEAMDIR"; then
- echo $"Repairing installation, linking $STEAMDATALINK to $DEFAULTSTEAMDIR"
+ _gettextecho "Repairing installation, linking $STEAMDATALINK to $DEFAULTSTEAMDIR"
repair_bootstrap "$DEFAULTSTEAMDIR"
elif check_bootstrap "$CLASSICSTEAMDIR"; then
- echo $"Repairing installation, linking $STEAMDATALINK to $CLASSICSTEAMDIR"
+ _gettextecho "Repairing installation, linking $STEAMDATALINK to $CLASSICSTEAMDIR"
repair_bootstrap "$CLASSICSTEAMDIR"
fi
fi
-if [[ ! -L "$STEAMDATALINK" ]]; then
+if [ ! -L "$STEAMDATALINK" ]; then
# We don't have the data link and we couldn't find an existing bootstrap, so just install the bootstrap
install_bootstrap "$DEFAULTSTEAMDIR"
elif ! check_bootstrap "$LAUNCHSTEAMDIR"; then
# We have the data link but we can't find the data, prompt the user
- if zenity --question --text=$"Couldn't find Steam content, did you move it?" --ok-label=$"Search" --cancel-label=$"Reinstall"; then
+ if zenity --question --text="$(_gettextecho "Could not find Steam content, did you move it?")" --ok-label="$(_gettextecho "Search")" --cancel-label="$(_gettextecho "Reinstall")"; then
while true; do
STEAMDIR="`zenity --file-selection --directory`"
- if [[ -z "$STEAMDIR" ]]; then
+ if [ -z "$STEAMDIR" ]; then
# User canceled
exit 0
fi
@@ -162,7 +184,7 @@
repair_bootstrap "$STEAMDIR"
break;
else
- show_message --error $"Please pick a valid Steam content directory"
+ show_message --error "$(_gettextecho "Please pick a valid Steam content directory")"
fi
done
else
@@ -171,7 +193,7 @@
fi
if ! check_bootstrap "$LAUNCHSTEAMDIR"; then
- show_message --error $"Couldn't set up Steam data - please contact technical support"
+ show_message --error "$(_gettextecho "Could not set up Steam data - please contact technical support")"
exit 1
fi
From: Julian Ospald <hasufell@gentoo.org>
Date: Wed Jan 9 14:24:59 UTC 2013
Subject: POSIX compliance
--- steam.sh
+++ steam.sh
@@ -1,7 +1,9 @@
-#!/bin/bash
+#!/bin/sh
-export TEXTDOMAIN=steam
-export TEXTDOMAINDIR=/usr/share/locale
+TEXTDOMAIN=steam
+export TEXTDOMAIN
+TEXTDOMAINDIR=/usr/share/locale
+export TEXTDOMAINDIR
# figure out the absolute path to the script being run a bit
# non-obvious, the ${0%/*} pulls the path out of $0, cd's into the
@@ -19,38 +21,52 @@
# The version of the Steam runtime used by Steam itself
STEAM_RUNTIME=1
-function show_message()
+if command -v gettext.sh >/dev/null; then
+ GETTEXT_FOUND=1
+ . gettext.sh
+fi
+
+_gettextecho()
+{
+ if [ $GETTEXT_FOUND = 1 ] ; then
+ echo "$(eval_gettext "$1")"
+ else
+ echo "$1"
+ fi
+}
+
+show_message()
{
style=$1
shift
if ! zenity "$style" --text="$*" 2>/dev/null; then
case "$style" in
--error)
- title=$"Error"
+ title="$(_gettextecho "Error")"
;;
--warning)
- title=$"Warning"
+ title="$(_gettextecho "Warning")"
;;
*)
- title=$"Note"
+ title="$(_gettextecho "Note")"
;;
esac
# Save the prompt in a temporary file because it can have newlines in it
tmpfile="$(mktemp || echo "/tmp/steam_message.txt")"
- echo -e "$*" >"$tmpfile"
- xterm -T "$title" -e "cat $tmpfile; echo -n 'Press enter to continue: '; read input" 2>/dev/null || \
- (echo "$title:"; cat "$tmpfile"; echo -n 'Press enter to continue: '; read input)
+ printf "%b$*" >"$tmpfile"
+ xterm -T "$title" -e "cat $tmpfile; printf 'Press enter to continue: '; read input" 2>/dev/null || \
+ (echo "$title:"; cat "$tmpfile"; printf 'Press enter to continue: '; read input)
rm -f "$tmpfile"
fi
}
-function warn_outofdate()
+warn_outofdate()
{
- show_message --warning $"Your steam package is out of date. Please get an updated version from your package provider or directly from http://repo.steampowered.com/steam for supported distributions."
+ show_message --warning "$(_gettextecho 'Your steam package is out of date. Please get an updated version from your package provider or directly from http://repo.steampowered.com/steam for supported distributions.')"
}
-function detect_distro()
+detect_distro()
{
if [ -f /etc/os-release ]; then
(. /etc/os-release; echo $ID)
@@ -60,7 +76,7 @@
fi
}
-function detect_release()
+detect_release()
{
if [ -f /etc/os-release ]; then
(. /etc/os-release; echo $VERSION)
@@ -70,7 +86,7 @@
fi
}
-function detect_platform()
+detect_platform()
{
# Default to unknown/unsupported distribution, pick something and hope for the best
PLATFORM=ubuntu12_32
@@ -86,7 +102,7 @@
echo $PLATFORM
}
-function detect_universe()
+detect_universe()
{
if test -f "$STEAMROOT/Steam.cfg" && \
egrep '^[Uu]niverse *= *[Bb]eta$' "$STEAMROOT/Steam.cfg" >/dev/null; then
@@ -100,7 +116,7 @@
echo $STEAMUNIVERSE
}
-function detect_package()
+detect_package()
{
case `detect_universe` in
"Beta")
@@ -113,10 +129,10 @@
echo "$STEAMPACKAGE"
}
-function detect_scriptversion()
+detect_scriptversion()
{
SCRIPT_VERSION=$(fgrep "$2=" "$1")
- if [[ "$SCRIPT_VERSION" ]]; then
+ if [ "$SCRIPT_VERSION" ]; then
expr "$SCRIPT_VERSION" : ".*=\(.*\)"
else
echo "0"
@@ -125,23 +141,23 @@
# Check a currently installed script against a new script and see if the
# installed one needs to be updated.
-function check_scriptversion()
+check_scriptversion()
{
CURSCRIPT=$1
NEWSCRIPT=$2
VERSION_TOKEN=$3
- if [ -f "$CURSCRIPT" -a -f "$NEWSCRIPT" ]; then
+ if [ -f "$CURSCRIPT" ] && [ -f "$NEWSCRIPT" ]; then
CURVERSION="$(detect_scriptversion "$CURSCRIPT" $VERSION_TOKEN)"
NEWVERSION="$(detect_scriptversion "$NEWSCRIPT" $VERSION_TOKEN)"
- if [[ "$CURVERSION" -lt "$NEWVERSION" ]]; then
+ if [ "$CURVERSION" -lt "$NEWVERSION" ]; then
return 1
fi
fi
return 0
}
-function detect_steamdatalink()
+detect_steamdatalink()
{
# Don't create a link in development
if [ -f "$STEAMROOT/steam_dev.cfg" ]; then
@@ -152,7 +168,7 @@
echo $STEAMDATALINK
}
-function install_bootstrap()
+install_bootstrap()
{
# Don't install bootstrap in development
if [ -f "$STEAMROOT/steam_dev.cfg" ]; then
@@ -165,12 +181,16 @@
omask=`umask`
umask 0077
- STEAMBOOTSTRAPARCHIVE="/usr/lib/`detect_package`/bootstraplinux_`detect_platform`.tar.xz"
+ # allow env override
+ if [ -z $STEAMBOOTSTRAPARCHIVE ] ; then
+ STEAMBOOTSTRAPARCHIVE="/usr/lib/`detect_package`/bootstraplinux_`detect_platform`.tar.xz"
+ fi
+
if [ -f "$STEAMBOOTSTRAPARCHIVE" ]; then
tar xJf "$STEAMBOOTSTRAPARCHIVE"
STATUS=$?
else
- show_message --error $"Couldn't start bootstrap and couldn't reinstall from $STEAMBOOTSTRAPARCHIVE. Please contact technical support."
+ show_message --error "$(_gettextecho "Couldn't start bootstrap and couldn't reinstall from $STEAMBOOTSTRAPARCHIVE. Please contact technical support.")"
STATUS=1
fi
@@ -182,14 +202,14 @@
#determine platform
UNAME=`uname`
-if [ "$UNAME" == "Linux" ]; then
+if [ "$UNAME" = "Linux" ]; then
# See if we need to update the /usr/bin/steam script
NEWSTEAMSCRIPT="$STEAMROOT/bin_steam.sh"
if [ -z "$STEAMSCRIPT" ]; then
STEAMSCRIPT="/usr/bin/`detect_package`"
fi
- if [ -f "$STEAMSCRIPT" -a -f "$NEWSTEAMSCRIPT" ]; then
+ if [ -f "$STEAMSCRIPT" ] && [ -f "$NEWSTEAMSCRIPT" ]; then
if ! check_scriptversion "$STEAMSCRIPT" "$NEWSTEAMSCRIPT" STEAMSCRIPT_VERSION; then
warn_outofdate "$STEAMSCRIPT"
fi
@@ -198,7 +218,7 @@
# See if we need to update the /usr/bin/steamdeps script
STEAMDEPS="`dirname $STEAMSCRIPT`/`detect_package`deps"
NEWSTEAMDEPS="$STEAMROOT/bin_steamdeps.py"
- if [ -f "$STEAMDEPS" -a -f "$NEWSTEAMDEPS" ]; then
+ if [ -f "$STEAMDEPS" ] && [ -f "$NEWSTEAMDEPS" ]; then
if ! check_scriptversion "$STEAMDEPS" "$NEWSTEAMDEPS" STEAMDEPS_VERSION; then
warn_outofdate "$STEAMDEPS"
elif [ -f "$STEAMROOT/steamdeps.txt" ]; then
@@ -208,7 +228,7 @@
fi
# identify Linux distribution and pick an optimal bin dir
- if [ "$STEAMEXE" == "steamcmd" ]; then
+ if [ "$STEAMEXE" = "steamcmd" ]; then
PLATFORM=linux32 # dedicated server build (minimal dependencies)
else
PLATFORM=`detect_platform`
@@ -256,15 +276,18 @@
#rm -f ~/.steampath ~/.steampid ~/.steam/bin
# prepend our lib path to LD_LIBRARY_PATH
- export LD_LIBRARY_PATH="$STEAMROOT/$PLATFORM:$LD_LIBRARY_PATH"
+ LD_LIBRARY_PATH="$STEAMROOT/$PLATFORM:$LD_LIBRARY_PATH"
+ export LD_LIBRARY_PATH
# disable SDL1.2 DGA mouse because we can't easily support it in the overlay
- export SDL_VIDEO_X11_DGAMOUSE=0
+ SDL_VIDEO_X11_DGAMOUSE=0
+ export SDL_VIDEO_X11_DGAMOUSE
-else # if [ "$UNAME" == "Darwin" ]; then
+else # if [ "$UNAME" = "Darwin" ]; then
PLATFORM=osx32
# prepend our lib path to LD_LIBRARY_PATH
- export DYLD_LIBRARY_PATH="$STEAMROOT/$PLATFORM:$DYLD_LIBRARY_PATH"
+ DYLD_LIBRARY_PATH="$STEAMROOT/$PLATFORM:$DYLD_LIBRARY_PATH"
+ export DYLD_LIBRARY_PATH
# make sure our architecture is sane
ARCH=`arch`
case "$ARCH" in
@@ -289,7 +312,8 @@
esac
fi
-ulimit -n 2048
+# not a POSIX built-in
+#ulimit -n 2048
# Touch our startup file so we can detect bootstrap launch failure
if [ "$UNAME" = "Linux" ]; then
@@ -299,7 +323,7 @@
MAGIC_RESTART_EXITCODE=42
# and launch steam
-if [ "$DEBUGGER" == "gdb" ] || [ "$DEBUGGER" == "cgdb" ]; then
+if [ "$DEBUGGER" = "gdb" ] || [ "$DEBUGGER" = "cgdb" ]; then
ARGSFILE=$(mktemp $USER.steam.gdb.XXXX)
# Set the LD_PRELOAD varname in the debugger, and unset the global version.
@@ -317,12 +341,13 @@
STATUS=$?
if [ "$UNAME" = "Linux" ]; then
- if [ $STATUS -ne $MAGIC_RESTART_EXITCODE -a -f "$STEAMSTARTING" \
- -a -z "$STEAM_INSTALLED_BOOTSTRAP" ]; then
+ if [ $STATUS -ne $MAGIC_RESTART_EXITCODE ] && [ -f "$STEAMSTARTING" ] \
+ && [ -z "$STEAM_INSTALLED_BOOTSTRAP" ]; then
# Launching the bootstrap failed, try reinstalling
if install_bootstrap; then
# We were able to reinstall the bootstrap, try again
- export STEAM_INSTALLED_BOOTSTRAP=1
+ STEAM_INSTALLED_BOOTSTRAP=1
+ export STEAM_INSTALLED_BOOTSTRAP
STATUS=$MAGIC_RESTART_EXITCODE
fi
fi
@@ -330,7 +355,7 @@
if [ $STATUS -eq $MAGIC_RESTART_EXITCODE ]; then
# are we running running from a bundle on osx?
- if [ $PLATFORM == "osx32" -a -f Info.plist ]; then
+ if [ $PLATFORM = "osx32" ] && [ -f Info.plist ]; then
exec open "$STEAMROOT/../.."
else
exec "$0" $*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment