forked from scottchiefbaker/dool
-
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.
First pass at a Python installer script
- Loading branch information
1 parent
23c9a74
commit 20590dc
Showing
1 changed file
with
79 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/usr/bin/python3 | ||
|
||
import sys | ||
import getopt | ||
import glob | ||
import os | ||
import shutil | ||
import pathlib | ||
|
||
base_dir = os.path.dirname(__file__) | ||
base_dir = base_dir or "." | ||
am_root = os.getuid() == 0 | ||
|
||
# Glob the files we need to install | ||
binaries = glob.glob(base_dir + "/dool") | ||
plugins = glob.glob(base_dir + "/plugins/*.py") | ||
manpages = glob.glob(base_dir + "/docs/dool.1") | ||
|
||
############################################################ | ||
|
||
def root_install(binaries, plugins, manpages): | ||
bindir = "/usr/bin/" | ||
plugin_dir = "/usr/share/dool/" | ||
manpage_dir = "/usr/share/man/man1/" | ||
|
||
ok = os.makedirs(bindir, exist_ok=True) | ||
ok = os.makedirs(plugin_dir, exist_ok=True) | ||
|
||
print("Installing binary in %s" % bindir) | ||
for x in binaries: | ||
file = os.path.basename(x) | ||
shutil.copyfile(x, bindir + "/" + file) | ||
os.chmod(bindir + "/" + file, 0o755) | ||
|
||
print("Installing plugins in %s" % plugin_dir) | ||
for x in plugins: | ||
file = os.path.basename(x) | ||
shutil.copyfile(x, plugin_dir + "/" + file) | ||
os.chmod(plugin_dir + "/" + file, 0o644) | ||
|
||
print("Installing manpages in %s" % manpage_dir) | ||
for x in manpages: | ||
file = os.path.basename(x) | ||
shutil.copyfile(x, manpage_dir + "/" + file) | ||
os.chmod(manpage_dir + "/" + file, 0o644) | ||
|
||
def user_install(binaries, plugins, manpages): | ||
homedir = os.path.expanduser("~/") | ||
bindir = homedir + "/bin/" | ||
plugin_dir = homedir + "/.dool/" | ||
|
||
bindir = bindir.replace("//", "/") | ||
plugin_dir = plugin_dir.replace("//", "/") | ||
|
||
ok = os.makedirs(bindir, exist_ok=True) | ||
ok = os.makedirs(plugin_dir, exist_ok=True) | ||
|
||
print("Installing binary in %s" % bindir) | ||
for x in binaries: | ||
file = os.path.basename(x) | ||
shutil.copyfile(x, bindir + "/" + file) | ||
os.chmod(bindir + "/" + file, 0o755) | ||
|
||
print("Installing plugins in %s" % plugin_dir) | ||
for x in plugins: | ||
file = os.path.basename(x) | ||
shutil.copyfile(x, plugin_dir + "/" + file) | ||
os.chmod(plugin_dir + "/" + file, 0o644) | ||
|
||
############################################################ | ||
|
||
if (am_root): | ||
print("You are root, doing a system wide install\n") | ||
|
||
root_install(binaries, plugins, manpages) | ||
else: | ||
print("You are a regular user, doing a local install\n") | ||
|
||
user_install(binaries, plugins, manpages) |