DeaD_EyE icon

steamcmd install test

DeaD_EyE | PRO | 08/02/23 10:25:25 AM UTC | 0 ⭐ | 1218 👁️ | Never ⏰ | []
Python |

1.75 KB

|

None

|

0 👍

/

0 👎

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()
 

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎