Skip to content

Commit

Permalink
First pass at a Python installer script
Browse files Browse the repository at this point in the history
  • Loading branch information
scottchiefbaker committed Sep 27, 2022
1 parent 23c9a74 commit 20590dc
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions install.py
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)

0 comments on commit 20590dc

Please sign in to comment.