packages feed

dl-fedora 0.7.5 → 0.7.6

raw patch · 4 files changed

+75/−54 lines, 4 filesdep +extra

Dependencies added: extra

Files

CHANGELOG.md view
@@ -1,5 +1,10 @@ # Changelog +## 0.7.6 (2021-01-21)+- improve help text for releases related for Beta and RCs (#1)+- if ~/Downloads/iso/ exists then download to it otherwise ~/Downloads/+- support ELN boot.iso+ ## 0.7.5 (2020-09-13) - always print download url and already downloaded filename - --replace deletes previous symlinked image after downloading new one
Main.hs view
@@ -9,7 +9,7 @@ import Data.Semigroup ((<>)) #endif -import Control.Monad (when, unless)+import Control.Monad.Extra  import qualified Data.ByteString.Char8 as B import Data.Char (isDigit, toLower, toUpper)@@ -80,16 +80,17 @@ data CheckSum = AutoCheckSum | NoCheckSum | CheckSum   deriving Eq -dlFpo, downloadFpo, kojiPkgs:: String+dlFpo, downloadFpo, kojiPkgs, odcsFpo :: String dlFpo = "https://dl.fedoraproject.org/pub" downloadFpo = "https://download.fedoraproject.org/pub" kojiPkgs = "https://kojipkgs.fedoraproject.org/compose"+odcsFpo = "https://odcs.fedoraproject.org/composes"  main :: IO () main = do   let pdoc = Just $ P.vcat              [ P.text "Tool for downloading Fedora iso file images.",-               P.text ("RELEASE = " <> intercalate ", " ["release number", "respin", "rawhide", "test", "stage", "or koji"]),+               P.text ("RELEASE = " <> intercalate ", " ["release number", "respin", "rawhide", "test (Beta)", "stage (RC)", "eln", "or koji"]),                P.text "EDITION = " <> P.lbrace <> P.align (P.fillCat (P.punctuate P.comma (map (P.text . map toLower . show) [(minBound :: FedoraEdition)..maxBound])) <> P.rbrace),                P.text "",                P.text "See <https://fedoraproject.org/wiki/Infrastructure/MirrorManager>",@@ -110,7 +111,7 @@     mirrorOpt :: Parser String     mirrorOpt =       flagWith' dlFpo 'd' "dl" "Use dl.fedoraproject.org" <|>-      strOptionWith 'm' "mirror" "HOST" "Mirror url for /pub [default https://download.fedoraproject.org/pub]"+      strOptionWith 'm' "mirror" "HOST" ("Mirror url for /pub [default " ++ downloadFpo ++ "]")      checkSumOpts :: Parser CheckSum     checkSumOpts =@@ -122,40 +123,47 @@   let mirror =         case mmirror of           Nothing | tgtrel == "koji" -> kojiPkgs+          Nothing | tgtrel == "eln" -> odcsFpo           Nothing -> downloadFpo           Just _ | tgtrel == "koji" -> error' "Cannot specify mirror for koji"           Just m -> m   home <- getHomeDirectory-  dlDir <- getUserDir "DOWNLOAD"-  setDownloadDir dlDir home+  dlDir <- setDownloadDir home   mgr <- httpManager-  (fileurl, filenamePrefix, (masterUrl,masterSize), mchecksum, done) <- findURL mgr mirror-  downloadFile done mgr fileurl (masterUrl,masterSize) >>= fileChecksum mgr mchecksum+  let showdestdir =+        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 dryrun $ do     let localfile = takeFileName fileurl-        symlink = filenamePrefix <> "-latest" <.> takeExtension fileurl-        showdestdir =-          let path = makeRelative home dlDir in-            if isRelative path then "~" </> path else path+        symlink = filenamePrefix <> (if tgtrel == "eln" then "-" <> arch else "") <> "-latest" <.> takeExtension fileurl     updateSymlink localfile symlink showdestdir     when run $ bootImage localfile showdestdir   where-    setDownloadDir dlDir home = do+    setDownloadDir home = do+      dlDir <- getUserDir "DOWNLOAD"       dirExists <- doesDirectoryExist dlDir       unless (dryrun || dirExists) $         when (home == dlDir) $           error' "HOME directory does not exist!"-      unless (dirExists || dryrun) $ createDirectoryIfMissing True dlDir-      dirExists' <- if dirExists then return True-                    else doesDirectoryExist dlDir-      when dirExists' $ setCurrentDirectory dlDir+      dlIsoDir <- let isodir = dlDir </> "iso" in+        ifM (doesDirectoryExist isodir) (return isodir) $ do+        unless (dirExists || dryrun) $ createDirectoryIfMissing True dlDir+        return dlDir+      setCurrentDirectory dlIsoDir+      return dlIsoDir      -- urlpath, fileprefix, (master,size), checksum, downloaded-    findURL :: Manager -> String -> IO (URL, String, (URL,Maybe Integer), Maybe String, Bool)-    findURL mgr mirror = do+    findURL :: Manager -> String -> String -> IO (URL, String, (URL,Maybe Integer), Maybe String, Bool)+    findURL mgr mirror showdestdir = do       (path,mrelease) <- urlPathMRel mgr       -- use http-directory trailingSlash (0.1.7)-      let masterDir = (if tgtrel == "koji" then kojiPkgs else dlFpo) </> path <> "/"+      let masterDir =+            (case tgtrel of+               "koji" -> kojiPkgs+               "eln" -> odcsFpo+               _ -> dlFpo) </> path <> "/"       hrefs <- httpDirectory mgr masterDir       let prefixPat = makeFilePrefix mrelease           selector = if '*' `elem` prefixPat then (=~ prefixPat) else (prefixPat `isPrefixOf`)@@ -166,7 +174,7 @@           error' $ "no match for " <> prefixPat <> " in " <> masterDir         Just file -> do           let prefix = if '*' `elem` prefixPat-                       then file =~ prefixPat+                       then (file =~ prefixPat) ++ if arch `isInfixOf` prefixPat then "" else arch                        else prefixPat               masterUrl = masterDir </> file           masterSize <- httpFileSize mgr masterUrl@@ -175,12 +183,11 @@             exists <- doesFileExist localfile             if exists               then do-              done <- checkLocalFileSize localfile masterSize+              done <- checkLocalFileSize localfile masterSize showdestdir               if done                 then return (masterUrl,True)                 else do-                canwrite <- writable <$> getPermissions localfile-                unless canwrite $+                unlessM (writable <$> getPermissions localfile) $                   error' $ localfile <> " does have write permission, aborting!"                 findMirror masterUrl path file               else findMirror masterUrl path file@@ -201,7 +208,7 @@            findMirror masterUrl path file = do             url <--              if mirror `elem` [dlFpo,kojiPkgs] then return masterUrl+              if mirror `elem` [dlFpo,kojiPkgs,odcsFpo] then return masterUrl                 else                 if mirror /= downloadFpo then return $ mirror </> path                 else do@@ -215,12 +222,12 @@                         else return masterUrl             return (url,False) -    checkLocalFileSize localfile masterSize = do+    checkLocalFileSize localfile masterSize showdestdir = do       localsize <- toInteger . fileSize <$> getFileStatus localfile       if Just localsize == masterSize         then do         when (not run && takeExtension localfile == ".iso") $-          putStrLn $ localfile <> " already fully downloaded"+          putStrLn $ showdestdir </> localfile         return True         else do         let showsize =@@ -241,6 +248,7 @@         "rawhide" -> return ("fedora/linux/development/rawhide" </> subdir, Just "Rawhide")         "test" -> testRelease mgr subdir         "stage" -> stageRelease mgr subdir+        "eln" -> return ("production/latest-Fedora-ELN/compose" </> "Everything" </> arch </> "iso", Nothing)         "koji" -> kojiCompose mgr subdir         rel | all isDigit rel -> released mgr rel subdir         _ -> error' "Unknown release"@@ -288,16 +296,18 @@      makeFilePrefix :: Maybe String -> String     makeFilePrefix mrelease =-      if tgtrel == "respin" then "F[1-9][0-9]*-" <> liveRespin edition <> "-x86_64" <> "-LIVE"-      else-        let showRel r = if last r == '/' then init r else r-            rel = maybeToList (showRel <$> mrelease)-            middle =-              if edition `elem` [Cloud, Container]-              then rel ++ [".*" <> arch]-              else arch : rel-        in-          intercalate "-" (["Fedora", show edition, editionType edition] ++ middle)+      case tgtrel of+        "respin" -> "F[1-9][0-9]*-" <> liveRespin edition <> "-x86_64" <> "-LIVE"+        "eln" -> "Fedora-ELN-Rawhide"+        _ ->+          let showRel r = if last r == '/' then init r else r+              rel = maybeToList (showRel <$> mrelease)+              middle =+                if edition `elem` [Cloud, Container]+                then rel ++ [".*" <> arch]+                else arch : rel+          in+            intercalate "-" (["Fedora", show edition, editionType edition] ++ middle)      downloadFile :: Bool -> Manager -> URL -> (URL, Maybe Integer) -> IO Bool     downloadFile done mgr url (masterUrl,masterSize) =@@ -314,20 +324,19 @@           cmd_ "curl" ["-C", "-", "-O", url]           return True -    fileChecksum :: Manager -> Maybe URL -> Bool -> IO ()-    fileChecksum _ Nothing _ = return ()-    fileChecksum mgr (Just url) needChecksum =+    fileChecksum :: Manager -> Maybe URL -> String -> Bool -> IO ()+    fileChecksum _ Nothing _ _ = return ()+    fileChecksum mgr (Just url) showdestdir needChecksum =       when ((needChecksum && checksum /= NoCheckSum) || checksum == CheckSum) $ do         let checksumdir = ".dl-fedora-checksums"             checksumfile = checksumdir </> takeFileName url         exists <- do           dirExists <- doesDirectoryExist checksumdir-          if dirExists then checkChecksumfile mgr url checksumfile+          if dirExists then checkChecksumfile mgr url checksumfile showdestdir             else createDirectory checksumdir >> return False         putStrLn ""-        unless exists $ do-          remoteExists <- httpExists mgr url-          when remoteExists $+        unless exists $+          whenM (httpExists mgr url) $             withCurrentDirectory checksumdir $             cmd_ "curl" ["-C", "-", "-s", "-S", "-O", url]         haveChksum <- doesFileExist checksumfile@@ -354,13 +363,13 @@             putStrLn $ "Running " <> shasum <> ":"             cmd_ shasum ["-c", "--ignore-missing", checksumfile] -    checkChecksumfile :: Manager -> URL -> FilePath -> IO Bool-    checkChecksumfile mgr url  checksumfile = do+    checkChecksumfile :: Manager -> URL -> FilePath -> String -> IO Bool+    checkChecksumfile mgr url checksumfile showdestdir = do       exists <- doesFileExist checksumfile       if not exists then return False         else do         masterSize <- httpFileSize mgr url-        ok <- checkLocalFileSize checksumfile masterSize+        ok <- checkLocalFileSize checksumfile masterSize showdestdir         unless ok $ error' "Checksum file filesize mismatch"         return ok 
README.md view
@@ -1,5 +1,6 @@ # dl-fedora +[![GitHub CI](https://github.com/juhp/dl-fedora/workflows/build/badge.svg)](https://github.com/juhp/dl-fedora/actions) [![Hackage](https://img.shields.io/hackage/v/dl-fedora.svg)](https://hackage.haskell.org/package/dl-fedora) [![GPL-3 license](https://img.shields.io/badge/license-GPL--3-blue.svg)](LICENSE) [![Stackage Lts](http://stackage.org/package/dl-fedora/badge/lts)](http://stackage.org/lts/package/dl-fedora)@@ -8,19 +9,23 @@ A tool for downloading Fedora images. By default it targets the Workstation edition of Fedora. -Usage example:+Usage examples:  `dl-fedora rawhide` : downloads the latest Fedora Rawhide Workstation Live iso -`dl-fedora -e silverblue 32` : downloads Fedora 32 Silverblue iso+`dl-fedora -e silverblue 33` : downloads the Fedora Silverblue iso  `dl-fedora -e kde respin` : downloads the latest KDE Live respin -`dl-fedora --edition server --arch aarch64 31` : will bring down the F31 Server iso+`dl-fedora --edition server --arch aarch64 32` : will bring down the F32 Server iso  `dl-fedora --run 33` : will download Fedora 33 Workstation and boot the Live image with qemu-kvm. +If the image is already in the Downloads/ directory+it will not be downloaded again of course.+Curl is used to do the downloading.+ A symlink to the latest iso is also created: eg for rawhide it might be `"Fedora-Workstation-Live-x86_64-Rawhide-latest.iso"`. -When available it also tries to check the iso checksum and its gpg signature.+It also tries to check the iso checksum and its gpg signature.
dl-fedora.cabal view
@@ -1,6 +1,6 @@ cabal-version:       1.18 name:                dl-fedora-version:             0.7.5+version:             0.7.6 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@@ -10,12 +10,13 @@ bug-reports:         https://github.com/juhp/dl-fedora/issues author:              Jens Petersen maintainer:          juhpetersen@gmail.com-copyright:           2019-2020  Jens Petersen+copyright:           2019-2021  Jens Petersen category:            Utility build-type:          Simple extra-doc-files:     README.md                    , CHANGELOG.md-tested-with:         GHC == 8.8.4, GHC == 8.6.5, GHC == 8.4.4, GHC == 8.2.2,+tested-with:         GHC == 8.10.3,+                     GHC == 8.8.4, GHC == 8.6.5, GHC == 8.4.4, GHC == 8.2.2,                      GHC == 8.0.2, GHC == 7.10.3, GHC == 7.8.4, GHC == 7.6.3,                      GHC == 7.4.2 @@ -30,6 +31,7 @@   build-depends:       base < 5,                        bytestring,                        directory >= 1.2.5,+                       extra,                        filepath,                        http-directory == 0.1.5 || >= 0.1.8,                        http-types,