Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import shutil
- import subprocess
- from argparse import ArgumentParser
- from pathlib import Path
- from urllib.parse import urlparse
- from urllib.request import urlretrieve
- STEAM_CMD_URL = "http://media.steampowered.com/client/steamcmd_linux.tar.gz"
- STEAM_CMD_DIR = Path.home().joinpath("steam_cmd")
- STEAM_CMD_ARCHIVE = STEAM_CMD_DIR / Path(urlparse(STEAM_CMD_URL).path).name
- STEAM_CMD_DIR.mkdir(exist_ok=True)
- def download():
- print("Downloading")
- urlretrieve(STEAM_CMD_URL, STEAM_CMD_ARCHIVE)
- def unpack():
- print("Extracting")
- shutil.unpack_archive(STEAM_CMD_ARCHIVE, STEAM_CMD_DIR)
- def is_installed() -> bool:
- return (STEAM_CMD_DIR / "steamcmd.sh").exists()
- def update_steamcmd():
- bin_dir = STEAM_CMD_DIR / "linux32"
- bin_file = bin_dir / "steamcmd"
- subprocess.run(
- [bin_file, "+quit"],
- env={"LD_LIBRARY_PATH": str(bin_dir)},
- stderr=subprocess.DEVNULL,
- )
- def install_game(appid, target):
- bin_dir = STEAM_CMD_DIR / "linux32"
- bin_file = bin_dir / "steamcmd"
- subprocess.run(
- [
- bin_file,
- "+force_install_dir",
- str(target),
- "+login",
- "anonymous",
- "+app_update",
- str(appid),
- "validate",
- "+quit",
- ],
- env={"LD_LIBRARY_PATH": str(bin_dir)},
- )
- def get_args():
- parser = ArgumentParser()
- parser.add_argument("appid", type=int)
- parser.add_argument("target", type=Path)
- return parser.parse_args()
- def main():
- args = get_args()
- if not is_installed():
- download()
- unpack()
- update_steamcmd()
- install_game(args.appid, args.target)
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement