-
Notifications
You must be signed in to change notification settings - Fork 0
/
rhino-deploy
executable file
·107 lines (102 loc) · 3.83 KB
/
rhino-deploy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env nu
def "setup-managers" [sources: list<any>] -> int {
if 'managers' in $sources.packages {
let managers = ($sources.packages.managers | transpose manager booled)
for $mngr in $managers {
if $mngr.booled == true {
match $mngr.manager {
'flatpak' => { ^bash -c 'sudo apt-get install -y flatpak && flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo' }
'snap' => { ^bash -c 'sudo apt-get install -y snapd' }
'appimage' => { ^bash -c 'sudo apt-get install -y libfuse2' }
_ => { return 1 }
}
}
}
} else {
return 0
}
}
def "setup-software" [sources: list<any>] -> int {
if 'software' in $sources.packages {
let software = ($sources.packages.software | transpose pkg booled)
for $soft in $software {
if $soft.booled == true {
match $soft.pkg {
'nala' => { ^pacstall -PI nala-deb }
'gh-cli' => { ^pacstall -PI github-cli-deb }
'apport' => { ^bash -c 'sudo apt-get install -y apport && sudo systemctl enable apport.service' }
_ => { print -e $"($soft.pkg) does not exist" and return 1 }
}
}
}
} else {
return 0
}
}
def "setup-packages" [sources: list<any>] -> int {
if 'packages' in $sources.packages {
let pkgs = ($sources.packages.packages | transpose pkg-type pkgs)
for $base in $pkgs {
if ($base.pkgs | not is-empty) {
match $base.pkg-type {
'apt' => { ^bash -c $"sudo apt install ($base.pkgs)" }
'pacstall' => { ^pacstall -PI $base.pkgs }
'flatpak' => { ^bash -c $"sudo flatpak install ($base.pkgs)" }
'snap' => { ^bash -c $"sudo snap install ($base.pkgs)" }
_ => { print -e $"($base.pkg-type) does not exist" and return 1 }
}
}
}
} else {
return 0
}
}
def "setup-users" [sources: list<any>] -> int {
# Do we have users
if 'users' in ($sources) {
let users = ($sources.users)
for $user in $users {
mut cmd = ['sudo', 'useradd']
mut groups = []
if 'home' in ($user) {
if $user.home == false {
$cmd ++= ['--no-create-home']
} else if $user.home == true {
$cmd ++= ['--create-home']
} else if ($user.home | describe) == string {
$cmd ++= ['--home-dir', $""($user.home)""]
}
} else {
$cmd ++= ['--create-home']
}
if 'comment' in ($user) {
$cmd ++= ['--comment', $""($user.comment)""]
}
if 'root' in ($user) and $user.root {
$groups ++= ['sudo']
}
if 'groups' in ($user) {
$groups ++= [$user.groups]
}
$cmd ++= ['-G', $""($groups | flatten -a | str join ,)""]
# At the end
$cmd ++= [$user.name]
print $"Running (ansi green)($cmd | str join ' ')(ansi reset)"
^bash -c $"($cmd | str join ' ')"
if $user.password {
^sudo passwd $user.name
}
}
} else {
return 0
}
}
def main [] -> int {
let sources = (open deploy.nuon)
let to_reboot = (input $"Finished deploying. Reboot? [(ansi green)Y(ansi reset)/(ansi red)N(ansi reset)] ")
if ($to_reboot | str starts-with -i 'Y') or ($to_reboot | is-empty) {
^sudo shutdown -r now 'Rebooting after deploying'
} else {
exit 0
}
}