2019-11-24 17:28:39 +00:00
|
|
|
// Copyright © 2019 Ettore Di Giacinto <mudler@gentoo.org>
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
installer "github.com/mudler/luet/pkg/installer"
|
|
|
|
|
|
|
|
. "github.com/mudler/luet/pkg/logger"
|
|
|
|
pkg "github.com/mudler/luet/pkg/package"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
var createrepoCmd = &cobra.Command{
|
|
|
|
Use: "create-repo",
|
|
|
|
Short: "Create a luet repository from a build",
|
|
|
|
Long: `Generate and renew repository metadata`,
|
2019-11-25 18:55:30 +00:00
|
|
|
PreRun: func(cmd *cobra.Command, args []string) {
|
|
|
|
viper.BindPFlag("packages", cmd.Flags().Lookup("packages"))
|
|
|
|
viper.BindPFlag("tree", cmd.Flags().Lookup("tree"))
|
|
|
|
viper.BindPFlag("output", cmd.Flags().Lookup("output"))
|
|
|
|
viper.BindPFlag("name", cmd.Flags().Lookup("name"))
|
2019-12-31 00:21:06 +00:00
|
|
|
viper.BindPFlag("descr", cmd.Flags().Lookup("descr"))
|
|
|
|
viper.BindPFlag("urls", cmd.Flags().Lookup("urls"))
|
2019-11-25 18:55:30 +00:00
|
|
|
viper.BindPFlag("type", cmd.Flags().Lookup("type"))
|
2020-01-03 23:31:11 +00:00
|
|
|
viper.BindPFlag("reset-revision", cmd.Flags().Lookup("reset-revision"))
|
2019-11-25 18:55:30 +00:00
|
|
|
},
|
2019-11-24 17:28:39 +00:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
|
|
|
|
tree := viper.GetString("tree")
|
|
|
|
dst := viper.GetString("output")
|
|
|
|
packages := viper.GetString("packages")
|
|
|
|
name := viper.GetString("name")
|
2019-12-31 00:21:06 +00:00
|
|
|
descr := viper.GetString("descr")
|
|
|
|
urls := viper.GetStringSlice("urls")
|
2019-11-24 17:28:39 +00:00
|
|
|
t := viper.GetString("type")
|
2020-01-03 23:31:11 +00:00
|
|
|
reset := viper.GetBool("reset-revision")
|
2019-11-24 17:28:39 +00:00
|
|
|
|
2019-12-31 00:21:06 +00:00
|
|
|
repo, err := installer.GenerateRepository(name, descr, t, urls, 1, packages, tree, pkg.NewInMemoryDatabase(false))
|
2019-11-24 17:28:39 +00:00
|
|
|
if err != nil {
|
|
|
|
Fatal("Error: " + err.Error())
|
|
|
|
}
|
2020-01-03 23:31:11 +00:00
|
|
|
err = repo.Write(dst, reset)
|
2019-11-24 17:28:39 +00:00
|
|
|
if err != nil {
|
|
|
|
Fatal("Error: " + err.Error())
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
path, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
Fatal(err)
|
|
|
|
}
|
|
|
|
createrepoCmd.Flags().String("packages", path, "Packages folder (output from build)")
|
|
|
|
createrepoCmd.Flags().String("tree", path, "Source luet tree")
|
|
|
|
createrepoCmd.Flags().String("output", path, "Destination folder")
|
|
|
|
createrepoCmd.Flags().String("name", "luet", "Repository name")
|
2019-12-31 00:21:06 +00:00
|
|
|
createrepoCmd.Flags().String("descr", "luet", "Repository description")
|
|
|
|
createrepoCmd.Flags().StringSlice("urls", []string{}, "Repository URLs")
|
|
|
|
createrepoCmd.Flags().String("type", "disk", "Repository type (disk)")
|
2020-01-03 23:31:11 +00:00
|
|
|
createrepoCmd.Flags().Bool("reset-revision", false, "Reset repository revision.")
|
2019-11-24 17:28:39 +00:00
|
|
|
|
|
|
|
RootCmd.AddCommand(createrepoCmd)
|
|
|
|
}
|