Created
February 4, 2024 08:16
-
-
Save danpicton/3e65fd279c4ea39247431fb6963c6a75 to your computer and use it in GitHub Desktop.
Terminal prompt to update Arch every n days
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/python | |
| from subprocess import run | |
| from datetime import datetime, timedelta | |
| TSFILE_LOCATION = '/home/abcde/.arch_updater' | |
| PROMPT_REMINDER_DAYS = 1 | |
| def write_tsfile(ts=None): | |
| ts = str(ts) | |
| with open(TSFILE_LOCATION, 'w+') as tsf: | |
| if ts: | |
| tsf.write(ts) | |
| def read_tsfile(): | |
| last_ts = None | |
| try: | |
| with open(TSFILE_LOCATION, 'r') as tsf: | |
| last_ts = tsf.readline() | |
| except FileNotFoundError: | |
| last_ts = (datetime.now() - timedelta(days=1)).timestamp() | |
| write_tsfile(last_ts) | |
| # print(last_ts) | |
| return datetime.fromtimestamp(float(last_ts)) | |
| def main(): | |
| last_prompt_date = read_tsfile() | |
| if datetime.now() >= last_prompt_date + timedelta(days=PROMPT_REMINDER_DAYS): | |
| while True: | |
| p_in = input("Do you wish to upgrade Arch? (y/n).: ") | |
| if p_in not in "nyNY": | |
| print("Please choose y or n to continue") | |
| continue | |
| if p_in in "Yy": | |
| run(["sudo", "pacman", "-Syyu"]) | |
| write_tsfile(datetime.now().timestamp()) | |
| break | |
| if __name__ == main(): | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment