mirror of
https://github.com/rwinkhart/sshyp.git
synced 2026-09-05 08:37:14 -04:00
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:
+7
-2
@@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env python3
|
#!/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 os.path import exists, expanduser, isdir, isfile, realpath
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from random import randint
|
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 sshync import delete as offline_delete, run_profile, make_profile, get_profile
|
||||||
from subprocess import CalledProcessError, DEVNULL, PIPE, run
|
from subprocess import CalledProcessError, DEVNULL, PIPE, run
|
||||||
from sys import argv, exit as s_exit
|
from sys import argv, exit as s_exit
|
||||||
|
# PORT START UNAME-IMPORT
|
||||||
|
from os import uname
|
||||||
|
# PORT END UNAME-IMPORT
|
||||||
home = expanduser("~")
|
home = expanduser("~")
|
||||||
|
|
||||||
|
|
||||||
@@ -208,18 +211,20 @@ def copy_id_check(_port, _username_ssh, _ip, _client_device_id):
|
|||||||
# ARGUMENT-SPECIFIC FUNCTIONS
|
# ARGUMENT-SPECIFIC FUNCTIONS
|
||||||
# runs configuration wizard
|
# runs configuration wizard
|
||||||
def tweak():
|
def tweak():
|
||||||
from os import symlink
|
|
||||||
_divider = f"\n{'=' * (get_terminal_size()[0] - int((.5 * get_terminal_size()[0])))}\n\n"
|
_divider = f"\n{'=' * (get_terminal_size()[0] - int((.5 * get_terminal_size()[0])))}\n\n"
|
||||||
|
|
||||||
# config directory creation
|
# config directory creation
|
||||||
Path(f"{home}/.config/sshyp/devices").mkdir(mode=0o700, parents=True, exist_ok=True)
|
Path(f"{home}/.config/sshyp/devices").mkdir(mode=0o700, parents=True, exist_ok=True)
|
||||||
if not exists(f"{home}/.config/sshyp/tmp"):
|
if not exists(f"{home}/.config/sshyp/tmp"):
|
||||||
|
from os import symlink
|
||||||
|
# PORT START UNAME-TMP
|
||||||
if uname()[0] in ('Haiku', 'FreeBSD', 'Darwin'):
|
if uname()[0] in ('Haiku', 'FreeBSD', 'Darwin'):
|
||||||
symlink('/tmp', f"{home}/.config/sshyp/tmp")
|
symlink('/tmp', f"{home}/.config/sshyp/tmp")
|
||||||
elif exists('/data/data/com.termux'):
|
elif exists('/data/data/com.termux'):
|
||||||
symlink('/data/data/com.termux/files/usr/tmp', f"{home}/.config/sshyp/tmp")
|
symlink('/data/data/com.termux/files/usr/tmp', f"{home}/.config/sshyp/tmp")
|
||||||
else:
|
else:
|
||||||
symlink('/dev/shm', f"{home}/.config/sshyp/tmp")
|
symlink('/dev/shm', f"{home}/.config/sshyp/tmp")
|
||||||
|
# PORT END UNAME-TMP
|
||||||
|
|
||||||
# PORT START TWEAK-DEVTYPE
|
# PORT START TWEAK-DEVTYPE
|
||||||
# device type configuration
|
# device type configuration
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ _create_generic_linux() {
|
|||||||
cp -r lib/. port-jobs/working/
|
cp -r lib/. port-jobs/working/
|
||||||
cd port-jobs
|
cd port-jobs
|
||||||
./CLIPBOARD.py LINUX
|
./CLIPBOARD.py LINUX
|
||||||
|
./UNAME.py LINUX
|
||||||
./COMMENTS.py ALL
|
./COMMENTS.py ALL
|
||||||
./BLANKS.py
|
./BLANKS.py
|
||||||
./TABS.sh TABS
|
./TABS.sh TABS
|
||||||
@@ -149,6 +150,7 @@ urls {
|
|||||||
./RMSERVER.py
|
./RMSERVER.py
|
||||||
./CLIPBOARD.py HAIKU
|
./CLIPBOARD.py HAIKU
|
||||||
./COMMENTS.py ALL
|
./COMMENTS.py ALL
|
||||||
|
./UNAME.py TMP
|
||||||
./BLANKS.py
|
./BLANKS.py
|
||||||
./TABS.sh TABS
|
./TABS.sh TABS
|
||||||
cd ..
|
cd ..
|
||||||
@@ -206,6 +208,7 @@ Installed-Size: 71680
|
|||||||
./CLIPBOARD.py WSL
|
./CLIPBOARD.py WSL
|
||||||
special=WSL-ONLY-UBUNTU
|
special=WSL-ONLY-UBUNTU
|
||||||
fi
|
fi
|
||||||
|
./UNAME.py LINUX
|
||||||
./COMMENTS.py ALL
|
./COMMENTS.py ALL
|
||||||
./BLANKS.py
|
./BLANKS.py
|
||||||
./TABS.sh TABS
|
./TABS.sh TABS
|
||||||
@@ -247,6 +250,7 @@ Installed-Size: 71680
|
|||||||
cp -r lib/. port-jobs/working/
|
cp -r lib/. port-jobs/working/
|
||||||
cd port-jobs
|
cd port-jobs
|
||||||
./CLIPBOARD.py TERMUX
|
./CLIPBOARD.py TERMUX
|
||||||
|
./UNAME.py TERMUX
|
||||||
./COMMENTS.py ALL
|
./COMMENTS.py ALL
|
||||||
./BLANKS.py
|
./BLANKS.py
|
||||||
./TABS.sh TABS
|
./TABS.sh TABS
|
||||||
@@ -304,6 +308,7 @@ cp -r %%{_sourcedir}/usr %%{buildroot}
|
|||||||
cp -r lib/. port-jobs/working/
|
cp -r lib/. port-jobs/working/
|
||||||
cd port-jobs
|
cd port-jobs
|
||||||
./CLIPBOARD.py LINUX
|
./CLIPBOARD.py LINUX
|
||||||
|
./UNAME.py LINUX
|
||||||
./COMMENTS.py ALL
|
./COMMENTS.py ALL
|
||||||
./BLANKS.py
|
./BLANKS.py
|
||||||
./TABS.sh TABS
|
./TABS.sh TABS
|
||||||
@@ -370,6 +375,7 @@ printf "/usr/bin/sshyp
|
|||||||
cp -r lib/. port-jobs/working/
|
cp -r lib/. port-jobs/working/
|
||||||
cd port-jobs
|
cd port-jobs
|
||||||
./CLIPBOARD.py TERMUX
|
./CLIPBOARD.py TERMUX
|
||||||
|
./UNAME.py TMP
|
||||||
./COMMENTS.py ALL
|
./COMMENTS.py ALL
|
||||||
./BLANKS.py
|
./BLANKS.py
|
||||||
./TABS.sh TABS
|
./TABS.sh TABS
|
||||||
|
|||||||
Executable
+47
@@ -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)
|
||||||
Reference in New Issue
Block a user