2023-05-03 20:31:54 +00:00
|
|
|
from os import mkdir
|
|
|
|
from os.path import exists
|
|
|
|
from os.path import join as path_join
|
2016-06-09 03:44:45 +00:00
|
|
|
import shutil
|
2023-09-20 04:09:25 +00:00
|
|
|
from nxc.paths import NXC_PATH, CONFIG_PATH, TMP_PATH, DATA_PATH
|
2023-09-14 21:07:15 +00:00
|
|
|
from nxc.nxcdb import initialize_db
|
|
|
|
from nxc.logger import nxc_logger
|
2016-06-04 05:42:26 +00:00
|
|
|
|
2018-03-01 19:36:17 +00:00
|
|
|
|
2023-09-14 21:07:15 +00:00
|
|
|
def first_run_setup(logger=nxc_logger):
|
2023-05-03 20:31:54 +00:00
|
|
|
if not exists(TMP_PATH):
|
|
|
|
mkdir(TMP_PATH)
|
2016-09-12 06:52:50 +00:00
|
|
|
|
2023-09-20 04:09:25 +00:00
|
|
|
if not exists(NXC_PATH):
|
2023-05-02 15:17:59 +00:00
|
|
|
logger.display("First time use detected")
|
|
|
|
logger.display("Creating home directory structure")
|
2023-09-20 04:09:25 +00:00
|
|
|
mkdir(NXC_PATH)
|
2017-03-27 21:09:36 +00:00
|
|
|
|
2023-05-03 20:31:54 +00:00
|
|
|
folders = (
|
2023-05-02 15:17:59 +00:00
|
|
|
"logs",
|
|
|
|
"modules",
|
|
|
|
"protocols",
|
|
|
|
"workspaces",
|
|
|
|
"obfuscated_scripts",
|
|
|
|
"screenshots",
|
2023-05-03 20:31:54 +00:00
|
|
|
)
|
2017-03-27 21:09:36 +00:00
|
|
|
for folder in folders:
|
2023-09-20 04:09:25 +00:00
|
|
|
if not exists(path_join(NXC_PATH, folder)):
|
2023-04-12 04:25:38 +00:00
|
|
|
logger.display(f"Creating missing folder {folder}")
|
2023-09-20 04:09:25 +00:00
|
|
|
mkdir(path_join(NXC_PATH, folder))
|
2016-06-04 05:42:26 +00:00
|
|
|
|
2023-03-02 16:01:29 +00:00
|
|
|
initialize_db(logger)
|
2016-06-04 05:42:26 +00:00
|
|
|
|
2023-05-03 20:31:54 +00:00
|
|
|
if not exists(CONFIG_PATH):
|
2023-05-02 15:17:59 +00:00
|
|
|
logger.display("Copying default configuration file")
|
2023-09-14 21:07:15 +00:00
|
|
|
default_path = path_join(DATA_PATH, "nxc.conf")
|
2023-09-20 04:09:25 +00:00
|
|
|
shutil.copy(default_path, NXC_PATH)
|
2016-06-09 03:44:45 +00:00
|
|
|
|
2023-05-03 20:31:54 +00:00
|
|
|
# if not exists(CERT_PATH):
|
2023-01-02 11:55:03 +00:00
|
|
|
# if os.name != 'nt':
|
|
|
|
# if e.errno == errno.ENOENT:
|