222 lines
5.8 KiB
Go
222 lines
5.8 KiB
Go
package common
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
func (repo *Repo) buildRsyncHost() string {
|
|
if repo.RsyncUser != "" {
|
|
repo.RsyncHost = repo.RsyncUser + "@" + repo.RsyncHost
|
|
}
|
|
return "rsync://" + repo.RsyncHost + "/" + repo.RsyncDir
|
|
}
|
|
|
|
func (repo *Repo) buildRsyncDaemonHost() string {
|
|
if repo.RsyncUser != "" {
|
|
repo.RsyncHost = repo.RsyncUser + "@" + repo.RsyncHost
|
|
}
|
|
return repo.RsyncHost + "::" + repo.RsyncDir
|
|
}
|
|
|
|
func (repo *Repo) buildDownloadDir() string {
|
|
return repo.cfg.DownloadDir + "/" + repo.LocalDir
|
|
}
|
|
|
|
func (repo *Repo) CSCSyncApache() []string {
|
|
args := []string{
|
|
"nice", "rsync", "-az", "--no-owner", "--no-group", "--delete", "--safe-links",
|
|
"--timeout=3600", "-4", "--address=" + repo.cfg.IPv4Address,
|
|
"--exclude", ".~tmp~/",
|
|
"--quiet", "--stats", "--log-file=" + repo.LogFile,
|
|
}
|
|
args = append(args, repo.buildRsyncDaemonHost(), repo.buildDownloadDir())
|
|
|
|
return args
|
|
}
|
|
|
|
func (repo *Repo) CSCSyncArchLinux() []string {
|
|
|
|
tempDir := "" // is this option even needed?
|
|
|
|
// add option for verbose flag?
|
|
args := []string{
|
|
"rsync", "-rtlH", "--safe-links", "--delete-after", "--timeout=600",
|
|
"--contimeout=60", "-p", "--delay-updates", "--no-motd",
|
|
"--temp-dir=" + tempDir, "--log-file=" + repo.LogFile, "--address=" + repo.cfg.IPv4Address,
|
|
}
|
|
args = append(args, repo.buildRsyncHost(), repo.buildDownloadDir())
|
|
|
|
return args
|
|
|
|
}
|
|
|
|
func (repo *Repo) CSCSyncBadPerms() []string {
|
|
args := []string{
|
|
"nice", "rsync", "-aH", "--no-owner", "--no-group", "--chmod=o=rX", "--delete",
|
|
"--timeout=3600", "-4", "--address=" + repo.cfg.IPv4Address,
|
|
"--exclude", ".~tmp~/",
|
|
"--quiet", "--stats", "--log-file=" + repo.LogFile,
|
|
}
|
|
args = append(args, repo.buildRsyncDaemonHost(), repo.buildDownloadDir())
|
|
|
|
return args
|
|
}
|
|
|
|
func (repo *Repo) CSCSyncCDImage() []string {
|
|
args := []string{
|
|
"nice", "rsync", "-aH", "--no-owner", "--no-group", "--delete",
|
|
"--timeout=3600", "-4", "--address=" + repo.cfg.IPv4Address,
|
|
"--exclude", ".*/", "--quiet", "--stats", "--log-file=" + repo.LogFile,
|
|
}
|
|
args = append(args, repo.buildRsyncDaemonHost(), repo.buildDownloadDir())
|
|
|
|
return args
|
|
}
|
|
|
|
func (repo *Repo) CSCSyncChmod() []string {
|
|
args := []string{
|
|
"nice", "rsync", "-aH", "--no-owner", "--no-group", "--delete-after", "--delay-updates", "--safe-links",
|
|
"--timeout=3600", "-4", "--address=" + repo.cfg.IPv4Address,
|
|
"--exclude", ".~tmp~/", "--quiet", "--stats", "--log-file=" + repo.LogFile,
|
|
"--chmod=u=rwX,go=rX",
|
|
}
|
|
args = append(args, repo.buildRsyncHost(), repo.buildDownloadDir())
|
|
|
|
return args
|
|
}
|
|
|
|
func (repo *Repo) CSCSyncDebian() []string {
|
|
|
|
// sync /pool
|
|
args := []string{"nice", "rsync", "-rlHtvp",
|
|
"--exclude", ".~tmp~/", "--timeout=3600", "-4",
|
|
"--address=" + repo.cfg.IPv4Address,
|
|
}
|
|
// $RSYNC_HOST::$RSYNC_DIR/pool/ $TO/pool/ >> $LOGFILE 2>&1
|
|
return args
|
|
}
|
|
|
|
func (repo *Repo) CSCSyncDebianCD() []string {
|
|
|
|
// this is basically the same as CSCSyncDebian, except it has an extra --exclude
|
|
args := []string{"nice", "rsync", "-rlHtvp", "--delete",
|
|
"--exclude", ".~tmp~/", "--timeout=3600", "-4",
|
|
"--address=" + repo.cfg.IPv4Address,
|
|
// "--exclude", "Archive-Update-in-Progress-${HOSTNAME}"
|
|
}
|
|
// $RSYNC_HOST::$RSYNC_DIR $TO >> $LOGFILE 2>&1
|
|
return args
|
|
}
|
|
|
|
func (repo *Repo) CSCSyncGentoo() []string {
|
|
repo.RsyncUser = "gentoo"
|
|
repo.PasswordFile = "gentoo-distfiles"
|
|
return repo.CSCSyncStandard()
|
|
}
|
|
|
|
func (repo *Repo) CSCSyncStandard() []string {
|
|
args := []string{
|
|
"nice", "rsync", "-aH", "--no-owner", "--no-group", "--delete-after",
|
|
"--delay-updates", "--safe-links", "--timeout=3600", "-4", "--address=" + repo.cfg.IPv4Address,
|
|
"--exclude", ".~tmp~/", "--quiet", "--stats", "--log-file=" + repo.LogFile,
|
|
}
|
|
if repo.PasswordFile != "" {
|
|
filename := repo.cfg.PasswordDir + "/" + repo.PasswordFile
|
|
args = append(args, "--password-file", filename)
|
|
}
|
|
args = append(args, repo.buildRsyncHost(), repo.buildDownloadDir())
|
|
|
|
return args
|
|
}
|
|
|
|
func (repo *Repo) CSCSyncStandardIPV6() []string {
|
|
args := []string{
|
|
"nice", "rsync", "-aH", "--no-owner", "--no-group", "--delete-after",
|
|
"--delay-updates", "--safe-links", "--timeout=3600", "-6", "--address=" + repo.cfg.IPv4Address,
|
|
"--exclude", ".~tmp~/", "--quiet", "--stats", "--log-file=" + repo.LogFile,
|
|
}
|
|
args = append(args, repo.buildRsyncDaemonHost(), repo.buildDownloadDir())
|
|
|
|
return args
|
|
}
|
|
|
|
|
|
|
|
// executes a particular sync job depending on repo.SyncType.
|
|
func (repo *Repo) getSyncCommand() []string {
|
|
switch repo.SyncType {
|
|
/*
|
|
# scripts used by merlin.py
|
|
csc-sync-debian
|
|
csc-sync-standard
|
|
csc-sync-ssh
|
|
csc-sync-apache
|
|
csc-sync-archlinux
|
|
csc-sync-debian-cd
|
|
csc-sync-gentoo
|
|
csc-sync-wget
|
|
csc-sync-s3
|
|
csc-sync-standard-ipv6
|
|
csc-sync-ceph
|
|
|
|
zfssync
|
|
report_mirror (what is this?)
|
|
|
|
# other things in bin/
|
|
csc-sync-archlinux-old
|
|
csc-sync-cdimage
|
|
csc-sync-chmod
|
|
csc-sync-badperms
|
|
make-torrents
|
|
ubuntu-releases-sync
|
|
*/
|
|
case "csc-sync-debian":
|
|
case "csc-sync-arch":
|
|
case "csc-sync-standard":
|
|
default:
|
|
repo.Logger.Error("Unrecognized sync type", "'"+repo.SyncType+"'")
|
|
}
|
|
|
|
return []string{}
|
|
}
|
|
|
|
func (repo *Repo) StartSyncJob() {
|
|
status := FAILURE
|
|
defer func() {
|
|
repo.DoneChan <- Result{
|
|
Name: repo.Name,
|
|
Exit: status,
|
|
}
|
|
}()
|
|
|
|
localDir := repo.buildDownloadDir()
|
|
err := os.MkdirAll(localDir, 0775)
|
|
if err != nil {
|
|
err = fmt.Errorf("Could not create directory %s: %w", localDir, err)
|
|
repo.Logger.Error(err)
|
|
return
|
|
}
|
|
|
|
args := repo.getSyncCommand()
|
|
if repo.PasswordFile != "" {
|
|
filename := repo.cfg.PasswordDir + "/" + repo.PasswordFile
|
|
args = append(args, "--password-file", filename)
|
|
}
|
|
args = append(args, repo.buildRsyncHost(), localDir)
|
|
|
|
ch := SpawnProcess(repo, args)
|
|
if ch == nil {
|
|
// Log that something failed?
|
|
return
|
|
}
|
|
cmd := <-ch
|
|
switch cmd.ProcessState.ExitCode() {
|
|
case 0:
|
|
status = SUCCESS
|
|
case -1:
|
|
status = TERMINATED
|
|
// default is already FAILURE
|
|
}
|
|
}
|