diff --git a/lib/sshyp.py b/lib/sshyp.py index a9d5cb7..2c780d7 100755 --- a/lib/sshyp.py +++ b/lib/sshyp.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -from os import chmod, environ, listdir, remove, uname, walk +from os import chmod, environ, listdir, remove, walk from os.path import exists, expanduser, isdir, isfile, realpath from pathlib import Path from random import randint @@ -7,6 +7,9 @@ from shutil import get_terminal_size, move, rmtree from sshync import delete as offline_delete, run_profile, make_profile, get_profile from subprocess import CalledProcessError, DEVNULL, PIPE, run from sys import argv, exit as s_exit +# PORT START UNAME-IMPORT +from os import uname +# PORT END UNAME-IMPORT home = expanduser("~") @@ -208,18 +211,20 @@ def copy_id_check(_port, _username_ssh, _ip, _client_device_id): # ARGUMENT-SPECIFIC FUNCTIONS # runs configuration wizard def tweak(): - from os import symlink _divider = f"\n{'=' * (get_terminal_size()[0] - int((.5 * get_terminal_size()[0])))}\n\n" # config directory creation Path(f"{home}/.config/sshyp/devices").mkdir(mode=0o700, parents=True, exist_ok=True) if not exists(f"{home}/.config/sshyp/tmp"): + from os import symlink + # PORT START UNAME-TMP if uname()[0] in ('Haiku', 'FreeBSD', 'Darwin'): symlink('/tmp', f"{home}/.config/sshyp/tmp") elif exists('/data/data/com.termux'): symlink('/data/data/com.termux/files/usr/tmp', f"{home}/.config/sshyp/tmp") else: symlink('/dev/shm', f"{home}/.config/sshyp/tmp") + # PORT END UNAME-TMP # PORT START TWEAK-DEVTYPE # device type configuration diff --git a/package.sh b/package.sh index c1e2875..edf540d 100755 --- a/package.sh +++ b/package.sh @@ -37,6 +37,7 @@ _create_generic_linux() { cp -r lib/. port-jobs/working/ cd port-jobs ./CLIPBOARD.py LINUX + ./UNAME.py LINUX ./COMMENTS.py ALL ./BLANKS.py ./TABS.sh TABS @@ -149,6 +150,7 @@ urls { ./RMSERVER.py ./CLIPBOARD.py HAIKU ./COMMENTS.py ALL + ./UNAME.py TMP ./BLANKS.py ./TABS.sh TABS cd .. @@ -206,6 +208,7 @@ Installed-Size: 71680 ./CLIPBOARD.py WSL special=WSL-ONLY-UBUNTU fi + ./UNAME.py LINUX ./COMMENTS.py ALL ./BLANKS.py ./TABS.sh TABS @@ -247,6 +250,7 @@ Installed-Size: 71680 cp -r lib/. port-jobs/working/ cd port-jobs ./CLIPBOARD.py TERMUX + ./UNAME.py TERMUX ./COMMENTS.py ALL ./BLANKS.py ./TABS.sh TABS @@ -304,6 +308,7 @@ cp -r %%{_sourcedir}/usr %%{buildroot} cp -r lib/. port-jobs/working/ cd port-jobs ./CLIPBOARD.py LINUX + ./UNAME.py LINUX ./COMMENTS.py ALL ./BLANKS.py ./TABS.sh TABS @@ -370,6 +375,7 @@ printf "/usr/bin/sshyp cp -r lib/. port-jobs/working/ cd port-jobs ./CLIPBOARD.py TERMUX + ./UNAME.py TMP ./COMMENTS.py ALL ./BLANKS.py ./TABS.sh TABS diff --git a/port-jobs/UNAME.py b/port-jobs/UNAME.py new file mode 100755 index 0000000..6a2eb33 --- /dev/null +++ b/port-jobs/UNAME.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 +import re +from sys import argv, exit as s_exit + +# read arguments +arguments = argv[1:] + +# define replacement text depending on arguments +if len(arguments) > 0: + if arguments[0] == 'TMP': + replacement = 'symlink("/tmp", f"{home}/.config/sshyp/tmp")' + elif arguments[0] == 'TERMUX': + replacement = 'symlink("/data/data/com.termux/files/usr/tmp", f"{home}/.config/sshyp/tmp")' + elif arguments[0] == 'LINUX': + replacement = 'symlink("/dev/shm", f"{home}/.config/sshyp/tmp")' +else: + s_exit() + +# UNAME-IMPORT +# define PORT target +string1 = '# PORT START UNAME-IMPORT' +string2 = '# PORT END UNAME-IMPORT' + +# read input file +text = open('working/sshyp.py', 'r').read() + +# find and replace the defined PORT target +regex = re.compile(f"{string1}.*?{string2}\n", re.DOTALL) +new_text = re.sub(regex, '', text) + +# write updated text +open('working/sshyp.py', 'w').write(new_text) + +# UNAME-TMP +# define PORT target +string1 = '# PORT START UNAME-TMP' +string2 = '# PORT END UNAME-TMP' + +# read input file +text = open('working/sshyp.py', 'r').read() + +# find and replace the defined PORT target +regex = re.compile(f"{string1}.*?{string2}", re.DOTALL) +new_text = re.sub(regex, replacement, text) + +# write updated text +open('working/sshyp.py', 'w').write(new_text)