forked from fosskers/aura
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakePkg.hs
37 lines (30 loc) · 1.29 KB
/
MakePkg.hs
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
module MakePkg where
-- System Libraries
import System.Directory (getDirectoryContents)
import Text.Regex.Posix ((=~))
import System.Exit (ExitCode)
-- Custom Libraries
import Shell
makepkg :: String -> IO (ExitCode,FilePath,String)
makepkg = makepkgQuiet
-- This should to be used as non-root.
-- Building packages as root IS NOT safe!
makepkgGen :: (String -> [String] -> IO (ExitCode,String,String)) ->
String -> IO (ExitCode,FilePath,String)
makepkgGen f user = do
(exitStatus,out,err) <- f command opts
contents <- getDirectoryContents "." -- I don't like this relative path.
let pkgFiles = filter (\file -> (file =~ ".pkg.tar.xz")) contents
pkgName = if null pkgFiles then "" else head pkgFiles
return $ (exitStatus,pkgName,err ++ "\n" ++ out)
where (command,opts) = determineRunStyle user
determineRunStyle :: String -> (String,[String])
determineRunStyle "root" = ("makepkg",["--asroot"])
determineRunStyle user = ("su",[user,"-c","makepkg"])
makepkgQuiet :: String -> IO (ExitCode,FilePath,String)
makepkgQuiet user = makepkgGen quietShellCmd' user
makepkgVerbose :: String -> IO (ExitCode,FilePath,String)
makepkgVerbose user = makepkgGen shellCmd' user
where shellCmd' cmd opts = do
exitStatus <- shellCmd cmd opts
return (exitStatus,"","")