diff --git a/agent/ambassador-agent.cabal b/agent/ambassador-agent.cabal index 12c3c7137..ac8fb781b 100644 --- a/agent/ambassador-agent.cabal +++ b/agent/ambassador-agent.cabal @@ -5,7 +5,7 @@ cabal-version: 1.12 -- see: https://github.com/sol/hpack name: ambassador-agent -version: 0.2.13 +version: 0.2.14 build-type: Simple extra-source-files: ./migrations/0.1.0::0.1.0 @@ -19,6 +19,7 @@ extra-source-files: ./migrations/0.2.10::0.2.11 ./migrations/0.2.11::0.2.12 ./migrations/0.2.12::0.2.13 + ./migrations/0.2.13::0.2.14 ./migrations/0.2.1::0.2.2 ./migrations/0.2.2::0.2.3 ./migrations/0.2.3::0.2.4 diff --git a/agent/src/Lib/Synchronizers.hs b/agent/src/Lib/Synchronizers.hs index a944fba90..12fc41e0e 100644 --- a/agent/src/Lib/Synchronizers.hs +++ b/agent/src/Lib/Synchronizers.hs @@ -591,19 +591,22 @@ syncUpgradeTor :: SyncOp syncUpgradeTor = SyncOp "Install Latest Tor" check migrate False where check = run $ do + shell "apt-get clean" shell "apt-get update" mTorVersion <- (shell "dpkg -s tor" $| shell "grep '^Version'" $| shell "cut -d ' ' -f2" $| conduit await) echo ("CURRENT TOR VERSION:" :: Text) (show mTorVersion :: Text) let torVersion = case mTorVersion of Nothing -> panic "invalid output from dpkg, can't read tor version" Just x -> x - availVersions <- - (shell "apt-cache madison tor" $| shell "cut -d '|' -f2" $| shell "xargs" $| conduit consume) - echo ("AVAILABLE TOR VERSIONS:" :: Text) (show availVersions :: Text) - pure . not $ isJust (find ((== EQ) . compareTorVersions torVersion) availVersions) + pure $ compareTorVersions torVersion "0.3.5.15-1" == LT migrate = liftIO . run $ do shell "apt-get update" - shell "apt-get install -y tor" + availVersions <- + (shell "apt-cache madison tor" $| shell "cut -d '|' -f2" $| shell "xargs" $| conduit consume) + let latest = case lastMay $ sortBy compareTorVersions availVersions of + Nothing -> panic "No available versions of tor" + Just x -> x + shell $ "apt-get install -y tor=" <> if "0.3.5.15-1" `elem` availVersions then "0.3.5.15-1" else latest compareTorVersions :: ByteString -> ByteString -> Ordering compareTorVersions a b = let a' = (traverse (readMaybe @Int . decodeUtf8) . (split '.' <=< split '-') $ a)