Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Reimplemented srctool as a bash script.

  • Loading branch information...
commit 5220b8e2cd1f3c5b4526419c649884edcf48091d 1 parent e5904b6
@jimbru authored
Showing with 67 additions and 60 deletions.
  1. +67 −0 srctool
  2. +0 −60 srctool.py
View
67 srctool
@@ -0,0 +1,67 @@
+#!/bin/bash
+#
+# srctool
+#
+# Useful for managing srcds.
+# -jimbru
+
+SCRIPT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
+action_install() {
+ INSTALL_PATH=$1
+ : ${INSTALL_PATH:="."}
+
+ SRCDS_PATH=$INSTALL_PATH/srcds
+
+ echo "Installing srcds into $SRCDS_PATH ..."
+
+ mkdir -p $SRCDS_PATH
+
+ echo yes | $SCRIPT_PATH/hldsupdatetool.bin > /dev/null
+ if [[ $? != 0 ]]
+ then
+ echo "ERROR: Hldsupdatetool.bin exited abnormally. Exiting..."
+ exit 1
+ fi
+
+ mv readme.txt $SRCDS_PATH/srcds_readme.txt
+ mv steam $SRCDS_PATH/
+
+ RETURN=1
+ INDEX=0
+ RETRY=5
+ while [[ $RETURN != 0 && $INDEX < $RETRY ]]
+ do
+ $SRCDS_PATH/steam -command update -game "Counter-Strike Source" -dir $SRCDS_PATH
+ RETURN=$?
+ ((++INDEX))
+ done
+ if [[ $INDEX == $RETRY ]]
+ then
+ echo "ERROR: Steam failed after $RETRY retries. Exiting..."
+ exit 1
+ fi
+
+ echo "[ DONE ]"
+}
+
+print_usage() {
+ echo "Usage: $0 action [-opts] [args]"
+}
+
+# -----
+
+if [[ $# < 1 ]]
+then
+ print_usage
+ exit 1
+fi
+
+ACTION=$1
+shift
+case $ACTION in
+ install ) action_install $@ ;;
+ usage ) print_usage ;;
+ * ) echo "Unknown action. Exiting..." ;;
+esac
+exit 0
View
60 srctool.py
@@ -1,60 +0,0 @@
-#!/usr/bin/python
-#
-# srctool
-#
-# A tool to ease management of srcds.
-# -jimbru
-#
-
-from argparse import ArgumentParser
-import os
-import os.path
-from shutil import move
-from subprocess import Popen, PIPE
-
-
-def install(dir):
- if not os.path.exists(dir):
- os.makedirs(dir)
-
- proc = Popen("./hldsupdatetool.bin", stdin=PIPE, stdout=PIPE, stderr=PIPE)
- proc.communicate("yes")
- proc.wait()
- if proc.returncode != 0:
- print "Error: hldsupdatetool.bin exited abnormally"
- exit(proc.returncode)
-
- move("readme.txt", os.path.join(dir, "srcds_readme.txt"))
- steam_path = os.path.join(dir, "steam")
- move("steam", steam_path)
-
- cmd = [steam_path, "-command", "update", "-game", "Counter-Strike Source",
- "-dir", dir]
- limit = 3
-
- for i in range(limit):
- proc = Popen(cmd, stdin=PIPE)
- proc.wait()
- if proc.returncode == 0:
- break
- elif i == limit - 1:
- print "Error: steam update failed after %d retries" % limit
- exit(proc.returncode)
-
- print "Install complete."
-
-
-def main():
- parser = ArgumentParser("srctool")
- parser.add_argument("action", help="action to take")
- parser.add_argument("-d", "--dir", default="srcds", help="install directory")
- args = parser.parse_args()
-
- if args.action == "install":
- install(args.dir)
- else:
- print "Unrecognized action. Exiting..."
-
-
-if __name__ == "__main__":
- main()
Please sign in to comment.
Something went wrong with that request. Please try again.