c0d3m0nk3y Posted May 7, 2022 Share Posted May 7, 2022 (edited) I needed ack and prename installed in the system bin, along with some of my own. So I cleaned up the code and decided to share. This only requires vanilla python v3+. What it does: For each item in the dictionary _scripts - If script is missing , or older than a week (can be changed on line 27), it will download it from the url defined in the dictionary item For each *.sh or *.pl file in the script's directory - Copies it to /usr/bin/ and enables execution permission Python Script import os import subprocess from datetime import datetime from datetime import timedelta def shell(cmd, check=False) -> str: res = subprocess.run(cmd, stdout=subprocess.PIPE, shell=True, check=check) return res.stdout.decode('utf-8').strip() def curl(url, scriptName): shell(f'curl {url} -o {scriptName}') _scripts = { #https://forums.unraid.net/topic/79490-rename-instead-of-rename-perl-instead-of-unix-util/ 'prename.pl': lambda k: curl('https://gist.githubusercontent.com/javiermon/3939556/raw/b9d0634f2c099b825a483d3d75cae1712fb9aa31/prename.pl', k), #https://beyondgrep.com/install/ 'ack.pl': lambda k: curl('https://beyondgrep.com/ack-v3.5.0', k) } _scriptExt = ['.sh', '.pl'] _bin = '/usr/bin/' def run(): oneWeekAgo = datetime.now() - timedelta(days=7) for k in _scripts.keys(): sp = './' + k if not os.path.exists(sp) or datetime.fromtimestamp(os.path.getmtime(sp)) < oneWeekAgo: print(f'Updating: {k}') _scripts[k](k) for f in os.listdir(os.fsencode('./')): fn = os.fsdecode(f) fns = os.path.splitext(fn) if fns[1] in _scriptExt: print(f'Copying: {fn} -> {_bin}{fns[0]}') shell(f'cp {fn} {_bin}{fns[0]}') shell(f'chmod +x {_bin}{fns[0]}') run() Bash Script I suggest adding to UserScripts with Schedule set to "At First Array Start Only" Change "/mnt/user/projects/scripts" to wherever you save the python script Change "installScripts.py" to whatever you name the python script #!/bin/bash cd /mnt/user/projects/scripts python3 installScripts.py Edited May 7, 2022 by c0d3m0nk3y Typos Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.