forked from tommilligan/qubes-recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recipe.sh
executable file
·246 lines (214 loc) · 8.6 KB
/
recipe.sh
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
########
# USAGE
#
# save this file in an AppVM
# run in dom0 shell by using:
# bash <(qvm-run --pass-io <src-vm> 'cat ~/Documents/qubes-recipe.sh')
########
qubesRecipeMode=$1
# Base template names
vanillaTemplateDebian="debian-8"
vanillaTemplateFedora="fedora-23"
exoticSuffix="-exotic"
# Utility functions
function qrInfo {
echo -e "\e[36mqubes-recipes|INFO|$@\e[39m" 1>&2
}
function qrWarn {
echo -e "\e[33mqubes-recipes|WARN|$@\e[39m" 1>&2
}
# Debug options
## Do not clone or create VMs
debugNoCreateTemplateVMs=false
debugNoCreateAppVMs=false
if [ "$qubesRecipeMode" == "debug" ] ; then
qrWarn 'Running in debug mode'
debugNoCreateTemplateVMs=true
debugNoCreateAppVMs=true
fi
# QubesOS wrappers
function qubesRecipeClone {
local originalTemplateName="$1"
local cloneTemplateName="$2"
qrInfo "Cloning '$cloneTemplateName' from '$originalTemplateName'"
if [ "$debugNoCreateTemplateVMs" = true ] ; then
qrWarn 'debugNoCreateTemplateVMs - no TemplateVM created'
else
qvm-clone $originalTemplateName $cloneTemplateName
fi
}
function qubesRecipeRunSynchronously {
local targetQube="$1"
local targetCommand="$2"
qrInfo "Connecting to '$targetQube' to run '$targetCommand'"
qvm-run --pass-io "$targetQube" "$targetCommand"
}
function qubesRecipeStart {
local targetQube="$1"
qrInfo "Starting '$targetQube'"
qvm-start "$targetQube"
}
function qubesRecipeShutdown {
local targetQube="$1"
qrInfo "Shutting down '$targetQube'"
qvm-shutdown "$targetQube" --wait
}
function qubesRecipeFirewallPolicy {
local targetQube="$1"
local targetPolicy="$2"
qrInfo "Firewall for '$targetQube' set to '$targetPolicy'"
qvm-firewall -P "$targetPolicy" "$targetQube"
}
function qubesRecipeTemplateStart {
local targetQube="$1"
qrInfo "Starting '$targetQube'"
qubesRecipeStart "$targetQube"
}
function qubesRecipeTemplateDisableFirewall {
local targetQube="$1"
qrInfo "Opening firewall for '$targetQube'"
qubesRecipeFirewallPolicy "$targetQube" "allow"
}
function qubesRecipeTemplateTeardown {
local targetQube="$1"
qrInfo "Tearing down '$targetQube' from customisation"
qubesRecipeFirewallPolicy "$targetQube" "deny"
qubesRecipeShutdown "$targetQube"
}
function qubesRecipeTemplateNewApp {
local templateQube="$1"
local appQube="$2"
local appColor="$3"
qrInfo "Creating AppVM '$appQube' from TemplateVM '$templateQube'"
if [ "$debugNoCreateAppVMs" = true ] ; then
qrWarn 'debugNoCreateAppVMs - no AppVM created'
else
qvm-create -t "$templateQube" -l "$appColor" "$appQube"
fi
}
function qubesRecipeAppSetPref {
local targetQube="$1"
local prefKey="$2"
local prefValue="$3"
qrInfo "Setting config for AppVM '${targetQube}': ${prefKey} = ${prefValue}"
qvm-prefs -s "$targetQube" "$prefKey" "$prefValue"
}
function qubesRecipeAppRemoveNetwork {
local targetQube="$1"
qrInfo "Removing network from '$targetQube'"
qubesRecipeAppSetPref "$targetQube" netvm none
}
function qubesRecipeAppSetColor {
local targetQube="$1"
local labelColor="$2"
qrInfo "Coloring '$targetQube' as '$labelColor'"
qubesRecipeAppSetPref "$targetQube" label "$labelColor"
}
# Subshell functions
function qubesRecipeSubTemplateNameExotic {
# Run as subshell - stdout = exoticTemplateName
local originalTemplateName="$1"
local exoticTemplateName="${originalTemplateName}${exoticSuffix}"
qrInfo "Generated exotic template name '$exoticTemplateName'"
echo "$exoticTemplateName"
}
# Recipes
function qubesRecipeUpgradeVanilla {
qrInfo "Ensuring vanilla TemplateVMs are upgraded"
# Fedora
local workingTemplate="$vanillaTemplateFedora"
qubesRecipeStart "$workingTemplate"
qubesRecipeRunSynchronously "$workingTemplate" 'sudo dnf check-update && sudo dnf -y upgrade'
qubesRecipeShutdown "$workingTemplate"
# Debian
local workingTemplate="$vanillaTemplateDebian"
qubesRecipeStart "$workingTemplate"
qubesRecipeRunSynchronously "$workingTemplate" 'sudo apt-get update && sudo apt-get -y upgrade'
qubesRecipeShutdown "$workingTemplate"
}
function qubesRecipeRecipeDebianExotic {
qrInfo "Starting DebianExotic recipe"
# Clone new TemplateVM
qrInfo "Making exotic TemplateVM for third-party packages"
local workingTemplate=$(qubesRecipeSubTemplateNameExotic "$vanillaTemplateDebian")
qubesRecipeClone "$vanillaTemplateDebian" "$workingTemplate"
## Setup
qubesRecipeTemplateStart "$workingTemplate"
qubesRecipeTemplateDisableFirewall "$workingTemplate"
## Add new repos
### Add chrome repo
qubesRecipeRunSynchronously "$workingTemplate" 'wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - && echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" | sudo tee /etc/apt/sources.list.d/google.list'
### Add spotify repo
qubesRecipeRunSynchronously "$workingTemplate" 'sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys BBEBDCB318AD50EC6865090613B00F1FD2C19886 && echo deb http://repository.spotify.com stable non-free | sudo tee /etc/apt/sources.list.d/spotify.list'
## Update package lists
qubesRecipeRunSynchronously "$workingTemplate" 'sudo apt-get update'
## Install from repos
qubesRecipeRunSynchronously "$workingTemplate" 'sudo apt-get -y install google-chrome-stable spotify-client'
## Teardown
qubesRecipeTemplateTeardown "$workingTemplate"
# Generate AppVMs
qrInfo "Creating AppVMs"
# juke (jukebox, media playback)
qubesRecipeTemplateNewApp "$workingTemplate" juke orange
}
function qubesRecipeRecipeFedoraExotic {
qrInfo "Starting FedoraExotic recipe"
# Clone new TemplateVM
qrInfo "Making exotic TemplateVM for third-party packages"
local workingTemplate=$(qubesRecipeSubTemplateNameExotic "$vanillaTemplateFedora")
qubesRecipeClone "$vanillaTemplateFedora" "$workingTemplate"
## Setup
qubesRecipeTemplateStart "$workingTemplate"
qubesRecipeTemplateDisableFirewall "$workingTemplate"
## Add new repos
### Add chrome repo
qubesRecipeRunSynchronously "$workingTemplate" 'echo -e "[google-chrome]\nname=google-chrome - \$basearch\nbaseurl=http://dl.google.com/linux/chrome/rpm/stable/\$basearch\nenabled=1\ngpgcheck=1\ngpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub" | sudo tee /etc/yum.repos.d/google-chrome.repo'
### Add VSCode repo
qubesRecipeRunSynchronously "$workingTemplate" 'sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc'
qubesRecipeRunSynchronously "$workingTemplate" 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" | sudo tee /etc/yum.repos.d/vscode.repo'
### Audacity is provided by default
## Update package lists
qubesRecipeRunSynchronously "$workingTemplate" 'dnf check-update'
## Install from repos
qubesRecipeRunSynchronously "$workingTemplate" 'sudo dnf -y install google-chrome-stable code audacity'
## Install .rpm packages
### Skype
qubesRecipeRunSynchronously "$workingTemplate" 'wget -P /tmp/ https://repo.skype.com/latest/skypeforlinux-64.rpm'
qubesRecipeRunSynchronously "$workingTemplate" 'sudo dnf -y install /tmp/skypeforlinux-64.rpm'
qubesRecipeRunSynchronously "$workingTemplate" 'rm /tmp/skypeforlinux-64.rpm'
## Teardown
qubesRecipeTemplateTeardown "$workingTemplate"
# Generate AppVMs
qrInfo "Creating AppVMs"
# av (online banking only)
qubesRecipeTemplateNewApp "$workingTemplate" av orange
# dev (online banking only)
qubesRecipeTemplateNewApp "$workingTemplate" dev orange
# usb (offline KeepassX storage; passwords, keys)
local workingApp="usb"
qubesRecipeTemplateNewApp "$workingTemplate" "$workingApp" yellow
qubesRecipeAppRemoveNetwork "$workingApp"
}
function qubesRecipeRecipeFedora {
qrInfo "Starting Fedora recipe"
local workingTemplate="$vanillaTemplateFedora"
# Generate AppVMs
qrInfo "Creating AppVMs"
# banking (online banking only)
qubesRecipeTemplateNewApp "$workingTemplate" banking blue
# vault (offline KeepassX storage; passwords, keys)
local workingApp="vault"
qubesRecipeTemplateNewApp "$workingTemplate" "$workingApp" black
qubesRecipeAppRemoveNetwork "$workingApp"
}
# Main
function qubesRecipe {
qrInfo "Running qubes-recipes"
# Check we're all up to date before starting'
qubesRecipeUpgradeVanilla
# Run recipes
qubesRecipeRecipeFedora
qubesRecipeRecipeFedoraExotic
qubesRecipeRecipeDebianExotic
}
qubesRecipe