-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.py
100 lines (87 loc) · 3.84 KB
/
install.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import yaml, os, shutil, sys, subprocess, colorama
def get_choice():
while True:
choice = input("Choose Installation:\n 1 Native installation\n 2 Installation as container ")
#depending on the shell the input might be either int or string
if choice == 1 or choice == "1":
print("Installing natively...")
return 1
if choice == 2 or choice == "2":
print("Installing as container...")
return 2
def main():
#python 3.* is needed for input() to work as needed
if sys.version_info.major < 3:
raise Exception("Must be using Python 3")
db_path = ""
log_path = ""
prefix = ""
entrypoint = "" #entrypoint directory for the indexing
while not os.path.exists(entrypoint):
entrypoint = input("Please enter the entry point for the indexer: ")
installation = "native" #this value is never used and is just to verify from the config which installation was chosen
config_dir = "/var/lib/file_index_search/"
scripts_dir = "/usr/local/bin/"
indexer = "file_indexer.py"
searcher = "file_search.py"
if get_choice() == 1:
#move executable file_indexer
os.rename(indexer, indexer[:-3]) #remove file extension
indexer = indexer[:-3]
os.chmod(indexer, 0o744)
#if the script is run without enough permission, rerunning will break on the next run because filenames already changed
try:
#move to directory included in PATH
shutil.move(indexer, scripts_dir)
except shutil.Error:
os.remove(os.path.join(scripts_dir, indexer))
shutil.move(indexer, scripts_dir)
except Exception as e:
print(e)
sys.exit("Couldn't move the python files to the destination directory")
#location where database and logs are saved
db_dir = ""
while not os.path.exists(db_dir):
db_dir = input("Please enter the directory path for the database and log: ")
db_path = os.path.join(db_dir, "files.db")
log_path = os.path.join(db_dir, "status.log")
else:
#just create logs for container installation
#when it is run as a container, db_path and log_path aren't needed for the indexer itself
db_path = "/var/lib/docker/volumes/files-db/_data/files.db"
log_path = "/var/lib/docker/volumes/files-db/_data/status.log"
entrypoint = "/host" + entrypoint
prefix = "/host"
installation = "container"
subprocess.call(["docker", "build", "-t", "indexer", "."])
print("Run")
print(colorama.Fore.YELLOW + 'docker run -v /etc/localtime:/etc/localtime:ro --mount source=files-db,target=\"/etc/files-index\" --mount type=bind,source=\"/\",target=\"/host\",readonly indexer')
print(colorama.Style.RESET_ALL + "to use the indexer.")
#move executable file_search
#remove file extension
os.rename(searcher, searcher[:-3])
searcher = searcher[:-3]
os.chmod(searcher, 0o744)
try:
#move to directory included in PATH
shutil.move(searcher, scripts_dir)
except shutil.Error:
os.remove(os.path.join(scripts_dir, searcher))
shutil.move(searcher, scripts_dir)
except Exception as e:
print(e)
sys.exit("Couldn't move the python files to the destination directory")
data = dict()
data["installation"] = installation
data["db_path"] = db_path
data["log_path"] = log_path
data["entrypoint"] = entrypoint
data["prefix"] = prefix
#data = { "db_path": db_path, "log_path": log_path, "entrypoint": entrypoint }
if not os.path.isdir(config_dir):
os.mkdir(config_dir)
with open(config_dir + "config.yaml", "w") as config:
yaml.dump(data, config)
print("Finished")
if __name__ == "__main__":
main()