Update environment variables to support custom data directory

This commit is contained in:
2024-02-17 08:23:10 -06:00
parent 5484699565
commit dbe5cb2985
7 changed files with 30 additions and 35 deletions

View File

@@ -15,22 +15,31 @@ main = do
keyFileInit :: IO ()
keyFileInit = do
keyExists <- doesFileExist "./data/encryptionKey"
dataPathStr <- dataPath
keyExists <- doesFileExist $ dataPathStr ++ "data/encryptionKey"
case keyExists of
True -> putStrLn "Using existing key"
False -> do
key <- newKey
B.writeFile "./data/encryptionKey" (encode key)
B.writeFile (dataPathStr ++ "data/encryptionKey") (encode key)
putStrLn "Creating new encryption key; any pre-existing DB entries will not decrypt"
dbPath :: IO String
dbPath = getEnv "dbFile"
confLinkLength :: IO String
confLinkLength = getEnv "linkLength"
adminEmail :: IO String
adminEmail = getEnv "adminEmail"
adminEmail = getEnv "ADMINEMAIL"
appPort :: IO String
appPort = getEnv "applicationPort"
appPort = getEnv "APPLICATIONPORT"
dataPath :: IO String
dataPath = getEnv "DATADIR"
dbPath :: IO String
dbPath = getEnv "DBFILE"
confLinkLength :: IO String
confLinkLength = getEnv "LINKLENGTH"
encKey :: IO B.ByteString
encKey = do
dataPathStr <- dataPath
B.readFile (dataPathStr ++ "data/encryptionKey")