Skip to content

Commit

Permalink
Add repository replacement script
Browse files Browse the repository at this point in the history
  • Loading branch information
rdner committed Mar 27, 2023
1 parent e407fc1 commit dbf0c3a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
46 changes: 45 additions & 1 deletion dev-tools/mage/pkgdeps.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
package mage

import (
"bytes"
"fmt"
"log"
"os"

"github.com/magefile/mage/sh"
)
Expand Down Expand Up @@ -117,10 +120,15 @@ func installDependencies(arch string, pkgs ...string) error {
}
}

err := fixJessieRepositories()
if err != nil {
return fmt.Errorf("error while editing the repositories: %w", err)
}

// TODO: This is only for debian 7 and should be removed when move to a newer OS. This flag is
// going to be used unnecessary when building using non-debian7 images
// (like when making the linux/arm binaries) and we should remove it soonish.
// See https://github.com/elastic/beats/v7/issues/11750 for more details.
// See https://github.com/elastic/beats/issues/11750 for more details.
if err := sh.Run("apt-get", "update", "-o", "Acquire::Check-Valid-Until=false"); err != nil {
return err
}
Expand All @@ -137,6 +145,42 @@ func installDependencies(arch string, pkgs ...string) error {
return sh.Run("apt-get", params...)
}

// This is a hack to continue using the old Debian Jessie (8) release.
// The repositories were moved to the archive, so we have to replace sources
// in order to make `apt` work again.
func fixJessieRepositories() error {
sources := "/etc/apt/sources.list"
bts, err := os.ReadFile(sources)
if err != nil {
return err
}
if !bytes.Contains(bts, []byte("jessie")) {
return nil
}

log.Println("Detected Debian Jessie, need to fix the repository sources...")

sourcesFile := `deb [check-valid-until=no] http://archive.debian.org/debian jessie-backports main
deb-src http://archive.debian.org/debian jessie-backports main
deb [check-valid-until=no] http://archive.debian.org/debian jessie main
deb-src [check-valid-until=no] http://archive.debian.org/debian jessie main
`

err = os.WriteFile(sources, []byte(sourcesFile), 0644)
if err != nil {
return err
}

err = sh.Run("apt-get", "autoremove")
if err != nil {
return err
}

log.Println("Repository sources have been replaced")

return nil
}

func (p PlatformDescription) Packages(names ...string) PackageDependency {
return PackageDependency{}.WithTag(p.DefaultTag).Add(names...)
}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/auditbeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func installDependencies(arch string, pkgs ...string) error {
// TODO: This is only for debian 7 and should be removed when move to a newer OS. This flag is
// going to be used unnecessary when building using non-debian7 images
// (like when making the linux/arm binaries) and we should remove it soonish.
// See https://github.com/elastic/beats/v7/issues/11750 for more details.
// See https://github.com/elastic/beats/issues/11750 for more details.
if err := sh.Run("apt-get", "update", "-o", "Acquire::Check-Valid-Until=false"); err != nil {
return err
}
Expand Down

0 comments on commit dbf0c3a

Please sign in to comment.