mirror of
https://github.com/rwinkhart/sshyp.git
synced 2026-09-02 07:07:18 -04:00
Former-commit-id: 511d1d887fb34b8613f063fc7992418bb614a740 Former-commit-id: 03f6817527864c52012de1d02bb2c34e8fed8a18
63 lines
1.7 KiB
Python
Executable File
63 lines
1.7 KiB
Python
Executable File
#!/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-SSHYP
|
|
# define PORT target
|
|
string1 = '# PORT START UNAME-IMPORT-SSHYP'
|
|
string2 = '# PORT END UNAME-IMPORT-SSHYP'
|
|
|
|
# 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-IMPORT-STWEAK
|
|
# define PORT target
|
|
string1 = '# PORT START UNAME-IMPORT-STWEAK'
|
|
string2 = '# PORT END UNAME-IMPORT-STWEAK'
|
|
|
|
# read input file
|
|
text = open('working/stweak.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/stweak.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/stweak.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/stweak.py', 'w').write(new_text)
|