port-jobs: Added port-job for removing the need for os-detection via os.uname()

Former-commit-id: 640dd6a448fc9df35a20ec253e1498b142a47a04
Former-commit-id: e66d00a8bce55319c9310835b1d2963531ca34ca
This commit is contained in:
2023-04-24 11:38:17 -04:00
parent c26975bdab
commit 3c877d6e4a
3 changed files with 60 additions and 2 deletions
+7 -2
View File
@@ -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
+6
View File
@@ -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
+47
View File
@@ -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)