import subprocess import sys import requests def run_command(command): print(command) process = subprocess.Popen(['bash', '-c', '. /home/mastodon/.bashrc; . /home/mastodon/.profile; ' + command], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = process.communicate() if process.returncode != 0: print(f'Error executing command: {command}') if err: print(f'Error message: {err.decode("utf-8")}') quit(1) else: if out: print(f'{out.decode("utf-8")}') return True # Get the latest release from the Mastodon repository response = requests.get('https://api.github.com/repos/mastodon/mastodon/releases/latest') data = response.json() latest_release = data['tag_name'] # Get the current tag of the local repository process = subprocess.Popen(['git', 'describe', '--tags'], stdout=subprocess.PIPE) out, err = process.communicate() current_tag = out.decode('utf-8').strip() # Compare the latest release with the current tag if latest_release == current_tag: print('Local repository is up to date.') else: print(f'Local repository is not up to date. We have {current_tag}, latest release is {latest_release}.') # Fetch the latest changes and checkout to the latest release if run_command(f'git fetch && git checkout {latest_release}'): if run_command('/home/mastodon/.rbenv/shims/bundle install') and run_command('yarn install --frozen-lockfile'): sys.exit(100)