-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release 1.5.0
- Loading branch information
Showing
11 changed files
with
431 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
**/.pytest_cache/ | ||
**/.DS_Store | ||
.idea/ | ||
**/__pycache__ | ||
**/__pycache__ | ||
/.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
#!/usr/bin/python3 | ||
|
||
import sys | ||
import os | ||
from subprocess import call | ||
from shutil import which, rmtree | ||
|
||
columns = int(os.popen('stty size', 'r').read().split()[1]) | ||
|
||
def status(msg): | ||
"""Print Status Message. | ||
Prints "major" messages for the end user. | ||
Args: | ||
msg (str): Message to print. | ||
""" | ||
print("#"*int(columns*0.75)) | ||
print(msg) | ||
print("#"*int(columns*0.75)) | ||
|
||
|
||
def run(cmds): | ||
"""Run Command. | ||
A tiny function that simply uses 'call', and returns whether or not the call exited successfully. | ||
Args: | ||
cmds (str[]): The command list to pass to call() | ||
Returns: | ||
bool: Whether or not the call() succeeded. | ||
""" | ||
err = call(cmds) | ||
return err == 0 | ||
|
||
|
||
def install_package(pkg): | ||
"""Installs a Package. | ||
Installs the specified package using the distro's package manager. | ||
Currently supports the following package managers: | ||
* apt | ||
* apt-get | ||
* dnf | ||
* pacman | ||
Dictionary format: | ||
If a given package has a different name depending on the package manager (ie. Debian systems having 'python3-tk' | ||
while Arch systems having 'tk'), a dict can be used to specify that. | ||
Example: | ||
{"apt": "python3-tk", "dnf": "python3-tkinter", "pacman": "tk"} | ||
The above example will install the package "python3-tk" if the user is using apt OR apt-get, | ||
"python3-tkinter" if the user is using dnf, or "tk" if the user is using pacman. | ||
Args: | ||
pkg (str/dict): If a string, the package to install. See above for dictionary format. | ||
""" | ||
if type(pkg) is not str: | ||
if which("apt") is not None or which("apt-get") is not None: | ||
pkg = pkg["apt"] | ||
elif which("dnf") is not None: | ||
pkg = pkg["dnf"] | ||
elif which("pacman") is not None: | ||
pkg = pkg["pacman"] | ||
else: | ||
status("This script only supports automatic program installtion through apt(-get), dnf, and pip; please install {} manually!".format(pkg)) | ||
sys.exit(1) | ||
if which("apt") is not None: | ||
passed = run(["sudo", "apt", "install", pkg, "-y"]) | ||
elif which("apt-get") is not None: | ||
passed = run(["sudo", "apt-get", "install", pkg, "-y"]) | ||
elif which("dnf") is not None: | ||
passed = run(["sudo", "dnf", "install", pkg, "-y"]) | ||
elif which("pacman") is not None: | ||
passed = run(["sudo", "pacman", "-S", pkg, "--noconfirm"]) | ||
else: | ||
status("This script only supports automatic program installtion through apt(-get), dnf, and pip; please install {} manually!".format(pkg)) | ||
sys.exit(1) | ||
if not passed: | ||
status("Error installing package {}! Please install it manually, and/or read the error above for information how to resolve this error!".format(pkg)) | ||
sys.exit(1) | ||
|
||
|
||
def setup(): | ||
# Checks | ||
status("Checking for anything missing for tarstall setup") | ||
supported_package_managers = ["apt", "apt-get", "dnf", "pacman"] | ||
supported_shells = ["bash", "zsh"] | ||
if which("sudo") is None: | ||
status("Please install 'sudo'!") | ||
sys.exit(1) | ||
supported = False | ||
for manager in supported_package_managers: | ||
if which(manager) is not None: | ||
supported = True | ||
break | ||
if not supported: | ||
status("You currently don't have a supported package manager! Currently supported package managers are: " + ", ".join(supported_package_managers)) | ||
sys.exit(1) | ||
shell = os.environ["SHELL"] | ||
shell_supported = False | ||
for sshell in supported_shells: | ||
if sshell in shell: | ||
shell_supported = True | ||
break | ||
if not shell_supported: | ||
print(shell) | ||
msg = "WARNING: YOUR SHELL IS NOT SUPPORTED!\n\nYOU WILL HAVE TO MANUALLY ADD ~/.tarstall/tarstall_execs TO YOUR PATH, " \ | ||
"AND ANY PATH/BINLINK FUNCTIONS WILL NOT WORK!\nWOULD YOU LIKE TO PROCEED WITH INSTALLATION ANYWAYS?" | ||
status(msg) | ||
should_proceed = input("Type 'YES' to continue; anything else to exit... ") | ||
if should_proceed.lower() != "yes": | ||
status("Installation cancelled!") | ||
sys.exit(1) | ||
print("All of the checks passed!\n\n\n") | ||
|
||
# User information | ||
status("Welcome!\nThis installer is going to install tarstall! You'll need to enter your sudo password at some points. " + | ||
"This will use your distro's package manager along with pip to install the dependencies required for tarstall!") | ||
cancel = input("When you're ready to start installation, press ENTER! If you would like to cancel, type 'c', then press ENTER!") | ||
if cancel.lower() == 'c': | ||
status("Cancelling tarstall setup...") | ||
sys.exit() | ||
|
||
# Install git and wget | ||
status("Installing git and wget") | ||
install_package("git") | ||
install_package("wget") | ||
|
||
# Clone repository | ||
status("Getting a copy of tarstall") | ||
try: | ||
rmtree("/tmp/tarstall-setup") | ||
except FileNotFoundError: | ||
pass | ||
os.mkdir("/tmp/tarstall-setup") | ||
os.chdir("/tmp/tarstall-setup") | ||
if not run(["git", "clone", "https://github.com/hammy3502/tarstall.git"]): | ||
status("Error while getting the tarstall repository!") | ||
try: | ||
rmtree("/tmp/tarstall-setup") | ||
except FileNotFoundError: | ||
pass | ||
sys.exit(1) | ||
os.chdir("/tmp/tarstall-setup/tarstall") | ||
|
||
# Install requirements | ||
status("Installing tarstall's requirements") | ||
if not run([sys.executable, "-m", "pip", "install", "-r", "requirements.txt", "--user"]): | ||
install_package({"apt": "python3-pip", "dnf": "python3-pip", "pacman": "python-pip"}) | ||
if not run([sys.executable, "-m", "pip", "install", "-r", "requirements.txt", "--user"]) or not \ | ||
run([sys.executable, "-m", "pip", "install", "-r", "requirements-gui.txt", "--user"]): | ||
status("An error occured while installing the GUI requirements!") | ||
sys.exit(1) | ||
|
||
# Test tkinter (since we can't install it through pip) | ||
status("Installing tkinter") | ||
try: | ||
import tkinter | ||
del tkinter | ||
print("Thanks for having tkinter already installed!") | ||
except ImportError: | ||
install_package({"apt": "python3-tk", "dnf": "python3-tkinter", "pacman": "tk"}) | ||
|
||
# Pass control to tarstall | ||
status("Running tarstall installation") | ||
run([sys.executable, "./tarstall_execs/tarstall", "-f"]) | ||
|
||
# Removing tarstall setup directory | ||
try: | ||
rmtree("/tmp/tarstall-setup") | ||
except FileNotFoundError: | ||
pass | ||
|
||
if __name__ == "__main__": | ||
setup() |
Oops, something went wrong.