util.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package control
  2. import (
  3. "bufio"
  4. "fmt"
  5. "os"
  6. "strings"
  7. "github.com/rancher/os/config"
  8. "github.com/rancher/os/pkg/log"
  9. )
  10. func yes(question string) bool {
  11. fmt.Printf("%s [y/N]: ", question)
  12. in := bufio.NewReader(os.Stdin)
  13. line, err := in.ReadString('\n')
  14. if err != nil {
  15. log.Fatal(err)
  16. }
  17. return strings.ToLower(line[0:1]) == "y"
  18. }
  19. func formatImage(image string, cfg *config.CloudConfig) string {
  20. domainRegistry := cfg.Rancher.Environment["REGISTRY_DOMAIN"]
  21. if domainRegistry != "docker.io" && domainRegistry != "" {
  22. return fmt.Sprintf("%s/%s", domainRegistry, image)
  23. }
  24. return image
  25. }
  26. func symLinkEngineBinary(version string) []symlink {
  27. baseSymlink := []symlink{
  28. {"/var/lib/rancher/engine/docker", "/usr/bin/docker"},
  29. {"/var/lib/rancher/engine/dockerd", "/usr/bin/dockerd"},
  30. {"/var/lib/rancher/engine/docker-init", "/usr/bin/docker-init"},
  31. {"/var/lib/rancher/engine/docker-proxy", "/usr/bin/docker-proxy"},
  32. {"/usr/share/ros/os-release", "/usr/lib/os-release"},
  33. {"/usr/share/ros/os-release", "/etc/os-release"},
  34. }
  35. if strings.Contains(version, "18.09") {
  36. baseSymlink = append(baseSymlink, []symlink{
  37. {"/var/lib/rancher/engine/containerd", "/usr/bin/containerd"},
  38. {"/var/lib/rancher/engine/ctr", "/usr/bin/ctr"},
  39. {"/var/lib/rancher/engine/containerd-shim", "/usr/bin/containerd-shim"},
  40. {"/var/lib/rancher/engine/runc", "/usr/bin/runc"},
  41. }...)
  42. } else {
  43. baseSymlink = append(baseSymlink, []symlink{
  44. {"/var/lib/rancher/engine/docker-containerd", "/usr/bin/docker-containerd"},
  45. {"/var/lib/rancher/engine/docker-containerd-ctr", "/usr/bin/docker-containerd-ctr"},
  46. {"/var/lib/rancher/engine/docker-containerd-shim", "/usr/bin/docker-containerd-shim"},
  47. {"/var/lib/rancher/engine/docker-runc", "/usr/bin/docker-runc"},
  48. }...)
  49. }
  50. return baseSymlink
  51. }
  52. func checkGlobalCfg() bool {
  53. _, err := os.Stat("/proc/1/root/boot/global.cfg")
  54. if err == nil || os.IsExist(err) {
  55. return true
  56. }
  57. return false
  58. }