Package br.com.objectos.rio

Source Code of br.com.objectos.rio.GentooMirror

/*
* Copyright 2014 Objectos, Fábrica de Software LTDA.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package br.com.objectos.rio;

import java.io.File;

import br.com.objectos.rio.core.os.Chroot;
import br.com.objectos.rio.core.os.ChrootMount;
import br.com.objectos.rio.core.os.ChrootUmount;
import br.com.objectos.way.base.io.Directory;
import br.com.objectos.way.base.io.Stdout;

/**
* @author marcio.endo@objectos.com.br (Marcio Endo)
*/
public class GentooMirror extends AbstractGentoo {

  private final GentooMirrorBuilderPojo pojo;

  public GentooMirror(GentooMirrorBuilderPojo builder) {
    super(builder.command);
    this.pojo = builder;
  }

  public void quickpkg() {
    Directory mountDir = pojo.getMountDir();

    infoAction("quickpkg");
    info("Generating binaries.");

    Directory portage = mountDir.dirAt("usr/portage");
    chmod(portage)
        .file("packages").to(755)
        .recursively()
        .exec();

    ChrootMount mount = ChrootMount.at(mountDir).mount();

    try {

      Chroot chroot = Chroot.at(mountDir)
          .add("source /etc/profile")
          .add("export PS1=\"(chroot) $PS1\"")
          .add("quickpkg \"*/*\"")
          .exec();

      Stdout.print(chroot);

    } finally {

      ChrootUmount umount = mount.umount();
      Stdout.print(umount);

    }
  }

  public void distfiles() {
    Directory mountDir = pojo.getMountDir();
    String server = pojo.getServer();

    infoAction("distfiles");
    info("Uploading distfiles to portage mirror.");

    File distfiles = mountDir.fileAt("/usr/portage/distfiles");

    scpFile(distfiles)
        .toHost(server)
        .at("/var/www/localhost/htdocs/gentoo/distfiles")
        .send();
  }

  public void packages() {
    String server = pojo.getServer();
    String remotePath = pojo.getRemotePath();
    Directory mountDir = pojo.getMountDir();

    infoAction("packages");
    info("Uploading binaries to portage binhost.");

    ssh(server).connect()
        .execute("mkdir -p %s", remotePath)
        .disconnect();

    File packages = mountDir.fileAt("usr/portage/packages");
    scpFile(packages)
        .toHost(server)
        .at(remotePath)
        .send();
  }

  public void stage3() {
    Directory mountDir = pojo.getMountDir();
    File stage3File = pojo.getStage3File();

    infoAction("stage3");
    info("Generating stage3 tarball.");

    tar(mountDir)
        .preserve()
        .exclude("./usr/portage/distfiles")
        .exclude("./usr/portage/packages")
        .add(".")
        .gzip()
        .toFile(stage3File);
  }

  public void stage3Upload() {
    String server = pojo.getServer();
    String remotePath = pojo.getRemotePath();
    File stage3File = pojo.getStage3File();

    infoAction("stage3-upload");
    info("Uploading stage3 tarball to portage binhost.");

    scpFile(stage3File)
        .toHost(server)
        .at(remotePath)
        .send();
  }

}
TOP

Related Classes of br.com.objectos.rio.GentooMirror

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.