dl-fedora 0.7.4 → 0.7.5
raw patch · 5 files changed
+90/−67 lines, 5 filessetup-changed
Files
- CHANGELOG.md +5/−0
- Main.hs +80/−60
- README.md +3/−3
- Setup.hs +0/−2
- dl-fedora.cabal +2/−2
CHANGELOG.md view
@@ -1,5 +1,10 @@ # Changelog +## 0.7.5 (2020-09-13)+- always print download url and already downloaded filename+- --replace deletes previous symlinked image after downloading new one+- improved checksum file handling+ ## 0.7.4 (2020-03-15) - add 'koji' release target: downloads latest branched compose from kojipkgs
Main.hs view
@@ -1,10 +1,8 @@ {-# LANGUAGE CPP #-} -#if (defined(MIN_VERSION_base) && MIN_VERSION_base(4,13,0))-#else+#if !MIN_VERSION_base(4,13,0) import Control.Applicative ((<|>)-#if (defined(MIN_VERSION_base) && MIN_VERSION_base(4,8,0))-#else+#if !MIN_VERSION_base(4,8,0) , (<$>), (<*>) #endif )@@ -74,6 +72,8 @@ Nothing -> error' "unknown edition" >> RP.pfail Just ed -> RP.lift (R.string e) >> return ed +type URL = String+ fedoraSpins :: [FedoraEdition] fedoraSpins = [Cinnamon ..] @@ -101,6 +101,7 @@ <*> checkSumOpts <*> switchWith 'n' "dry-run" "Don't actually download anything" <*> switchWith 'r' "run" "Boot image in Qemu"+ <*> switchWith 'R' "replace" "Delete old image after downloading new one" <*> optional mirrorOpt <*> strOptionalWith 'a' "arch" "ARCH" "Architecture [default: x86_64]" "x86_64" <*> optionalWith auto 'e' "edition" "EDITION" "Fedora edition [default: workstation]" Workstation@@ -116,8 +117,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 -> Maybe String -> String -> FedoraEdition -> String -> IO ()-program gpg checksum dryrun run mmirror arch edition tgtrel = do+program :: Bool -> CheckSum -> Bool -> Bool -> Bool -> Maybe String -> String -> FedoraEdition -> String -> IO ()+program gpg checksum dryrun run removeold mmirror arch edition tgtrel = do let mirror = case mmirror of Nothing | tgtrel == "koji" -> kojiPkgs@@ -129,7 +130,7 @@ setDownloadDir dlDir home mgr <- httpManager (fileurl, filenamePrefix, (masterUrl,masterSize), mchecksum, done) <- findURL mgr mirror- downloadFile done mgr fileurl (masterUrl,masterSize) >>= fileChecksum mchecksum+ downloadFile done mgr fileurl (masterUrl,masterSize) >>= fileChecksum mgr mchecksum unless dryrun $ do let localfile = takeFileName fileurl symlink = filenamePrefix <> "-latest" <.> takeExtension fileurl@@ -150,7 +151,7 @@ when dirExists' $ setCurrentDirectory dlDir -- urlpath, fileprefix, (master,size), checksum, downloaded- findURL :: Manager -> String -> IO (String, String, (String,Maybe Integer), Maybe String, Bool)+ findURL :: Manager -> String -> IO (URL, String, (URL,Maybe Integer), Maybe String, Bool) findURL mgr mirror = do (path,mrelease) <- urlPathMRel mgr -- use http-directory trailingSlash (0.1.7)@@ -187,8 +188,6 @@ unless (run && already) $ maybe (return ()) putStrLn $ showMSize masterSize <> showMDate mlocaltime let finalDir = dropFileName finalurl- unless run $- putStrLn finalurl return (finalurl, prefix, (masterUrl,masterSize), (finalDir </>) . T.unpack <$> mchecksum, already) where httpTimestamp url = do@@ -220,8 +219,8 @@ localsize <- toInteger . fileSize <$> getFileStatus localfile if Just localsize == masterSize then do- unless run $- putStrLn "File already fully downloaded"+ when (not run && takeExtension localfile == ".iso") $+ putStrLn $ localfile <> " already fully downloaded" return True else do let showsize =@@ -231,7 +230,7 @@ putStrLn $ "File " <> showsize <> " downloaded" return False - urlPathMRel :: Manager -> IO (String, Maybe String)+ urlPathMRel :: Manager -> IO (FilePath, Maybe String) urlPathMRel mgr = do let subdir = if edition `elem` fedoraSpins@@ -300,7 +299,7 @@ in intercalate "-" (["Fedora", show edition, editionType edition] ++ middle) - downloadFile :: Bool -> Manager -> String -> (String, Maybe Integer) -> IO Bool+ downloadFile :: Bool -> Manager -> URL -> (URL, Maybe Integer) -> IO Bool downloadFile done mgr url (masterUrl,masterSize) = if done then return False@@ -309,70 +308,91 @@ mirrorSize <- httpFileSize mgr url unless (mirrorSize == masterSize) $ putStrLn "Warning! Mirror filesize differs from master file"+ putStrLn url if dryrun then return False else do cmd_ "curl" ["-C", "-", "-O", url] return True - fileChecksum :: Maybe FilePath -> Bool -> IO ()- fileChecksum Nothing _ = return ()- fileChecksum (Just url) needChecksum =+ fileChecksum :: Manager -> Maybe URL -> Bool -> IO ()+ fileChecksum _ Nothing _ = return ()+ fileChecksum mgr (Just url) 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 doesFileExist checksumfile+ if dirExists then checkChecksumfile mgr url checksumfile else createDirectory checksumdir >> return False putStrLn ""- unless exists $- withCurrentDirectory checksumdir $- cmd_ "curl" ["-C", "-", "-s", "-S", "-O", url]- pgp <- grep_ "PGP" checksumfile- when (gpg && pgp) $ do- havekey <- checkForFedoraKeys- unless havekey $ do- putStrLn "Importing Fedora GPG keys:\n"- -- https://fedoramagazine.org/verify-fedora-iso-file/- pipe_ ("curl",["-s", "-S", "https://getfedora.org/static/fedora.gpg"]) ("gpg",["--import"])- putStrLn ""- chkgpg <- if pgp- then checkForFedoraKeys- else return False- let shasum = if "CHECKSUM512" `isPrefixOf` takeFileName checksumfile- then "sha512sum" else "sha256sum"- if chkgpg then do- putStrLn $ "Running gpg verify and " <> shasum <> ":"- pipeFile_ checksumfile ("gpg",["-q"]) (shasum, ["-c", "--ignore-missing"])+ unless exists $ do+ remoteExists <- httpExists mgr url+ when remoteExists $+ withCurrentDirectory checksumdir $+ cmd_ "curl" ["-C", "-", "-s", "-S", "-O", url]+ haveChksum <- doesFileExist checksumfile+ if not haveChksum+ then putStrLn "No checksum file found" else do- putStrLn $ "Running " <> shasum <> ":"- cmd_ shasum ["-c", "--ignore-missing", checksumfile]+ pgp <- grep_ "PGP" checksumfile+ when (gpg && pgp) $ do+ havekey <- checkForFedoraKeys+ unless havekey $ do+ putStrLn "Importing Fedora GPG keys:\n"+ -- https://fedoramagazine.org/verify-fedora-iso-file/+ pipe_ ("curl",["-s", "-S", "https://getfedora.org/static/fedora.gpg"]) ("gpg",["--import"])+ putStrLn ""+ chkgpg <- if pgp+ then checkForFedoraKeys+ else return False+ let shasum = if "CHECKSUM512" `isPrefixOf` takeFileName checksumfile+ then "sha512sum" else "sha256sum"+ if chkgpg then do+ putStrLn $ "Running gpg verify and " <> shasum <> ":"+ pipeFile_ checksumfile ("gpg",["-q"]) (shasum, ["-c", "--ignore-missing"])+ else do+ putStrLn $ "Running " <> shasum <> ":"+ cmd_ shasum ["-c", "--ignore-missing", checksumfile] + checkChecksumfile :: Manager -> URL -> FilePath -> IO Bool+ checkChecksumfile mgr url checksumfile = do+ exists <- doesFileExist checksumfile+ if not exists then return False+ else do+ masterSize <- httpFileSize mgr url+ ok <- checkLocalFileSize checksumfile masterSize+ unless ok $ error' "Checksum file filesize mismatch"+ return ok+ checkForFedoraKeys :: IO Bool checkForFedoraKeys = pipeBool ("gpg",["--list-keys"]) ("grep", ["-q", " Fedora .*(" <> tgtrel <> ").*@fedoraproject.org>"]) -updateSymlink :: FilePath -> FilePath -> String -> IO ()-updateSymlink target symlink showdestdir = do- symExists <- do- havefile <- doesFileExist symlink- if havefile then return True- else do- -- check for broken symlink- dirfiles <- listDirectory "."- return $ symlink `elem` dirfiles- if symExists- then do- linktarget <- readSymbolicLink symlink- when (linktarget /= target) $ do- removeFile symlink- makeSymlink- else makeSymlink- where- makeSymlink = do- putStrLn ""- createSymbolicLink target symlink- putStrLn $ unwords [showdestdir </> symlink, "->", target]+ updateSymlink :: FilePath -> FilePath -> FilePath -> IO ()+ updateSymlink target symlink showdestdir = do+ mmsymlinkTarget <- do+ havefile <- doesFileExist symlink+ if havefile+ then Just . Just <$> readSymbolicLink symlink+ else do+ -- check for broken symlink+ dirfiles <- listDirectory "."+ return $ if symlink `elem` dirfiles then Just Nothing else Nothing+ case mmsymlinkTarget of+ Nothing -> makeSymlink+ Just Nothing -> do+ removeFile symlink+ makeSymlink+ Just (Just symlinktarget) -> do+ when (symlinktarget /= target) $ do+ when removeold $ removeFile symlinktarget+ removeFile symlink+ makeSymlink+ where+ makeSymlink = do+ putStrLn ""+ createSymbolicLink target symlink+ putStrLn $ unwords [showdestdir </> symlink, "->", target] editionType :: FedoraEdition -> String editionType Server = "dvd"
README.md view
@@ -12,13 +12,13 @@ `dl-fedora rawhide` : downloads the latest Fedora Rawhide Workstation Live iso -`dl-fedora -e silverblue 31` : downloads Fedora 31 Silverblue iso+`dl-fedora -e silverblue 32` : downloads Fedora 32 Silverblue iso `dl-fedora -e kde respin` : downloads the latest KDE Live respin -`dl-fedora --edition server --arch aarch64 30` : will bring down the F30 Server iso+`dl-fedora --edition server --arch aarch64 31` : will bring down the F31 Server iso -`dl-fedora --run 32` : will download Fedora 32 Workstation and boot the Live image with qemu-kvm.+`dl-fedora --run 33` : will download Fedora 33 Workstation and boot the Live image with qemu-kvm. A symlink to the latest iso is also created: eg for rawhide it might be `"Fedora-Workstation-Live-x86_64-Rawhide-latest.iso"`.
− Setup.hs
@@ -1,2 +0,0 @@-import Distribution.Simple-main = defaultMain
dl-fedora.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.18 name: dl-fedora-version: 0.7.4+version: 0.7.5 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@@ -15,7 +15,7 @@ build-type: Simple extra-doc-files: README.md , CHANGELOG.md-tested-with: GHC == 8.8.3, GHC == 8.6.5, GHC == 8.4.4, GHC == 8.2.2,+tested-with: 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