Advertisement
DeaD_EyE

steamcmd install test

Aug 2nd, 2023
747
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.75 KB | None | 0 0
  1. import shutil
  2. import subprocess
  3. from argparse import ArgumentParser
  4. from pathlib import Path
  5. from urllib.parse import urlparse
  6. from urllib.request import urlretrieve
  7.  
  8. STEAM_CMD_URL = "http://media.steampowered.com/client/steamcmd_linux.tar.gz"
  9. STEAM_CMD_DIR = Path.home().joinpath("steam_cmd")
  10. STEAM_CMD_ARCHIVE = STEAM_CMD_DIR / Path(urlparse(STEAM_CMD_URL).path).name
  11. STEAM_CMD_DIR.mkdir(exist_ok=True)
  12.  
  13.  
  14. def download():
  15.     print("Downloading")
  16.     urlretrieve(STEAM_CMD_URL, STEAM_CMD_ARCHIVE)
  17.  
  18.  
  19. def unpack():
  20.     print("Extracting")
  21.     shutil.unpack_archive(STEAM_CMD_ARCHIVE, STEAM_CMD_DIR)
  22.  
  23.  
  24. def is_installed() -> bool:
  25.     return (STEAM_CMD_DIR / "steamcmd.sh").exists()
  26.  
  27.  
  28. def update_steamcmd():
  29.     bin_dir = STEAM_CMD_DIR / "linux32"
  30.     bin_file = bin_dir / "steamcmd"
  31.     subprocess.run(
  32.         [bin_file, "+quit"],
  33.         env={"LD_LIBRARY_PATH": str(bin_dir)},
  34.         stderr=subprocess.DEVNULL,
  35.     )
  36.  
  37.  
  38. def install_game(appid, target):
  39.     bin_dir = STEAM_CMD_DIR / "linux32"
  40.     bin_file = bin_dir / "steamcmd"
  41.     subprocess.run(
  42.         [
  43.             bin_file,
  44.             "+force_install_dir",
  45.             str(target),
  46.             "+login",
  47.             "anonymous",
  48.             "+app_update",
  49.             str(appid),
  50.             "validate",
  51.             "+quit",
  52.         ],
  53.         env={"LD_LIBRARY_PATH": str(bin_dir)},
  54.     )
  55.  
  56.  
  57. def get_args():
  58.     parser = ArgumentParser()
  59.     parser.add_argument("appid", type=int)
  60.     parser.add_argument("target", type=Path)
  61.     return parser.parse_args()
  62.  
  63.  
  64. def main():
  65.     args = get_args()
  66.     if not is_installed():
  67.         download()
  68.         unpack()
  69.  
  70.     update_steamcmd()
  71.     install_game(args.appid, args.target)
  72.  
  73.  
  74. if __name__ == "__main__":
  75.     main()
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement