2024-01-30 16:45:03 +01:00
|
|
|
package pods
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2024-01-30 21:24:31 +01:00
|
|
|
"net/http"
|
|
|
|
"net/url"
|
2024-01-30 19:41:10 +01:00
|
|
|
"os"
|
2024-01-30 16:45:03 +01:00
|
|
|
|
2024-01-30 21:24:31 +01:00
|
|
|
"github.com/containers/podman/v4/pkg/bindings"
|
2024-01-30 16:45:03 +01:00
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CopySkelToContainer copies an Archive into the containers home directory
|
|
|
|
// (Assumes the use of a Webtop container)
|
|
|
|
func CopySkelToContainer(id string) error {
|
2024-01-30 19:41:10 +01:00
|
|
|
log.Println("Copying skel Archive to container")
|
2024-01-30 16:45:03 +01:00
|
|
|
var err error
|
2024-01-30 21:24:31 +01:00
|
|
|
conn, err := bindings.GetClient(Socket)
|
2024-01-30 16:45:03 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-01-30 21:24:31 +01:00
|
|
|
file, err := os.Open(viper.GetString("skel"))
|
2024-01-30 19:41:10 +01:00
|
|
|
if err != nil {
|
2024-01-30 21:24:31 +01:00
|
|
|
log.Println("Could not open skel archive", err)
|
2024-01-30 19:41:10 +01:00
|
|
|
return err
|
2024-01-30 16:45:03 +01:00
|
|
|
}
|
|
|
|
|
2024-01-30 21:24:31 +01:00
|
|
|
fileInfo, err := os.Stat(viper.GetString("skel"))
|
|
|
|
log.Println("Skel Archive is ", fileInfo.Size(), "b")
|
2024-01-30 16:45:03 +01:00
|
|
|
|
2024-01-30 21:24:31 +01:00
|
|
|
defer file.Close()
|
|
|
|
|
|
|
|
params := url.Values{}
|
|
|
|
params.Set("path", "/config")
|
|
|
|
|
|
|
|
response, err := conn.DoRequest(
|
|
|
|
Socket,
|
|
|
|
file,
|
|
|
|
http.MethodPut,
|
|
|
|
"/containers/%s/archive",
|
|
|
|
params,
|
|
|
|
nil,
|
|
|
|
id,
|
|
|
|
)
|
2024-01-30 16:45:03 +01:00
|
|
|
if err != nil {
|
2024-01-30 19:41:10 +01:00
|
|
|
return err
|
2024-01-30 16:45:03 +01:00
|
|
|
}
|
|
|
|
|
2024-01-30 21:24:31 +01:00
|
|
|
if response.StatusCode != http.StatusOK {
|
|
|
|
log.Println("Error putting archive into container: ")
|
|
|
|
return err
|
2024-01-30 16:45:03 +01:00
|
|
|
}
|
2024-01-30 21:24:31 +01:00
|
|
|
log.Println(response.StatusCode, response.Body)
|
|
|
|
return response.Process(nil)
|
2024-01-30 16:45:03 +01:00
|
|
|
}
|