Skip to content

Commit

Permalink
fix root to $HOME in sealos
Browse files Browse the repository at this point in the history
use bash not sh. centos default sh is bash not ubuntu.

Signed-off-by: oldthreefeng <[email protected]>
  • Loading branch information
oldthreefeng committed Jan 6, 2021
1 parent 2c3b8a7 commit b7adf25
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 21 deletions.
6 changes: 3 additions & 3 deletions cert/kube_certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ import (
)

var (
SealosConfigDir = getSealosCertDir()
SealosConfigDir = GetUserHomeDir() + "/.sealos"
KubernetesDir = "/etc/kubernetes"
KubeDefaultCertPath = "/etc/kubernetes/pki"
kubeDefaultCertEtcdPath = "/etc/kubernetes/pki/etcd"
)

func getSealosCertDir() string {
func GetUserHomeDir() string {
home, err := os.UserHomeDir()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
return home + "/.sealos"
return home
}

func CaList(CertPath, CertEtcdPath string) []Config {
Expand Down
7 changes: 4 additions & 3 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/spf13/cobra"

"github.com/fanux/sealos/cert"
"github.com/fanux/sealos/install"
"github.com/wonderivan/logger"
)
Expand Down Expand Up @@ -109,7 +110,7 @@ func init() {
// Here you will define your flags and configuration settings.
initCmd.Flags().StringVar(&install.SSHConfig.User, "user", "root", "servers user name for ssh")
initCmd.Flags().StringVar(&install.SSHConfig.Password, "passwd", "", "password for ssh")
initCmd.Flags().StringVar(&install.SSHConfig.PkFile, "pk", getUserHome() + "/.ssh/id_rsa", "private key for ssh")
initCmd.Flags().StringVar(&install.SSHConfig.PkFile, "pk", cert.GetUserHomeDir() + "/.ssh/id_rsa", "private key for ssh")
initCmd.Flags().StringVar(&install.SSHConfig.PkPassword, "pk-passwd", "", "private key password for ssh")

initCmd.Flags().StringVar(&install.KubeadmFile, "kubeadm-config", "", "kubeadm-config.yaml template file")
Expand Down Expand Up @@ -138,8 +139,8 @@ func init() {
initCmd.Flags().IntVar(&install.Vlog, "vlog", 0, "kubeadm log level")

// 不像用户暴露
// initCmd.Flags().StringVar(&install.CertPath, "cert-path", getUserHome() + "/.sealos/pki", "cert file path")
// initCmd.Flags().StringVar(&install.CertEtcdPath, "cert-etcd-path", getUserHome() + "/.sealos/pki/etcd", "etcd cert file path")
// initCmd.Flags().StringVar(&install.CertPath, "cert-path", cert.GetUserHomeDir() + "/.sealos/pki", "cert file path")
// initCmd.Flags().StringVar(&install.CertEtcdPath, "cert-etcd-path", cert.GetUserHomeDir() + "/.sealos/pki/etcd", "etcd cert file path")
}

func NewInitGenerateCmd() *cobra.Command {
Expand Down
3 changes: 2 additions & 1 deletion cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/spf13/cobra"

"github.com/fanux/sealos/cert"
"github.com/fanux/sealos/install"
"github.com/fanux/sealos/pkg/appmanager"
)
Expand Down Expand Up @@ -63,7 +64,7 @@ func init() {
rootCmd.AddCommand(installCmd)

installCmd.Flags().StringVar(&AppURL, "pkg-url", "", "http://store.lameleg.com/prometheus.tar.gz download offline plugins package url, or file localtion ex. /root/prometheus.tar.gz")
installCmd.Flags().StringVarP(&install.WorkDir, "workdir", "w", getUserHome(), "workdir for install package home ex. sealos install --pkg-url dashboard.tar --workdir /data")
installCmd.Flags().StringVarP(&install.WorkDir, "workdir", "w", cert.GetUserHomeDir(), "workdir for install package home ex. sealos install --pkg-url dashboard.tar --workdir /data")
installCmd.Flags().StringVarP(&install.PackageConfig, "pkg-config", "c", "", `packageConfig for install package config ex. sealos install --pkg-url dashboard.tar -c config`)
installCmd.Flags().StringVarP(&install.Values, "values", "f", "", "values for install package values.yaml , you know what you did .ex. sealos install --pkg-url dashboard.tar -f values.yaml")
}
13 changes: 2 additions & 11 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import (
"fmt"
"os"

"github.com/fanux/sealos/cert"
"github.com/fanux/sealos/install"
"github.com/wonderivan/logger"

"github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -64,7 +64,7 @@ func init() {
// initConfig reads in config file and ENV variables if set.
func initConfig() {
// Find home directory.
home := getUserHome()
home := cert.GetUserHomeDir()
logFile := fmt.Sprintf("%s/.sealos/sealos.log", home)
if !install.FileExist(home + "/.sealos") {
err := os.MkdirAll(home + "/.sealos",os.ModePerm)
Expand All @@ -78,12 +78,3 @@ func initConfig() {
logger.Cfg(6, logFile)
}
}

func getUserHome() string {
home, err := homedir.Dir()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
return home
}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ require (
github.com/fanux/sealgate v0.0.5
github.com/ghodss/yaml v1.0.0
github.com/gorilla/websocket v1.4.2 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/pkg/errors v0.9.1
github.com/pkg/sftp v1.11.0
github.com/satori/go.uuid v1.2.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion install/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func (s *SealosInstaller) SendPackage() {
pkg := path.Base(PkgUrl)
// rm old sealos in package avoid old version problem. if sealos not exist in package then skip rm
kubeHook := fmt.Sprintf("cd /root && rm -rf kube && tar zxvf %s && cd /root/kube/shell && rm -f ../bin/sealos && sh init.sh", pkg)
kubeHook := fmt.Sprintf("cd /root && rm -rf kube && tar zxvf %s && cd /root/kube/shell && rm -f ../bin/sealos && bash init.sh", pkg)
deletekubectl := `sed -i '/kubectl/d;/sealos/d' /root/.bashrc `
completion := "echo 'command -v kubectl &>/dev/null && source <(kubectl completion bash)' >> /root/.bashrc && echo 'command -v sealos &>/dev/null && source <(sealos completion bash)' >> /root/.bashrc && source /root/.bashrc"
kubeHook = kubeHook + " && " + deletekubectl + " && " + completion
Expand Down
2 changes: 1 addition & 1 deletion pkg/sshcmd/sshutil/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func fileExist(path string) bool {
return err == nil || os.IsExist(err)
}

// 使用 pk认证, pk路径为 "/root/.ssh/id_rsa", pk有密码和无密码在这里面验证
// 使用 pk认证, pk路径为 "$HOME/.ssh/id_rsa", pk有密码和无密码在这里面验证
func (ss *SSH) sshPrivateKeyMethod(pkFile, pkPassword string) (am ssh.AuthMethod, err error) {
pkData := ss.readFile(pkFile)
var pk ssh.Signer
Expand Down

0 comments on commit b7adf25

Please sign in to comment.