add support to upgrade pre-existing installs

This commit is contained in:
greenseeker 2024-02-18 18:58:06 -05:00
parent 88cdae6de0
commit e2ab01674f

107
setup
View file

@ -62,10 +62,59 @@ def download_file(url, filename):
pbar.close() pbar.close()
return filename return filename
if __name__ == "__main__": def version_compare(installed_version, package_version):
if installed_version == package_version: return 0
installed = installed_version.split(".")
packaged = package_version.split(".")
if installed[0] < packaged[0]:
return 1
elif installed[0] > packaged[0]:
return -1
if installed[1] < packaged[1]:
return 1
elif installed[1] > packaged[1]:
return -1
if installed[2] < packaged[2]:
return 1
elif installed[2] > packaged[2]:
return -1
if __name__ == "__main__":
# Check for an existing install. Read version from the release file if it exists, otherwise assume 0.7.3
if isfile(release_file):
with open(release_file, 'r') as rf:
installed_version = rf.read().rstrip()
elif isfile(f"{install_dir}/GameData/Tribes2.exe"):
installed_version = "0.7.3"
else:
installed_version = None
# Get the version in this install package
if isfile(f"{pwd}/etc/t2server/release"):
with open(f"{pwd}/etc/t2server/release", 'r') as rf:
package_version = rf.read().rstrip()
else:
package_version = None
# Compare versions to see if the install package is newer than the installed version and quit if not
if installed_version and package_version: upgrade = version_compare(installed_version, package_version)
else: upgrade = None
# Exit if trying to update to an older version or the same version, otherwise display the initial menu and determine the setup mode
if upgrade == -1:
bail(f"This would install t2server {package_version} which is older than what's already installed, version {installed_version}.")
elif upgrade == 0:
bail(f"The existing t2server install is the same version as this install package, {package_version}.")
elif upgrade == 1:
setup_mode=menu([f"[U]pgrade to {package_version}","[Q]uit"],header=f"An existing t2server {installed_version} install was detected. 'Upgrade' will only update the scripts and files that come with t2server and won't reinstall Tribes 2.")
if setup_mode == "Q": bail()
else:
action=menu(["~~[C]ontinue","[Q]uit"],header="This script will install Tribes 2 for use as a dedicated server.") action=menu(["~~[C]ontinue","[Q]uit"],header="This script will install Tribes 2 for use as a dedicated server.")
if action == "Q": bail() if action == "Q": bail()
setup_mode="I"
if setup_mode == "R":
system(f"{pwd}/usr/local/bin/t2remove -Y")
# Check if user exists # Check if user exists
try: try:
@ -73,47 +122,47 @@ if __name__ == "__main__":
except KeyError: except KeyError:
user_info = False user_info = False
# Create or repurpose user if setup_mode == "I" or setup_mode == "R":
# Create or repurpose user if installing or reinstalling
if user_info: if user_info:
if user_info.pw_dir == install_dir: if user_info.pw_dir == install_dir:
pwarn(f"User '{user}' exists and will be reused.") pwarn(f"User '{user}' exists and will be reused.")
else: else:
bail(f"ERROR: User '{user}' already exists and may belong to another person or process.") bail(f"ERROR: User '{user}' already exists and may belong to another person or process.")
else: else:
pinfo(f"Creating {user} user and {install_dir}.") print(f"Creating {user} user and {install_dir}.")
system(f"useradd -md {install_dir} {user}") system(f"useradd -md {install_dir} {user}")
if not user_info: user_info = getuser(user) if not user_info: user_info = getuser(user)
# Create log_dir # Create log_dir
pinfo(f"Creating {log_dir}.") print(f"Creating {log_dir}.")
makedirs(log_dir, mode=0o777, exist_ok=True) makedirs(log_dir, mode=0o777, exist_ok=True)
chmod(log_dir, 0o777) chmod(log_dir, 0o777)
# Create .wine dir # Create .wine dir
pinfo(f"Creating {install_dir}/.wine defaults.") print(f"Creating {install_dir}/.wine defaults.")
system(f"su - {user} -c'wineboot -i > /dev/null 2>&1'") system(f"su - {user} -c'wineboot -i > /dev/null 2>&1'")
# Map wine I: drive to pwd T: drive to install_dir and L: to log_dir # Map wine I: drive to pwd T: drive to install_dir and L: to log_dir
pinfo(f"Mapping I: in wine for {user}.") print(f"Mapping I: in wine for {user}.")
try: try:
symlink(f"{pwd}/winbin", f"{install_dir}/.wine/dosdevices/i:") symlink(f"{pwd}/winbin", f"{install_dir}/.wine/dosdevices/i:")
except FileExistsError: except FileExistsError:
pass pass
pinfo(f"Mapping L: in wine for {user}.") print(f"Mapping L: in wine for {user}.")
try: try:
symlink(log_dir, f"{install_dir}/.wine/dosdevices/l:") symlink(log_dir, f"{install_dir}/.wine/dosdevices/l:")
except FileExistsError: except FileExistsError:
pass pass
pinfo(f"Mapping T: in wine for {user}.") print(f"Mapping T: in wine for {user}.")
try: try:
symlink(install_parent, f"{install_dir}/.wine/dosdevices/t:") symlink(install_parent, f"{install_dir}/.wine/dosdevices/t:")
except FileExistsError: except FileExistsError:
pass pass
# Check for needed exe/zip/dll files in winbin dir # Check for needed exe/zip/dll files in winbin dir
needed_files=[] needed_files=[]
if isfile(f"{pwd}/winbin/tribes2gsi.exe"): if isfile(f"{pwd}/winbin/tribes2gsi.exe"):
@ -152,7 +201,7 @@ if __name__ == "__main__":
pinfo(f"\nDownloading from {url.split('/')[2]}...") pinfo(f"\nDownloading from {url.split('/')[2]}...")
installer_exe = download_file(url, f"{pwd}/winbin/tribes2_gsi.exe") installer_exe = download_file(url, f"{pwd}/winbin/tribes2_gsi.exe")
if md5sum(installer_exe) == installer_checksum: if md5sum(installer_exe) == installer_checksum:
pinfo("Checksum validation passed.") print("Checksum validation passed.")
break break
else: else:
perror("Checksum validation failed. Trying next mirror.") perror("Checksum validation failed. Trying next mirror.")
@ -169,7 +218,7 @@ if __name__ == "__main__":
pinfo(f"\nDownloading from {url.split('/')[2]}...") pinfo(f"\nDownloading from {url.split('/')[2]}...")
tnpatch_exe = download_file(url, f"{pwd}/winbin/TribesNext_rc2a.exe") tnpatch_exe = download_file(url, f"{pwd}/winbin/TribesNext_rc2a.exe")
if md5sum(tnpatch_exe) == tnpatch_checksum: if md5sum(tnpatch_exe) == tnpatch_checksum:
pinfo("Checksum validation passed.") print("Checksum validation passed.")
break break
else: else:
perror("Checksum validation failed. Trying next mirror." ) perror("Checksum validation failed. Trying next mirror." )
@ -214,7 +263,7 @@ if __name__ == "__main__":
if not isfile(f"{install_dir}/GameData/TN_Uninstall.exe"): bail(f"ERROR: Tribes Next installation appears to have failed. Check {log_dir}/install_wrapper.log") if not isfile(f"{install_dir}/GameData/TN_Uninstall.exe"): bail(f"ERROR: Tribes Next installation appears to have failed. Check {log_dir}/install_wrapper.log")
# Replace msvcrt-ruby190.dll with msvcrt-ruby191.dll # Replace msvcrt-ruby190.dll with msvcrt-ruby191.dll
pinfo("Updating msvcrt-ruby190.dll to msvcrt-ruby191.dll.\n") print("Updating msvcrt-ruby190.dll to msvcrt-ruby191.dll.\n")
copyfile(ruby_dll,f"{install_dir}/GameData/msvcrt-ruby191.dll") copyfile(ruby_dll,f"{install_dir}/GameData/msvcrt-ruby191.dll")
unlink(f"{install_dir}/GameData/msvcrt-ruby190.dll") unlink(f"{install_dir}/GameData/msvcrt-ruby190.dll")
symlink(f"{install_dir}/GameData/msvcrt-ruby191.dll", f"{install_dir}/GameData/msvcrt-ruby190.dll") symlink(f"{install_dir}/GameData/msvcrt-ruby191.dll", f"{install_dir}/GameData/msvcrt-ruby190.dll")
@ -236,16 +285,20 @@ if __name__ == "__main__":
pwarn(f"Ignoring {addon}.") pwarn(f"Ignoring {addon}.")
# Copy t2server and t2bouncer to /usr/local/bin/ # Copy t2server and t2bouncer to /usr/local/bin/
pinfo("Installing t2server script.") if setup_mode == "U": print("Updating t2server script.")
else: print("Installing t2server script.")
copyfile(f"{pwd}/usr/local/bin/t2server",f"{bin_dir}/t2server") copyfile(f"{pwd}/usr/local/bin/t2server",f"{bin_dir}/t2server")
pinfo("Installing t2bouncer script.")
if setup_mode == "U": print("Updating t2bouncer script.")
else: print("Installing t2bouncer script.")
copyfile(f"{pwd}/usr/local/bin/t2bouncer",f"{bin_dir}/t2bouncer") copyfile(f"{pwd}/usr/local/bin/t2bouncer",f"{bin_dir}/t2bouncer")
# Set owner/group on install_dir # Set owner/group on install_dir
chowner(install_dir, user) chowner(install_dir, user)
if setup_mode == "I" or setup_mode == "R":
# Clean up temp dir and some unneeded files # Clean up temp dir and some unneeded files
pinfo("A little housekeeping...") print("A little housekeeping...")
if isfile(f"{install_dir}/Tribes 2 Online.lnk"): unlink(f"{install_dir}/Tribes 2 Online.lnk") if isfile(f"{install_dir}/Tribes 2 Online.lnk"): unlink(f"{install_dir}/Tribes 2 Online.lnk")
if isfile(f"{install_dir}/Tribes 2 Solo & LAN.lnk"): unlink(f"{install_dir}/Tribes 2 Solo & LAN.lnk") if isfile(f"{install_dir}/Tribes 2 Solo & LAN.lnk"): unlink(f"{install_dir}/Tribes 2 Solo & LAN.lnk")
if isfile(f"{install_dir}/UNWISE.EXE"): unlink(f"{install_dir}/UNWISE.EXE") if isfile(f"{install_dir}/UNWISE.EXE"): unlink(f"{install_dir}/UNWISE.EXE")
@ -264,35 +317,37 @@ if __name__ == "__main__":
if isfile(f"{install_dir}/Classic_technical.txt"): unlink(f"{install_dir}/Classic_technical.txt") if isfile(f"{install_dir}/Classic_technical.txt"): unlink(f"{install_dir}/Classic_technical.txt")
# Create config directory and files # Create config directory and files
pinfo(f"\nCreating {etc_dir}, default config, and installing prefs files.") print(f"\nCreating {etc_dir}, default config, and installing prefs files.")
makedirs(f"{etc_dir}/serverprefs", mode=0o775, exist_ok=True) makedirs(f"{etc_dir}/serverprefs", mode=0o775, exist_ok=True)
if isfile(f"{etc_dir}/config.yaml"): if isfile(f"{etc_dir}/config.yaml"):
timestamp = int(time()) timestamp = int(time())
rename(f"{etc_dir}/config.yaml",f"{etc_dir}/config.yaml.{timestamp}") rename(f"{etc_dir}/config.yaml",f"{etc_dir}/config.yaml.{timestamp}")
pwarn(f"Existing {etc_dir}/config.yaml renamed to {etc_dir}/config.yaml.{timestamp}. Be sure to compare with and update the new config.yaml file.") pwarn(f"Existing {etc_dir}/config.yaml renamed to {etc_dir}/config.yaml.{timestamp}. Be sure to compare with and update the new config.yaml file.")
pinfo(f"Writing default {etc_dir}/config.yaml.") print(f"Writing default {etc_dir}/config.yaml.")
copyfile(f"{pwd}/etc/t2server/config.yaml", f"{etc_dir}/config.yaml") copyfile(f"{pwd}/etc/t2server/config.yaml", f"{etc_dir}/config.yaml")
print(f"Writing {etc_dir}/release")
copyfile(f"{pwd}/etc/t2server/release", f"{etc_dir}/release")
for pfile in iglob(f"{pwd}/etc/t2server/serverprefs/*"): for pfile in iglob(f"{pwd}/etc/t2server/serverprefs/*"):
pinfo(f"Copying {pfile} to {etc_dir}/serverprefs.") pinfo(f"Copying {pfile} to {etc_dir}/serverprefs.")
copyfile(pfile,f"{etc_dir}/serverprefs/{pfile.split('/')[-1]}") copyfile(pfile,f"{etc_dir}/serverprefs/{pfile.split('/')[-1]}")
# Create systemd units # Create systemd units
pinfo("\nCreating systemd units:") print("\nCreating systemd units:")
pinfo("- t2server service") print("- t2server service")
copyfile(f"{pwd}/etc/systemd/system/t2server.service",f"{unit_dir}/t2server.service") copyfile(f"{pwd}/etc/systemd/system/t2server.service",f"{unit_dir}/t2server.service")
pinfo("- t2bouncer service") print("- t2bouncer service")
copyfile(f"{pwd}/etc/systemd/system/t2bouncer.service",f"{unit_dir}/t2bouncer.service") copyfile(f"{pwd}/etc/systemd/system/t2bouncer.service",f"{unit_dir}/t2bouncer.service")
pinfo("- t2bouncer timer") print("- t2bouncer timer")
copyfile(f"{pwd}/etc/systemd/system/t2bouncer.timer",f"{unit_dir}/t2bouncer.timer") copyfile(f"{pwd}/etc/systemd/system/t2bouncer.timer",f"{unit_dir}/t2bouncer.timer")
system("systemctl daemon-reload") system("systemctl daemon-reload")
# Install utility scripts # Install utility scripts
pinfo("\nInstalling utilities:") print("\nInstalling utilities:")
pinfo("- t2bouncer") print("- t2bouncer")
copyfile(f"{pwd}/usr/local/bin/t2fixer",f"{bin_dir}/t2fixer") copyfile(f"{pwd}/usr/local/bin/t2fixer",f"{bin_dir}/t2fixer")
pinfo("- t2remove") print("- t2remove")
copyfile(f"{pwd}/usr/local/bin/t2remove",f"{bin_dir}/t2remove") copyfile(f"{pwd}/usr/local/bin/t2remove",f"{bin_dir}/t2remove")
pinfo("- t2help") print("- t2help")
copyfile(f"{pwd}/usr/local/bin/t2help",f"{bin_dir}/t2help") copyfile(f"{pwd}/usr/local/bin/t2help",f"{bin_dir}/t2help")
# Install python module # Install python module
@ -302,6 +357,6 @@ if __name__ == "__main__":
# Show help # Show help
system(f"{bin_dir}/t2help") system(f"{bin_dir}/t2help")
menu(['~~[E]xit'],header="You can run 't2help' at any time to view the info above again.") pinfo("You can run 't2help' at any time to view the info above again.")
print(f"{color.X}\n") print(f"{color.X}\n")