diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d5c91f9 --- /dev/null +++ b/Makefile @@ -0,0 +1,22 @@ +.DEFAULT_GOAL := build-n-run + +run: + ./bin/mc2 + +build: + go build -o bin/mc2 -ldflags "\ + -X 'mc2/config.BuildVersion=$$(git rev-parse --abbrev-ref HEAD)' \ + -X 'mc2/config.BuildUser=$$(id -u -n)' \ + -X 'mc2/config.BuildTime=$$(date)' \ + -X 'mc2/config.BuildGOOS=$$(go env GOOS)' \ + -X 'mc2/config.BuildARCH=$$(go env GOARCH)' \ + -s -w" + +docker-build: + docker build -t mc2 . + +docker-run: + docker run --rm -p 4200:4200 mc2 + +test: + go test -v ./... diff --git a/README.md b/README.md index e69de29..5b659e7 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,23 @@ +# Mirror Checker 2 + +To be written in the future.... + +## How to build + + +## Commands + +After building... + +## Notes (for devs) + + +... + +> From the original mirror checker: Future notes: Because many of the mirror checkers are built very specific to each mirror. A slight change in the way the project manages their mirror-related websites, public repos etc. can drastically influence whether the mirror checker works correctly or not. These problems are also unfortunately very hard to detect, so it's important that CSC actively maintain the mirror checker so that it works as intended in the long term. +> +> Extra notes: A test client for individual mirror checker classes is provided as test.py. To use it, simply change all occurrences of the imported project class + + + + diff --git a/config/build.go b/config/build.go new file mode 100644 index 0000000..87f2be5 --- /dev/null +++ b/config/build.go @@ -0,0 +1,13 @@ +package config + +import "runtime" + +var ( + BuildVersion = "development" + BuildTime = "unknown" + BuildUser = "unknown" + BuildGOOS = "unknown" + BuildARCH = "unknown" + GOOS = runtime.GOOS + GOARCH = runtime.GOARCH +) diff --git a/config/config.go b/config/config.go new file mode 100644 index 0000000..9c0aed5 --- /dev/null +++ b/config/config.go @@ -0,0 +1,3 @@ +package config + +var CSC_MIRROR = "http://mirror.csclub.uwaterloo.ca/" diff --git a/data/example.in b/data/example.in new file mode 100644 index 0000000..7d65f14 --- /dev/null +++ b/data/example.in @@ -0,0 +1,29 @@ +AlmaLinux +Alpine +Apache +Arch +Artix +CentOS +Ceph +CPAN +cran +ctan +Cygwin +Debian +DebianCD +DebianMultimedia +DebianPorts +DebianSecurity +Eclipse +Fedora +FreeBSD +GentooDistfiles +GentooPortage +GNOME +GNU +Gutenberg +IPFire +KDE +KDEApplicationData +Kernel +OpenBSD \ No newline at end of file diff --git a/data/mirrors.json b/data/mirrors.json new file mode 100644 index 0000000..492e26a --- /dev/null +++ b/data/mirrors.json @@ -0,0 +1,425 @@ +{ + "AlmaLinux": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "", + "upstream": "https://repo.almalinux.org/", + "file": "almalinux/TIME" + }, + "Alpine": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "", + "upstream": "https://uk.alpinelinux.org/", + "file": "alpine/last-updated" + }, + "Apache": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "apache/", + "upstream": "https://downloads.apache.org/", + "file": "zzz/time.txt" + }, + "Arch": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "archlinux/", + "upstream": "http://arch.mirror.constant.com/", + "file": "lastupdate" + }, + "Artix": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "artixlinux/", + "upstream": "https://mirror1.artixlinux.org/repos/" + }, + "CentOS": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "", + "upstream": "https://mirrors.edge.kernel.org/", + "file": "centos/TIME" + }, + "Ceph": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "ceph/", + "upstream": "https://download.ceph.com/", + "file": "timestamp" + }, + "CPAN": { + "out_of_sync_interval": 172800, + "out_of_sync_since": null + }, + "cran": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "", + "upstream": "https://cran.r-project.org/mirmon_report.html", + "file": "" + }, + "ctan": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "", + "upstream": "https://www.ctan.org/mirrors/mirmon", + "file": "" + }, + "Cygwin": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "cygwin/", + "upstream": "https://cygwin.com/pub/cygwin/", + "file": "x86/sha512.sum" + }, + "Debian": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "", + "upstream": "https://ftp-master.debian.org/", + "file": "debian/project/trace/master" + }, + "DebianCD": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "", + "upstream": "http://debian.mirror.estruxture.net/", + "file": "debian-cd/project/trace/cdimage.debian.org" + }, + "DebianMultimedia": { + "out_of_sync_since": 1659116719, + "out_of_sync_interval": 86400, + "csc": "debian-multimedia/", + "upstream": "http://debian-mirrors.sdinet.de/deb-multimedia/", + "file": "project/trace/deb-multimedia.org" + }, + "DebianPorts": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "", + "upstream": "https://deb.debian.org/", + "file": "debian-ports/project/trace/porta.debian.org", + "exclude": true + }, + "DebianSecurity": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "", + "upstream": "https://deb.debian.org/", + "file": "debian-security/project/trace/master" + }, + "Eclipse": { + "out_of_sync_since": null, + "out_of_sync_interval": 172800, + "csc": "eclipse/", + "upstream": "http://download.eclipse.org/", + "file": "TIME" + }, + "Fedora": { + "out_of_sync_since": null, + "out_of_sync_interval": 259200, + "csc": "fedora/", + "upstream": "http://fedora.mirror.iweb.com/", + "file": "linux/development/rawhide/COMPOSE_ID" + }, + "FreeBSD": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "", + "upstream": "http://ftp4.freebsd.org/pub/", + "file": "FreeBSD/TIMESTAMP" + }, + "GentooDistfiles": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "gentoo-distfiles/", + "upstream": "http://gentoo.mirrors.tera-byte.com/", + "file": "distfiles/timestamp.dev-local" + }, + "GentooPortage": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "rsync://rsync4.ca.gentoo.org/", + "upstream": "https://mirrorstats.gentoo.org/rsync/", + "upstream1": "rsync://rsync1.de.gentoo.org/", + "upstream2": "rsync://rsync8.de.gentoo.org/", + "file": "gentoo-portage/Manifest" + }, + "GNOME": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "gnome/", + "upstream1": "https://download.gnome.org/", + "upstream2": "https://mirrors.dotsrc.org/gnome/", + "upstream3": "https://muug.ca/mirror/gnome/", + "file1": "core/", + "file2": "cache.json" + }, + "GNU": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "", + "upstream": "https://mirrors.kernel.org/", + "file": "gnu/mirror-updated-timestamp.txt" + }, + "Gutenberg": { + "out_of_sync_since": null, + "out_of_sync_interval": 172800, + "csc": "gutenberg/", + "upstream": "https://gutenberg.pglaf.org/", + "file": "gutenberg.dcs" + }, + "IPFire": { + "out_of_sync_since": null, + "out_of_sync_interval": 172800 + }, + "KDE": { + "out_of_sync_since": 1659116720, + "out_of_sync_interval": 86400, + "csc": "kde/", + "upstream": "https://kde.c3sl.ufpr.br/", + "file": "ls-lR" + }, + "KDEApplicationData": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "kde-applicationdata/", + "upstream": "https://cdn.files.kde.org/", + "file": "last-updated" + }, + "Kernel": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "kernel.org/", + "upstream": "https://mirrors.edge.kernel.org/pub/", + "file": "linux/kernel/next/sha256sums.asc" + }, + "linuxmint": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "linuxmint/", + "upstream": "https://mirrors.edge.kernel.org/linuxmint/", + "file": "" + }, + "linuxmint_packages": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "linuxmint-packages/", + "upstream": "https://mirrors.edge.kernel.org/linuxmint-packages/", + "file": "dists/" + }, + "macports": { + "out_of_sync_since": 1642827723, + "out_of_sync_interval": 86400, + "csc": "MacPorts/mpdistfiles/", + "upstream": "https://distfiles.macports.org/", + "file": "ports.tar.gz" + }, + "manjaro": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "", + "upstream": "https://repo.manjaro.org/", + "file": "" + }, + "mxlinux": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "", + "upstream": "http://rsync-mxlinux.org/mirmon/packages.html", + "file": "" + }, + "mxlinux_iso": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "mxlinux-iso/", + "upstream": "http://rsync-mxlinux.org/mirmon/index.html", + "mirrors": [ + "http://mirror.its.dal.ca/mxlinux-cd/", + "http://mirror.umd.edu/mxlinux-iso/" + ], + "file": "" + }, + "mySQL": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "mysql/", + "upstream": "http://mirrors.sunsite.dk/mysql/", + "file": "last-updated.txt" + }, + "netbsd": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "NetBSD/", + "upstream": "http://ftp.netbsd.org/pub/NetBSD/", + "file": "" + }, + "nongnu": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "nongnu/", + "upstream": "http://download-mirror.savannah.gnu.org/releases/", + "file": "00_TIME.txt" + }, + "OpenBSD": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "", + "upstream": "https://ftp.openbsd.org/pub/", + "file": "OpenBSD/timestamp", + "exclude": true + }, + "opensuse": { + "out_of_sync_since": 1648699331, + "out_of_sync_interval": 86400, + "csc": "opensuse/update/", + "upstream": "http://opensuse-mirror-gce-us.opensu.se/update/", + "file": "" + }, + "parabola": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "parabola/", + "upstream": "https://repo.parabola.nu/", + "file": "lastsync" + }, + "pkgsrc": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "pkgsrc/", + "upstream": "http://ftp.netbsd.org/pub/pkgsrc/", + "file": "MIRROR-TIMESTAMP", + "exclude": true + }, + "puppy_linux": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "puppylinux/", + "upstream": "https://distro.ibiblio.org/puppylinux/", + "file": "" + }, + "qtproject": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "qtproject/", + "upstream": "https://download.qt.io/", + "file": "timestamp.txt", + "exclude": true + }, + "racket": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "racket/racket-installers/", + "upstream": "https://mirror.racket-lang.org/installers/", + "file": "" + }, + "raspberrypi": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "raspberrypi/debian/", + "upstream": "https://archive.raspberrypi.org/debian/", + "file": "dists/" + }, + "raspbian": { + "out_of_sync_since": 1659116721, + "out_of_sync_interval": 86400, + "csc": "raspbian/", + "upstream": "http://archive.raspbian.org/", + "file": "snapshotindex.txt" + }, + "sage": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "", + "upstream": "", + "file": "sage/src/index.html" + }, + "saltstack": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "saltstack/", + "upstream": "https://repo.saltproject.io/", + "file": "" + }, + "slackware": { + "out_of_sync_since": 1642827723, + "out_of_sync_interval": 86400, + "csc": "slackware/", + "upstream": "https://mirrors.slackware.com/slackware/", + "file": "" + }, + "tdf": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "tdf/", + "upstream": "https://download.documentfoundation.org/", + "file": "TIMESTAMP" + }, + "trisquel": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "trisquel/", + "upstream": "http://rsync.trisquel.info/trisquel/dists/", + "mirrors": [ + "https://mirror.fsf.org/trisquel-images/", + "http://mirrors.ocf.berkeley.edu/trisquel-images/" + ], + "file": "" + }, + "ubuntu": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "", + "upstream": "https://launchpad.net/ubuntu/+mirror/mirror.csclub.uwaterloo.ca-archive", + "file": "" + }, + "ubuntu_ports": { + "out_of_sync_since": 1651550528, + "out_of_sync_interval": 86400, + "csc": "ubuntu-ports/", + "upstream": "http://ports.ubuntu.com/ubuntu-ports/", + "file": "dists/" + }, + "ubuntu_ports_releases": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "ubuntu-ports-releases/", + "upstream": "https://cdimage.ubuntu.com/releases/", + "file": "" + }, + "ubuntu_releases": { + "out_of_sync_since": null, + "out_of_sync_interval": 172800, + "csc": "", + "upstream": "https://launchpad.net/ubuntu/+mirror/mirror.csclub.uwaterloo.ca-archive", + "file": "" + }, + "vlc": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "vlc/", + "upstream": "http://download.videolan.org/pub/videolan/", + "file": "trace" + }, + "x_org": { + "out_of_sync_since": 1657512131, + "out_of_sync_interval": 86400, + "csc": "x.org/individual/", + "upstream": "https://www.x.org/releases/individual/", + "file": "" + }, + "xiph": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "xiph/releases/", + "upstream": "https://ftp.osuosl.org/pub/xiph/releases/", + "file": "" + }, + "xubuntu_releases": { + "out_of_sync_since": null, + "out_of_sync_interval": 86400, + "csc": "xubuntu-releases/", + "upstream": "https://cdimage.ubuntu.com/xubuntu/releases/", + "file": "" + } +} diff --git a/main.go b/main.go new file mode 100644 index 0000000..cb43e24 --- /dev/null +++ b/main.go @@ -0,0 +1,57 @@ +package main + +import ( + "log" + "os" + + "github.com/Nathan13888/mirror-checker2/v2/config" + "github.com/Nathan13888/mirror-checker2/v2/web" + "github.com/urfave/cli/v2" +) + +func main() { + // Start CLI + // TODO: documentation - https://cli.urfave.org/v2/examples/full-api-example/ + app := &cli.App{ + Name: "CSC Mirror Checker 2", + Usage: "sees if the mirror is up!", + Version: config.BuildVersion, + EnableBashCompletion: true, + // https://cli.urfave.org/v2/examples/combining-short-options/ + // TODO: flags for config file (mirrors.json) and input + Commands: []*cli.Command{ + { + Name: "server", + Aliases: []string{"s", "serve", "web"}, + Usage: "starts web API", + Action: func(cCtx *cli.Context) error { + // TODO: flags for port, listen address + + return web.StartServer() + }, + }, + { + Name: "check", + Aliases: []string{"c"}, + Usage: "checks particular mirror", + Action: func(cCtx *cli.Context) error { + return nil + }, + // TODO: auto complete available mirrors, https://cli.urfave.org/v2/examples/combining-short-options/ + // BashComplete: func(cCtx *cli.Context) { + // // This will complete if no args are passed + // if cCtx.NArg() > 0 { + // return + // } + // for _, t := range config.Mirrors { + // fmt.Println(t) + // } + // }, + }, + }, + } + + if err := app.Run(os.Args); err != nil { + log.Fatal(err) + } +} diff --git a/web/server.go b/web/server.go new file mode 100644 index 0000000..c2d0c42 --- /dev/null +++ b/web/server.go @@ -0,0 +1,15 @@ +package web + +import "github.com/gofiber/fiber/v2" + +func StartServer() error { + app := fiber.New() + + app.Get("/", func(c *fiber.Ctx) error { + return c.SendString("Hello, World 👋!") + }) + + app.Listen(":3000") + + return nil +}