mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
add 'user-config'
Change-Id: Id93f4ca5b8b9fe621745ae554c2831528da63167
This commit is contained in:
parent
0756fd966b
commit
b9d7589d02
@ -41,7 +41,6 @@ func CreateGuestUser() (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
CopyUserDatas(username)
|
||||
return username, nil
|
||||
}
|
||||
|
||||
|
@ -69,12 +69,7 @@ func CreateUser(username, fullname, shell string, ty int32) error {
|
||||
}
|
||||
|
||||
cmd = fmt.Sprintf("%s %s", cmd, username)
|
||||
err := doAction(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
CopyUserDatas(username)
|
||||
return nil
|
||||
return doAction(cmd)
|
||||
}
|
||||
|
||||
func DeleteUser(rmFiles bool, username string) error {
|
||||
|
@ -19,13 +19,15 @@
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
|
||||
package users
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"pkg.linuxdeepin.com/dde-daemon/accounts/users"
|
||||
"pkg.linuxdeepin.com/lib/archive"
|
||||
dutils "pkg.linuxdeepin.com/lib/utils"
|
||||
"regexp"
|
||||
@ -41,18 +43,41 @@ const (
|
||||
* Copy user resource datas to their home directory
|
||||
**/
|
||||
func CopyUserDatas(user string) {
|
||||
info, err := GetUserInfoByName(user)
|
||||
info, err := users.GetUserInfoByName(user)
|
||||
if err != nil {
|
||||
fmt.Printf("Get '%s' info failed: %v\n", user, err)
|
||||
return
|
||||
}
|
||||
lang := getDefaultLang()
|
||||
|
||||
copyXDGDirConfig(info.Home, lang)
|
||||
lang := getDefaultLang()
|
||||
fmt.Println("Current LANG is :", lang)
|
||||
|
||||
err = copyXDGDirConfig(info.Home, lang)
|
||||
if err != nil {
|
||||
fmt.Printf("Copy xdg config for '%s' failed: %v\n", user, err)
|
||||
}
|
||||
|
||||
renameXDGDirs(info.Home, lang)
|
||||
copyDeepinManuals(info.Home, lang)
|
||||
copySoundThemeData(info.Home, lang)
|
||||
copyBroswerConfig(info.Home, lang)
|
||||
changeDirOwner(user, info.Home)
|
||||
|
||||
err = copyDeepinManuals(info.Home, lang)
|
||||
if err != nil {
|
||||
fmt.Printf("Copy deepin manuals for '%s' failed: %v\n", user, err)
|
||||
}
|
||||
|
||||
err = copySoundThemeData(info.Home, lang)
|
||||
if err != nil {
|
||||
fmt.Printf("Copy sound theme for '%s' failed: %v\n", user, err)
|
||||
}
|
||||
|
||||
err = copyBroswerConfig(info.Home, lang)
|
||||
if err != nil {
|
||||
fmt.Printf("Copy broswer config for '%s' failed: %v\n", user, err)
|
||||
}
|
||||
|
||||
err = changeDirOwner(user, info.Home)
|
||||
if err != nil {
|
||||
fmt.Printf("Change '%s' ower to '%s' failed: %v\n", info.Home, user, err)
|
||||
}
|
||||
}
|
||||
|
||||
func copyDeepinManuals(home, lang string) error {
|
||||
@ -223,3 +248,12 @@ func getDefaultLang() string {
|
||||
|
||||
return strings.Split(locale, ".")[0]
|
||||
}
|
||||
|
||||
func doAction(cmd string) error {
|
||||
out, err := exec.Command("/bin/sh", "-c", cmd).CombinedOutput()
|
||||
if err != nil {
|
||||
return fmt.Errorf(string(out))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
69
bin/user-config/main.go
Normal file
69
bin/user-config/main.go
Normal file
@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Copyright (c) 2011 ~ 2015 Deepin, Inc.
|
||||
* 2013 ~ 2015 jouyouyun
|
||||
*
|
||||
* Author: jouyouyun <jouyouwen717@gmail.com>
|
||||
* Maintainer: jouyouyun <jouyouwen717@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/user"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func helper() {
|
||||
fmt.Println("Initialize the user configuration, if the configuration files exist out directly.\n")
|
||||
fmt.Println("Usage: user-config [username]")
|
||||
fmt.Println("\tIf the user is not specified, will configure the current user.")
|
||||
}
|
||||
|
||||
func getUsername(args []string) (string, bool, error) {
|
||||
if len(args) == 1 {
|
||||
u, err := user.Current()
|
||||
if err != nil {
|
||||
return "", false, err
|
||||
}
|
||||
return u.Username, false, nil
|
||||
}
|
||||
|
||||
var arg = strings.ToLower(args[1])
|
||||
if arg == "-h" || arg == "--help" {
|
||||
return "", true, nil
|
||||
}
|
||||
|
||||
return args[1], false, nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
name, help, err := getUsername(os.Args)
|
||||
if err != nil {
|
||||
fmt.Println("Parse arguments failed:", err)
|
||||
return
|
||||
}
|
||||
|
||||
if help {
|
||||
helper()
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("Start init '%s' configuration.\n", name)
|
||||
CopyUserDatas(name)
|
||||
fmt.Printf("Init '%s' configuration over.\n", name)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user