Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru>
This commit is contained in:
2015-03-26 11:53:54 +03:00
parent b8521294cd
commit 5bbc02c647
7 changed files with 39 additions and 13 deletions

View File

@@ -185,8 +185,22 @@ func ExecuteScript(scriptPath string) (string, error) {
return name, err
}
func SetHostname(hostname string) error {
return exec.Command("hostnamectl", "set-hostname", hostname).Run()
func SetHostname(hostname string) (err error) {
for _, name := range []string{"hostnamectl", "hostname"} {
if _, err = exec.LookPath(name); err != nil {
continue
}
switch name {
case "hostname":
err = exec.Command(name, hostname).Run()
case "hostnamectl":
err = exec.Command(name, "set-hostname", hostname).Run()
}
}
if err != nil {
return
}
return ioutil.WriteFile("/etc/hostname", []byte(hostname+"\n"), 0644)
}
func Hostname() (string, error) {

View File

@@ -80,7 +80,11 @@ func CreateUser(u *config.User) error {
return err
}
args = []string{}
return nil
}
func LockUnlockUser(u *config.User) error {
args := []string{}
if u.LockPasswd {
args = append(args, "--lock")
@@ -90,7 +94,7 @@ func CreateUser(u *config.User) error {
args = append(args, u.Name)
output, err = exec.Command("passwd", args...).CombinedOutput()
output, err := exec.Command("passwd", args...).CombinedOutput()
if err != nil {
log.Printf("Command 'passwd %s' failed: %v\n%s", strings.Join(args, " "), err, output)
}
@@ -98,7 +102,7 @@ func CreateUser(u *config.User) error {
}
func SetUserPassword(user, hash string) error {
cmd := exec.Command("/usr/sbin/chpasswd", "-e")
cmd := exec.Command("chpasswd", "-e")
stdin, err := cmd.StdinPipe()
if err != nil {