main function
Show/Hide Function Body
{ fmt.Println("This plugin is not meant to run standalone!") }
Configuration for a CMake module
Provide plugin information as a JSON string
{
plugininfo := &api.PluginInfo{Name: "cmake", Type: api.BuildPlugin, UseContainerCmds: false}
pluginjson, err := json.Marshal(plugininfo)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
return C.CString(string(pluginjson))
}
Generate a shell command to build a CMake project based on the provided module and recipe.
Download and move the source, set up build variables and flags, and construct the CMake build command.
{
var module *CMakeModule
var recipe *api.Recipe
err := json.Unmarshal([]byte(C.GoString(moduleInterface)), &module)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
err = json.Unmarshal([]byte(C.GoString(recipeInterface)), &recipe)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
err = api.DownloadSource(recipe, module.Source, module.Name)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
err = api.MoveSource(recipe.DownloadsPath, recipe.SourcesPath, module.Source, module.Name)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
buildVars := map[string]string{}
for k, v := range module.BuildVars {
buildVars[k] = v
}
buildFlags := ""
if module.BuildFlags != "" {
buildFlags = " " + module.BuildFlags
}
cmd := fmt.Sprintf(
"cd /sources/%s && mkdir -p build && cd build && cmake ..%s && make",
filepath.Join(recipe.SourcesPath, api.GetSourcePath(module.Source, module.Name)),
buildFlags,
)
return C.CString(cmd)
}
{ fmt.Println("This plugin is not meant to run standalone!") }
Configuration for building a Debian package using dpkg
Provide plugin information as a JSON string
{
plugininfo := &api.PluginInfo{Name: "dpkg-buildpackage", Type: api.BuildPlugin, UseContainerCmds: false}
pluginjson, err := json.Marshal(plugininfo)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
return C.CString(string(pluginjson))
}
Generate a command to build a Debian package using dpkg and install
the resulting .deb package. Handle downloading, moving the source,
and running dpkg-buildpackage with appropriate options.
{
var module *DpkgBuildModule
var recipe *api.Recipe
err := json.Unmarshal([]byte(C.GoString(moduleInterface)), &module)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
err = json.Unmarshal([]byte(C.GoString(recipeInterface)), &recipe)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
err = api.DownloadSource(recipe, module.Source, module.Name)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
err = api.MoveSource(recipe.DownloadsPath, recipe.SourcesPath, module.Source, module.Name)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
cmd := fmt.Sprintf(
"cd /sources/%s && dpkg-buildpackage -d -us -uc -b",
api.GetSourcePath(module.Source, module.Name),
)
cmd += fmt.Sprintf(" && apt install -y --allow-downgrades ../%s*.deb", module.Source.Path)
cmd += " && apt clean"
return C.CString(cmd)
}
{ fmt.Println("This plugin is not meant to run standalone!") }
Configuration for managing Flatpak repositories and packages
Configuration for managing Flatpak repositories and packages
for both system and user contexts
Provide plugin information as a JSON string
{
plugininfo := &api.PluginInfo{Name: "flatpak", Type: api.BuildPlugin, UseContainerCmds: false}
pluginjson, err := json.Marshal(plugininfo)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
return C.CString(string(pluginjson))
}
Generate a command to add a Flatpak remote repository.
Add appropriate flags for system-wide or user-specific installation.
{
fmt.Println("Adding remote ", isSystem, " ", module)
command := "flatpak remote-add --if-not-exists"
if isSystem {
command = fmt.Sprintf("%s --system", command)
} else {
command = fmt.Sprintf("%s --user", command)
}
return fmt.Sprintf("%s %s %s", command, module.Reponame, module.Repourl)
}
Generate setup commands for Flatpak module configuration.
Create scripts for system-wide and user-specific Flatpak setups,
including repository addition, package installation, and service configuration.
{
var module *FlatpakModule
var recipe *api.Recipe
err := json.Unmarshal([]byte(C.GoString(moduleInterface)), &module)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
err = json.Unmarshal([]byte(C.GoString(recipeInterface)), &recipe)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
os.MkdirAll(path.Join(recipe.ParentPath, "includes.container/usr/bin/"), 0o775)
if module.System.Reponame != "" {
syscommands := "#!/usr/bin/env sh"
if module.System.Repourl != "" {
syscommands = fmt.Sprintf("%s\n%s", syscommands, createRepo(module.System, true))
fmt.Println(syscommands)
}
if len(module.System.Install) != 0 {
syscommands = fmt.Sprintf("%s\nflatpak install --system --noninteractive %s %s", syscommands, module.System.Reponame, strings.Join(module.System.Install, " "))
}
if len(module.System.Remove) != 0 {
syscommands = fmt.Sprintf("%s\nflatpak uninstall --system --noninteractive %s %s", syscommands, module.User.Reponame, strings.Join(module.System.Remove, " "))
}
syscommands = fmt.Sprintf("%s\nsystemctl disable flatpak-system-setup.service", syscommands)
err := os.WriteFile(path.Join(recipe.ParentPath, "includes.container/usr/bin/system-flatpak-setup"), []byte(syscommands), 0o777)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
}
if module.User.Reponame != "" {
usercommands := "#!/usr/bin/env sh"
if module.User.Repourl != "" {
usercommands = fmt.Sprintf("%s\n%s", usercommands, createRepo(module.User, false))
fmt.Println(usercommands)
}
if len(module.User.Install) != 0 {
usercommands = fmt.Sprintf("%s\nflatpak install --user --noninteractive %s", usercommands, strings.Join(module.User.Install, " "))
}
if len(module.User.Remove) != 0 {
usercommands = fmt.Sprintf("%s\nflatpak uninstall --user --noninteractive %s", usercommands, strings.Join(module.User.Remove, " "))
}
err := os.WriteFile(path.Join(recipe.ParentPath, "includes.container/usr/bin/user-flatpak-setup"), []byte(usercommands), 0o777)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
}
os.MkdirAll(path.Join(recipe.ParentPath, "includes.container/etc/systemd/user"), 0o775)
os.MkdirAll(path.Join(recipe.ParentPath, "includes.container/etc/systemd/system"), 0o775)
os.WriteFile(path.Join(recipe.ParentPath, "includes.container/etc/systemd/user/flatpak-user-setup.service"), []byte(UserService), 0o666)
os.WriteFile(path.Join(recipe.ParentPath, "includes.container/etc/systemd/system/flatpak-system-setup.service"), []byte(SystemService), 0o666)
return C.CString("systemctl enable --global flatpak-user-setup.service && systemctl enable --system flatpak-system-setup.service")
}
{ fmt.Println("This plugin is not meant to run standalone!") }
Configuration for building a Go module
Provide plugin information as a JSON string
{
plugininfo := &api.PluginInfo{Name: "go", Type: api.BuildPlugin, UseContainerCmds: false}
pluginjson, err := json.Marshal(plugininfo)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
return C.CString(string(pluginjson))
}
Generate a command to build a Go project. Add options for
setting the output binary name and location based on the provided buildVars
and BuildFlags, and handle downloading and moving the source.
{
var module *GoModule
var recipe *api.Recipe
err := json.Unmarshal([]byte(C.GoString(moduleInterface)), &module)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
err = json.Unmarshal([]byte(C.GoString(recipeInterface)), &recipe)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
err = api.DownloadSource(recipe, module.Source, module.Name)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
err = api.MoveSource(recipe.DownloadsPath, recipe.SourcesPath, module.Source, module.Name)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
buildVars := map[string]string{}
for k, v := range module.BuildVars {
buildVars[k] = v
}
buildFlags := ""
if module.BuildFlags != "" {
buildFlags = " " + module.BuildFlags
}
buildVars["GO_OUTPUT_BIN"] = module.Name
if module.BuildVars["GO_OUTPUT_BIN"] != "" {
buildVars["GO_OUTPUT_BIN"] = module.BuildVars["GO_OUTPUT_BIN"]
}
cmd := fmt.Sprintf(
"cd /sources/%s && go build%s -o %s",
api.GetSourcePath(module.Source, module.Name),
buildFlags,
buildVars["GO_OUTPUT_BIN"],
)
return C.CString(cmd)
}
{ fmt.Println("This plugin is not meant to run standalone!") }
Configuration for building a project using Make
Provide plugin information as a JSON string
{
plugininfo := &api.PluginInfo{Name: "make", Type: api.BuildPlugin, UseContainerCmds: false}
pluginjson, err := json.Marshal(plugininfo)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
return C.CString(string(pluginjson))
}
Generate a command to build a Make project. Change directory
to the source path, run 'make' to build the project, and 'make install'
to install the built project. Handle downloading and moving the source.
{
var module *MakeModule
var recipe *api.Recipe
err := json.Unmarshal([]byte(C.GoString(moduleInterface)), &module)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
err = json.Unmarshal([]byte(C.GoString(recipeInterface)), &recipe)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
err = api.DownloadSource(recipe, module.Source, module.Name)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
err = api.MoveSource(recipe.DownloadsPath, recipe.SourcesPath, module.Source, module.Name)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
buildCommand := "make"
installCommand := "make install"
intermediateSteps := " && "
if len(strings.TrimSpace(module.BuildCommand)) != 0 {
buildCommand = module.BuildCommand
}
if len(strings.TrimSpace(module.InstallCommand)) != 0 {
installCommand = module.InstallCommand
}
if len(module.IntermediateSteps) != 0 {
intermediateSteps = " && " + strings.Join(module.IntermediateSteps, " && ") + " && "
}
cmd := "cd /sources/" + api.GetSourcePath(module.Source, module.Name) + " && " + buildCommand + intermediateSteps + installCommand
return C.CString(cmd)
}
{ fmt.Println("This plugin is not meant to run standalone!") }
Configuration for building a Meson project
Provide plugin information as a JSON string
{
plugininfo := &api.PluginInfo{Name: "meson", Type: api.BuildPlugin, UseContainerCmds: false}
pluginjson, err := json.Marshal(plugininfo)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
return C.CString(string(pluginjson))
}
Generate a command to build a Meson project. Handle source downloading, moving,
and use Meson and Ninja build tools with a temporary build directory based on the checksum.
{
var module *MesonModule
var recipe *api.Recipe
err := json.Unmarshal([]byte(C.GoString(moduleInterface)), &module)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
err = json.Unmarshal([]byte(C.GoString(recipeInterface)), &recipe)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
err = api.DownloadSource(recipe, module.Source, module.Name)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
err = api.MoveSource(recipe.DownloadsPath, recipe.SourcesPath, module.Source, module.Name)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
// Since the downloaded source goes through checksum verification already
// it is safe to simply use the specified checksum from the module definition
tmpDir := fmt.Sprintf("/tmp/%s-%s", module.Source.Checksum, module.Name)
cmd := fmt.Sprintf(
"cd /sources/%s && meson %s %s && ninja -C %s && ninja -C %s install",
api.GetSourcePath(module.Source, module.Name),
strings.Join(module.BuildFlags, " "),
tmpDir,
tmpDir,
tmpDir,
)
return C.CString(cmd)
}
{ fmt.Println("This plugin is not meant to run standalone!") }
Configuration for a shim module
Provide plugin information as a JSON string
{
plugininfo := &api.PluginInfo{Name: "shim", Type: api.BuildPlugin, UseContainerCmds: false}
pluginjson, err := json.Marshal(plugininfo)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
return C.CString(string(pluginjson))
}
Generate a command to build a shim module. Create temporary directories,
write module and recipe data to files, and execute the plugin command with
the paths to these files.
{
var module *ShimModule
var recipe *api.Recipe
err := json.Unmarshal([]byte(C.GoString(moduleInterface)), &module)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
err = json.Unmarshal([]byte(C.GoString(recipeInterface)), &recipe)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
fmt.Printf("[SHIM] Starting plugin: %s\n", module.ShimType)
dataDir, err := os.MkdirTemp("", fmt.Sprintf("*-vibshim-%s", module.ShimType))
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
defer os.RemoveAll(dataDir)
pluginCommand := fmt.Sprintf("%s/%s", recipe.PluginPath, module.ShimType)
modulePath := filepath.Join(dataDir, "moduleInterface")
recipePath := filepath.Join(dataDir, "recipeInterface")
err = os.WriteFile(modulePath, []byte(C.GoString(moduleInterface)), 0o777)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
err = os.WriteFile(recipePath, []byte(C.GoString(recipeInterface)), 0o777)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
out, err := exec.Command(pluginCommand, modulePath, recipePath).Output()
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
return C.CString(string(out))
}
{}
Configuration for an APT module
Options for APT package management
Provide plugin information as a JSON string
{
plugininfo := &api.PluginInfo{Name: "apt", Type: api.BuildPlugin, UseContainerCmds: false}
pluginjson, err := json.Marshal(plugininfo)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
return C.CString(string(pluginjson))
}
Generate an apt-get install command from the provided module and recipe.
Handle package installation and apply appropriate options.
{
var module *AptModule
var recipe *api.Recipe
err := json.Unmarshal([]byte(C.GoString(moduleInterface)), &module)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
err = json.Unmarshal([]byte(C.GoString(recipeInterface)), &recipe)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
args := ""
if module.Options.NoRecommends {
args += "--no-install-recommends "
}
if module.Options.InstallSuggests {
args += "--install-suggests "
}
if module.Options.FixMissing {
args += "--fix-missing "
}
if module.Options.FixBroken {
args += "--fix-broken "
}
if len(module.Source.Packages) > 0 {
packages := ""
for _, pkg := range module.Source.Packages {
packages += pkg + " "
}
return C.CString(fmt.Sprintf("apt-get install -y %s %s && apt-get clean", args, packages))
}
if len(strings.TrimSpace(module.Source.Path)) > 0 {
cmd := ""
installFiles, err := os.ReadDir(module.Source.Path)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
for i, path := range installFiles {
fullPath := filepath.Join(module.Source.Path, path.Name())
fileInfo, err := os.Stat(fullPath)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
if !fileInfo.Mode().IsRegular() {
continue
}
packages := ""
file, err := os.Open(fullPath)
if err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
packages += scanner.Text() + " "
}
if err := scanner.Err(); err != nil {
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
}
cmd += fmt.Sprintf("apt-get install -y %s %s", args, packages)
if i != len(installFiles)-1 {
cmd += "&& "
} else {
cmd += "&& apt-get clean"
}
}
return C.CString(cmd)
}
return C.CString("ERROR: no packages or paths specified")
}
{}
import "C"
import "encoding/json"
import "fmt"
import "path/filepath"
import "github.com/vanilla-os/vib/api"
import "C"
import "encoding/json"
import "fmt"
import "github.com/vanilla-os/vib/api"
import "C"
import "encoding/json"
import "fmt"
import "github.com/vanilla-os/vib/api"
import "os"
import "path"
import "strings"
import "C"
import "fmt"
import "github.com/vanilla-os/vib/api"
import "encoding/json"
import "C"
import "encoding/json"
import "fmt"
import "github.com/vanilla-os/vib/api"
import "strings"
import "C"
import "encoding/json"
import "fmt"
import "strings"
import "github.com/vanilla-os/vib/api"
import "encoding/json"
import "fmt"
import "C"
import "github.com/vanilla-os/vib/api"
import "os"
import "os/exec"
import "path/filepath"
import "bufio"
import "encoding/json"
import "fmt"
import "os"
import "C"
import "github.com/vanilla-os/vib/api"
import "path/filepath"
import "strings"