Update environment variables to support custom data directory
This commit is contained in:
@ -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")
|
||||
|
@ -11,7 +11,6 @@ import Control.Monad.Trans (liftIO)
|
||||
import Data.Maybe (Maybe (Nothing))
|
||||
import Network.Wai.Middleware.RequestLogger (logStdoutDev)
|
||||
import Network.Wai.Middleware.Static
|
||||
import System.Environment
|
||||
import Web.Scotty
|
||||
|
||||
app :: PurrApp ()
|
||||
|
@ -23,6 +23,3 @@ main = do
|
||||
\ views INT,\
|
||||
\ maxViews INT)"
|
||||
close conn
|
||||
|
||||
encKey :: IO ByteString
|
||||
encKey = B.readFile "./data/encryptionKey"
|
||||
|
@ -12,7 +12,6 @@ import Control.Monad.Trans (liftIO)
|
||||
import Data.List.Split (splitOn)
|
||||
import Data.Maybe (listToMaybe)
|
||||
import Prelude
|
||||
import System.Environment
|
||||
import Web.Scotty
|
||||
|
||||
import qualified Data.Text as T
|
||||
|
@ -13,8 +13,8 @@ import Web.Scotty
|
||||
main :: IO ()
|
||||
main = do
|
||||
sodiumInit
|
||||
Configuration.keyFileInit
|
||||
Configuration.main
|
||||
Configuration.keyFileInit
|
||||
DB.main
|
||||
appPortStr <- Configuration.appPort
|
||||
let appPort = read appPortStr :: Int
|
||||
|
Reference in New Issue
Block a user