summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJensPetersen <>2021-04-07 14:38:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2021-04-07 14:38:00 (GMT)
commit7715ef81a68b66d83b2e20e306fc6be82b0a1d5c (patch)
treea51d546a86f111a9f871a59bde8adb81b764c8c4
parent6493289148b7d8bb0846808b7e0d95abfa3ad38c (diff)
version 0.8HEAD0.8master
-rw-r--r--CHANGELOG.md4
-rw-r--r--README.md7
-rw-r--r--dl-fedora.cabal2
-rw-r--r--src/Main.hs85
-rw-r--r--test/tests.hs4
5 files changed, 71 insertions, 31 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ca99c47..72c77bc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog
+## 0.8 (2021-04-07)
+- --local option: print (or --run) current local image instead of newer download
+- improve --dryrun Downloads/ handling for testsuite in CI
+
## 0.7.7 (2021-04-06)
- add the new F34 i3 spin
- shorten mate_compiz to mate
diff --git a/README.md b/README.md
index 6cbd009..3bf4144 100644
--- a/README.md
+++ b/README.md
@@ -21,8 +21,11 @@ Usage examples:
`dl-fedora --run 34` : will download Fedora 34 Workstation and boot the Live image with qemu-kvm.
-By default dl-fedora downloads to `~/Downloads/`, but if you create
-`~/Downloads/iso/` it will use that directory instead.
+`dl-fedora --local rawhide` : shows the current locally available image (as well as the latest one).
+
+By default dl-fedora downloads to `~/Downloads/`
+(correctly the XDG user "DOWNLOADS" directory),
+but if you create `~/Downloads/iso/` it will use that directory instead.
If the image is already found to be downloaded
it will not be downloaded again of course.
diff --git a/dl-fedora.cabal b/dl-fedora.cabal
index 201e1a6..f476156 100644
--- a/dl-fedora.cabal
+++ b/dl-fedora.cabal
@@ -1,6 +1,6 @@
cabal-version: 1.18
name: dl-fedora
-version: 0.7.7
+version: 0.8
synopsis: Fedora image download tool
description: Tool to download Fedora iso and image files
-- can change to GPL-3.0-or-later with Cabal-2.2
diff --git a/src/Main.hs b/src/Main.hs
index 449ecd8..dfa69ca 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -45,7 +45,6 @@ import qualified Text.ParserCombinators.ReadP as R
import qualified Text.ParserCombinators.ReadPrec as RP
import Text.Regex.Posix
-{-# ANN module "HLint: ignore Use camelCase" #-}
data FedoraEdition = Cloud
| Container
| Everything
@@ -110,6 +109,7 @@ main = do
<$> switchWith 'g' "gpg-keys" "Import Fedora GPG keys for verifying checksum file"
<*> checkSumOpts
<*> switchWith 'n' "dry-run" "Don't actually download anything"
+ <*> switchWith 'l' "local" "Show current local image via symlink"
<*> switchWith 'r' "run" "Boot image in Qemu"
<*> switchWith 'R' "replace" "Delete old image after downloading new one"
<*> optional mirrorOpt
@@ -127,8 +127,8 @@ main = do
flagWith' NoCheckSum 'C' "no-checksum" "Do not check checksum" <|>
flagWith AutoCheckSum CheckSum 'c' "checksum" "Do checksum even if already downloaded"
-program :: Bool -> CheckSum -> Bool -> Bool -> Bool -> Maybe String -> String -> FedoraEdition -> String -> IO ()
-program gpg checksum dryrun run removeold mmirror arch edition tgtrel = do
+program :: Bool -> CheckSum -> Bool -> Bool -> Bool -> Bool -> Maybe String -> String -> FedoraEdition -> String -> IO ()
+program gpg checksum dryrun local run removeold mmirror arch edition tgtrel = do
let mirror =
case mmirror of
Nothing | tgtrel == "koji" -> kojiPkgs
@@ -143,12 +143,20 @@ program gpg checksum dryrun run removeold mmirror arch edition tgtrel = do
let path = makeRelative home dlDir in
if isRelative path then "~" </> path else path
(fileurl, filenamePrefix, (masterUrl,masterSize), mchecksum, done) <- findURL mgr mirror showdestdir
- downloadFile done mgr fileurl (masterUrl,masterSize) >>= fileChecksum mgr mchecksum showdestdir
+ unless local $
+ downloadFile done mgr fileurl (masterUrl,masterSize) >>= fileChecksum mgr mchecksum showdestdir
unless dryrun $ do
- let localfile = takeFileName fileurl
- symlink = filenamePrefix <> (if tgtrel == "eln" then "-" <> arch else "") <> "-latest" <.> takeExtension fileurl
- updateSymlink localfile symlink showdestdir
- when run $ bootImage localfile showdestdir
+ let symlink = filenamePrefix <> (if tgtrel == "eln" then "-" <> arch else "") <> "-latest" <.> takeExtension fileurl
+ if local
+ then if run
+ then bootImage symlink showdestdir
+ else do
+ putStrLn $ "Latest: " ++ takeFileName fileurl ++ "\n"
+ showSymlink symlink showdestdir
+ else do
+ let localfile = takeFileName fileurl
+ updateSymlink localfile symlink showdestdir
+ when run $ bootImage localfile showdestdir
where
setDownloadDir home = do
dlDir <- getUserDir "DOWNLOAD"
@@ -156,12 +164,24 @@ program gpg checksum dryrun run removeold mmirror arch edition tgtrel = do
unless (dryrun || dirExists) $
when (home == dlDir) $
error' "HOME directory does not exist!"
- dlIsoDir <- let isodir = dlDir </> "iso" in
- ifM (doesDirectoryExist isodir) (return isodir) $ do
- unless (dirExists || dryrun) $ createDirectoryIfMissing True dlDir
- return dlDir
- setCurrentDirectory dlIsoDir
- return dlIsoDir
+ let isoDir = dlDir </> "iso"
+ isoExists <- doesDirectoryExist isoDir
+ if isoExists
+ then setCWD isoDir
+ else
+ if dirExists
+ then setCWD dlDir
+ else do
+ if dryrun
+ then return dlDir
+ else do
+ createDirectoryIfMissing True dlDir
+ setCWD dlDir
+
+ setCWD :: FilePath -> IO FilePath
+ setCWD dir = do
+ setCurrentDirectory dir
+ return dir
-- urlpath, fileprefix, (master,size), checksum, downloaded
findURL :: Manager -> String -> String -> IO (URL, String, (URL,Maybe Integer), Maybe String, Bool)
@@ -201,7 +221,7 @@ program gpg checksum dryrun run removeold mmirror arch edition tgtrel = do
findMirror masterUrl path file
else findMirror masterUrl path file
mlocaltime <- httpTimestamp masterUrl
- unless (run && already) $
+ unless (run && already || local) $
maybe (return ()) putStrLn $ showMSize masterSize <> showMDate mlocaltime
let finalDir = dropFileName finalurl
return (finalurl, prefix, (masterUrl,masterSize), (finalDir </>) . T.unpack <$> mchecksum, already)
@@ -318,36 +338,38 @@ program gpg checksum dryrun run removeold mmirror arch edition tgtrel = do
in
intercalate "-" (["Fedora", showEdition edition, editionType edition] ++ middle)
- downloadFile :: Bool -> Manager -> URL -> (URL, Maybe Integer) -> IO Bool
+ downloadFile :: Bool -> Manager -> URL -> (URL, Maybe Integer)
+ -> IO (Maybe Bool)
downloadFile done mgr url (masterUrl,masterSize) =
if done
- then return False
+ then return (Just False)
else do
when (url /= masterUrl) $ do
mirrorSize <- httpFileSize mgr url
unless (mirrorSize == masterSize) $
putStrLn "Warning! Mirror filesize differs from master file"
- putStrLn url
- if dryrun then return False
+ unless local $ putStrLn url
+ if dryrun || local then return Nothing
else do
cmd_ "curl" ["-C", "-", "-O", url]
- return True
+ return (Just True)
- fileChecksum :: Manager -> Maybe URL -> String -> Bool -> IO ()
+ fileChecksum :: Manager -> Maybe URL -> String -> Maybe Bool -> IO ()
fileChecksum _ Nothing _ _ = return ()
- fileChecksum mgr (Just url) showdestdir needChecksum =
- when ((needChecksum && checksum /= NoCheckSum) || checksum == CheckSum) $ do
+ fileChecksum mgr (Just url) showdestdir mneedChecksum =
+ when ((mneedChecksum == Just True && checksum /= NoCheckSum) || (isJust mneedChecksum && checksum == CheckSum)) $ do
let checksumdir = ".dl-fedora-checksums"
checksumfile = checksumdir </> takeFileName url
exists <- do
dirExists <- doesDirectoryExist checksumdir
- if dirExists then checkChecksumfile mgr url checksumfile showdestdir
+ if dirExists
+ then checkChecksumfile mgr url checksumfile showdestdir
else createDirectory checksumdir >> return False
putStrLn ""
unless exists $
whenM (httpExists mgr url) $
- withCurrentDirectory checksumdir $
- cmd_ "curl" ["-C", "-", "-s", "-S", "-O", url]
+ withCurrentDirectory checksumdir $
+ cmd_ "curl" ["-C", "-", "-s", "-S", "-O", url]
haveChksum <- doesFileExist checksumfile
if not haveChksum
then putStrLn "No checksum file found"
@@ -412,6 +434,17 @@ program gpg checksum dryrun run removeold mmirror arch edition tgtrel = do
createSymbolicLink target symlink
putStrLn $ unwords [showdestdir </> symlink, "->", target]
+ showSymlink :: FilePath -> FilePath -> IO ()
+ showSymlink symlink showdestdir = do
+ msymlinkTarget <- do
+ havefile <- doesFileExist symlink
+ if havefile
+ then Just <$> readSymbolicLink symlink
+ else return Nothing
+ case msymlinkTarget of
+ Just symlinktarget -> putStrLn $ showdestdir </> symlinktarget
+ _ -> return ()
+
editionType :: FedoraEdition -> String
editionType Server = "dvd"
editionType Silverblue = "ostree"
diff --git a/test/tests.hs b/test/tests.hs
index fb7b6ad..884b012 100644
--- a/test/tests.hs
+++ b/test/tests.hs
@@ -9,11 +9,11 @@ tests =
[["-n", "33", "-c"]
,["-n", "rawhide", "-e", "silverblue"]
,["-n", "34", "-e", "silverblue"]
- ,["respin"]
+ ,["-n", "respin"]
,["-n", "32", "-e", "kde"]
,["-n", "33", "-e", "everything"]
,["-n", "33", "-e", "server", "--arch", "aarch64"]
- ,["-n", "34"]
+ ,["-l", "34"]
]
main :: IO ()