[SH] FastDL downloader for HL2DM

Forum rules
- Ask questions about or share code from languages other than Source Engine scripting.
- Start new topic titles with the code language in brackets (i.e. [C#], [C++], [PHP], etc.)
Locked
User avatar
Xseba360
Server Admin
Posts: 1663
Joined: Sun Apr 11, 2010 12:26 pm
Location: Poland
Contact:

[SH] FastDL downloader for HL2DM

Post by Xseba360 » Fri May 17, 2013 1:26 pm

This shell script is supposed to download specified map from specified fastdl server.

Purposes:
  • When you're playing on some server, and you don't have the next map on the list, you can minimize the game, start up this script and get the map without long wait using in-game download.
  • You want to get the map without starting the game.
  • When properly modified, you can steal maps from other servers directly to your server, no need to upload anything! (doubt that's gonna work with a gameserver... unless they allow u to install packages and execute shell scripts)
Requirements:
Not really sure... though on Ubuntu 12.10 i had to get this:
  • Korn Shell (preferably AT&T) - won't work properly in Ubuntu's DASH (lack of some things LOL)
Script itself is here:
Spoiler
Show
https://dl.dropboxusercontent.com/u/19656788/fast2dl.sh (since tabs get turned into spaces on here ._.)
or

Code: Select all

#!/bin/ksh
# ^ THIS IS SUPPOSED TO BE RUN ON KORN SHELL
# This will download and extract map from fastdl servers (in case if ingame download fails).
# By Xseba360

# 16/05/2013 22:06:11 

# functions

askurl () {
	if [ -f "/tmp/.fastdl_cfg/url.txt" ]; then
		askurl2
	else
		usenew
	fi
}

askurl2 () {

	echo "Do you wish to use last used FastDL url?"
	read  answer
	case $answer in
		yes|Yes|y|Y|ya|yea|Yea)
			useold
			;;
	
		no|No|n|N|nah|Nah|Nope|nope|nop|Nop)
			usenew
			;;
	
		q*|Q*)
			exit
			;;
			
		*)
			echo "This is not a correct answer, let's try this again."
			askurl2
			;;
	esac

}

usenew () {
	cd "/tmp" && mkdir -p ".fastdl_cfg" && cd ".fastdl_cfg"
	echo "Type the FastDL url gotten from sv_downloadurl and press [ENTER]"
	echo ""
	echo "the 'http://' is not required"
	echo "Example: http://www.example.com/fastdl"
	echo "Example:        www.example.com/hl2mp"
	echo ""
	read urldir
	echo "$urldir">url.txt
	getname
}

useold () {
	cd "/tmp/.fastdl_cfg/"
	read -r urldir<url.txt
	getname
}

getname () {
	echo "Type the map name below and press [ENTER]:"
	echo "Example: dm_lockdown"
	read map
	getmap
}

getmap () {
	cd "/tmp" && mkdir -p ".fastdlmaps" && cd ".fastdlmaps"
	echo "Getting map file..."
	wget -q "$urldir/maps/$map.bsp" || wget -q "$urldir/maps/$map.bsp.bz2"
	unbz2
}

unbz2 () {
	if [ -f "/tmp/.fastdlmaps/$map.bsp" ]; then
		echo "Map file not compressed."
		movemap
	elif [ -f "/tmp/.fastdlmaps/$map.bsp.bz2" ]; then
		echo "Extracting map file..."
		bunzip2 -q "$map.bsp.bz2"
		movemap
	else
		echo "File not found! Re-check url and map name!"
	fi

}

movemap () {
	mv -f "$map.bsp" "/home/$USER/.steam/steam/SteamApps/common/Half-Life 2 Deathmatch/hl2mp/maps/" && echo "Moving map file..."
	echo "Done!"
}

# checksteamdir begin

if [ -d "/home/$USER/.steam/steam/SteamApps/" ]; then
	askurl
else
	echo "I don't know where your steam folder is! Sorry."
fi
This is obviously for Linux... so if you want to run it on windows... you can use cygwin... here's how:
Spoiler
Show
  1. Grab cygwin installer from here: http://cygwin.com/setup.exe
  2. Open the file and press 'Next >' 5 times, unless you use a proxy you can leave everything on default settings.
  3. Select mirror, doesn't matter which. Press next.
  4. Installer will start to download more setup files...
  5. Package downloader will show up. In search box type: ksh
  6. From Shells category select 'mksh: MirBSD Korn Shell' by clicking on 'Skip' text once.
  7. In search box type: wget
  8. From Web category select 'wget: Utility to retrieve ...' by clicking on 'Skip' text once.
  9. Packages will start to download. When it's done, press 'Next >'
  10. You can ignore the error. Press 'Next >'
  11. You may wish to create dekstop shortcut, you better do so because it might be handy in other step then click 'Finish'
  12. Now go to start menu and start Cygwin Terminal. You might find the shortcut you created in previous step handy.
  13. After some seconds the files inside our home folder should be ready then you can close the Terminal.
  14. WinXP: (you need administrator account for this) Open up CMD by pressing Win+R keys and typing in: cmd
    WinVista/7: Start menu -> in Search bar type -> cmd -> rightclick on search result and select Run as administrator
  15. Navigate to your /home/<username> folder inside cygwin installation folder like this: cd "C:/cygwin/home/<username>/"
    example:
    cd "C:/cygwin/home/xseba360"
  16. Then do:
    mkdir .steam
    and then:
    cd .steam
  17. And then do Then do: mklink /d Steam "<steam main folder>"
    example:
    mklink /d Steam "C:/Program Files (x86)/Steam"
    OR if you're WinXP user check this out:
    http://technet.microsoft.com/en-us/sysi ... 96768.aspx
  18. Download this: https://dl.dropboxusercontent.com/u/19656788/fast2dl.sh and put it in C:/cygwin/home/<username> (don't try copypasting the script from upper part of this post and paste it into windows notepad. it wont work... believe me)
  19. Open cygwin terminal and type: sh fast2dl.sh
  20. You're done! Everything should work like this: http://youtu.be/RJxk5QZHl2Q
If you find a problem, i'm gonna be really happy if you report it to me.
Last edited by Xseba360 on Fri May 17, 2013 5:56 pm, edited 4 times in total.

Locked