-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite login shell register with go (#216)
* Rewrite login shell register with go * Remove outdated job from CI The linters will be run in precommit and Nix CI
- Loading branch information
Showing
4 changed files
with
64 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"strings" | ||
) | ||
|
||
// Called should be `sudo -E ...`, See https://stackoverflow.com/a/40438345/1212807 | ||
|
||
// This script requires sudo execution, if it is a reasonable way, including in home.nix may be better | ||
|
||
func main() { | ||
homePath, ok := os.LookupEnv("HOME") | ||
if !ok { | ||
log.Fatalln("$HOME is not found") | ||
} | ||
if homePath == "/root" { | ||
log.Fatalln("used by root looks weird. You should run `sudo -E ...` instead of `sudo ...`") | ||
} | ||
|
||
loginAbles := []string{"zsh", "fish"} | ||
|
||
etcShellsBytes, err := os.ReadFile("/etc/shells") | ||
if err != nil { | ||
log.Fatalf("%v\n", err) | ||
} | ||
|
||
etcShells := string(etcShellsBytes) | ||
dirty := strings.Clone(etcShells) | ||
examplePath := "" | ||
|
||
for _, sh := range loginAbles { | ||
shellPath := homePath + "/.nix-profile/bin/" + sh | ||
if strings.Contains(etcShells, shellPath) { | ||
log.Printf("skip - %s is already registered in /etc/shells\n", shellPath) | ||
} else { | ||
log.Printf("insert - %s will be registered in /etc/shells\n", shellPath) | ||
examplePath = shellPath | ||
dirty += fmt.Sprintln(shellPath) | ||
} | ||
} | ||
|
||
if dirty != etcShells { | ||
err = os.WriteFile("/etc/shells", []byte(dirty), os.ModePerm) | ||
if err != nil { | ||
log.Fatalf("failed - could you correctly run this with sudo? - %v\n", err) | ||
} | ||
|
||
fmt.Printf(` | ||
Done! Set one of your favorite shell as follows | ||
chsh -s %s "$(whoami)" | ||
`, examplePath) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.