From 8708a4de8e10f1fdd8e562285f846dec17be7a00 Mon Sep 17 00:00:00 2001 From: Keagan McClelland Date: Tue, 13 Jul 2021 12:16:27 -0600 Subject: [PATCH] agent 0.2.14 --- agent/migrations/0.2.13::0.2.14 | 1 + agent/package.yaml | 4 ++-- agent/src/Lib/Synchronizers.hs | 42 ++++++++++++++++++++++----------- 3 files changed, 31 insertions(+), 16 deletions(-) create mode 100644 agent/migrations/0.2.13::0.2.14 diff --git a/agent/migrations/0.2.13::0.2.14 b/agent/migrations/0.2.13::0.2.14 new file mode 100644 index 000000000..b928005e2 --- /dev/null +++ b/agent/migrations/0.2.13::0.2.14 @@ -0,0 +1 @@ +SELECT TRUE; \ No newline at end of file diff --git a/agent/package.yaml b/agent/package.yaml index 9aecfaa49..e091502cf 100644 --- a/agent/package.yaml +++ b/agent/package.yaml @@ -1,5 +1,5 @@ name: ambassador-agent -version: 0.2.13 +version: 0.2.14 default-extensions: - NoImplicitPrelude @@ -182,4 +182,4 @@ executables: condition: flag(library-only) - condition: false other-modules: Paths_ambassador_agent -extra-source-files: ./migrations/* \ No newline at end of file +extra-source-files: ./migrations/* diff --git a/agent/src/Lib/Synchronizers.hs b/agent/src/Lib/Synchronizers.hs index 8ff5e9ee6..a944fba90 100644 --- a/agent/src/Lib/Synchronizers.hs +++ b/agent/src/Lib/Synchronizers.hs @@ -24,6 +24,7 @@ import qualified Data.Conduit.Combinators as Conduit import Data.Conduit.Shell hiding ( arch , hostname , patch + , split , stream ) import qualified Data.Conduit.Tar as Conduit @@ -50,6 +51,8 @@ import Constants import Control.Effect.Error hiding ( run ) import Control.Effect.Labelled ( runLabelled ) import Daemon.ZeroConf ( getStart9AgentHostname ) +import Data.ByteString.Char8 ( split ) +import Data.Conduit.List ( consume ) import qualified Data.Text as T import Foundation import Handler.Network @@ -98,12 +101,12 @@ parseKernelVersion = do pure $ KernelVersion (Version (major', minor', patch', 0)) arch synchronizer :: Synchronizer -synchronizer = sync_0_2_13 +synchronizer = sync_0_2_14 {-# INLINE synchronizer #-} -sync_0_2_13 :: Synchronizer -sync_0_2_13 = Synchronizer - "0.2.13" +sync_0_2_14 :: Synchronizer +sync_0_2_14 = Synchronizer + "0.2.14" [ syncCreateAgentTmp , syncCreateSshDir , syncRemoveAvahiSystemdDependency @@ -585,19 +588,30 @@ syncRestarterService = SyncOp "Install Restarter Service" check migrate True liftIO $ callCommand "systemctl enable restarter.timer" syncUpgradeTor :: SyncOp -syncUpgradeTor = SyncOp "Install Tor 0.3.5.14-1" check migrate False +syncUpgradeTor = SyncOp "Install Latest Tor" check migrate False where - check = - liftIO - $ ( run (shell [i|dpkg -l|] $| shell [i|grep tor|] $| shell [i|grep 0.3.5.14-1|] $| conduit await) - $> False - ) - `catch` \(e :: ProcessException) -> case e of - ProcessException _ (ExitFailure 1) -> pure True - _ -> throwIO e + check = run $ do + 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) migrate = liftIO . run $ do shell "apt-get update" - shell "apt-get install -y tor=0.3.5.14-1" + shell "apt-get install -y tor" + compareTorVersions :: ByteString -> ByteString -> Ordering + compareTorVersions a b = + let a' = (traverse (readMaybe @Int . decodeUtf8) . (split '.' <=< split '-') $ a) + b' = (traverse (readMaybe @Int . decodeUtf8) . (split '.' <=< split '-') $ b) + in case liftA2 compare a' b' of + Nothing -> panic "invalid tor version string" + Just x -> x + syncDropCertificateUniqueness :: SyncOp syncDropCertificateUniqueness = SyncOp "Eliminate OpenSSL unique_subject=yes" check migrate False