packages feed

dl-fedora 0.7.7 → 0.8

raw patch · 5 files changed

+71/−31 lines, 5 files

Files

CHANGELOG.md view
@@ -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
README.md view
@@ -21,8 +21,11 @@  `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.
dl-fedora.cabal view
@@ -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
src/Main.hs view
@@ -45,7 +45,6 @@ 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 @@     <$> 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 @@       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 @@         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,13 +164,25 @@       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)     findURL mgr mirror showdestdir = do@@ -201,7 +221,7 @@                 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 @@           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"@@ -411,6 +433,17 @@           putStrLn ""           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"
test/tests.hs view
@@ -9,11 +9,11 @@   [["-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 ()