forked from VictoryLinux/VictoryNixos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVersion_Upgrade.sh
executable file
·225 lines (173 loc) · 4.7 KB
/
Version_Upgrade.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
#!/usr/bin/env bash
# Version upgrade script for NixOS
# Ver. 1.3
#####################################################################
# ____ ____ __ #
# \ \ / / |__| ____ ________ ____ _______ ___ ___ #
# \ \/ / ___ | _|\__ __\ / _ \ | __ |\ \/ / #
# \ / | || |_ | | | |_| || | |__| \ / #
# \____/ |___||____| |__| \_____ / |__| |_| #
# #
# Victory Tek Install script #
# https://github.com/Victorytek #
#####################################################################
# Make sure each command executes properly
clear
check_exit_status() {
if [ $? -eq 0 ]
then
echo
echo "Success"
echo
else
echo
echo "[ERROR] Update Failed! Check the errors and try again"
echo
read -p "The last command exited with an error. Exit script? (y,Y/n,N) " answer
if [ "$answer" == "y" ]
then
exit 1
fi
fi
}
function greeting() {
echo -e "+-----------------------------------------------------------------+"
echo -e " Hello, $USER. Welcome to Victory Scripts. "
echo -e "+ +"
echo -e "+ You are attempting a Version Upgrade to +"
echo -e "+ +"
echo -e "+ NixOS +"
echo -e "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
# sleep 5s
echo "ARE YOU READY TO START? [y,n]"
read input
# did we get an input value?
if [ "$input" == "" ]; then
echo "Nothing was entered by the user"
# was it a y or a yes?
elif [[ "$input" == "y" ]] || [[ "$input" == "yes" ]]; then
echo "You replied $input, you are ready to start"
echo
echo "Starting NixOS Version Upgrade script."
echo
sleep 3s
# treat anything else as a negative response
else
echo "You replied $input, you are not ready"
echo
exit 1
fi
echo
check_exit_status
}
# Remove the container
function currentVersion() {
echo "You are running this version of Nixos currently"
echo
nixos-version
echo
check_exit_status
}
# Change to the new stable branch
function update() {
echo "What version of NixOS are we Upgrading to?"
echo
read -p 'nixos-' version
echo
echo "You want to upgrade to nixos-$version? [y,n]"
read input
# did we get an input value?
if [ "$input" == "" ]; then
echo "Nothing was entered by the user"
# was it a y or a yes?
elif [[ "$input" == "y" ]] || [[ "$input" == "yes" ]]; then
echo "You replied $input, you are ready to start"
echo
echo "Starting NixOS Version Upgrade script."
echo
sleep 3s
# treat anything else as a negative response
else
echo "You replied $input, you are not ready"
echo
exit 1
fi
echo
sudo nix-channel --add https://channels.nixos.org/nixos-$version nixos
echo
echo "Stable Channel Updated"
echo
check_exit_status
}
# List the branch
function list() {
sudo nix-channel --list | grep nixos
echo
echo "Current branch listed"
echo
echo "Is this the version you want to upgrade to? [y,n]"
read input
# did we get an input value?
if [ "$input" == "" ]; then
echo "Nothing was entered by the user"
# was it a y or a yes?
elif [[ "$input" == "y" ]] || [[ "$input" == "yes" ]]; then
echo "You replied $input, Let's upgrade NixOS"
echo
echo "Starting NixOS Version Upgrade."
echo
sleep 3s
# treat anything else as a negative response
else
echo "You replied $input, you are not ready"
echo
exit 1
fi
echo
check_exit_status
}
# Remove the container
function upgrade() {
sudo nixos-rebuild switch --upgrade
echo
echo "Nixos updated"
echo
sudo nano /etc/nixos/configuration.nix
echo
echo "Configuration version updated"
echo
check_exit_status
}
# Remove the old image
function reboot() {
echo "Do you want to restart? [y,n]"
read input
# did we get an input value?
if [ "$input" == "" ]; then
echo "Nothing was entered by the user"
# was it a y or a yes?
elif [[ "$input" == "y" ]] || [[ "$input" == "yes" ]]; then
echo "You replied $input, rebooting"
echo
sleep 3s
# treat anything else as a negative response
else
echo "You replied $input, not rebooting"
echo
exit 1
fi
echo
sudo shutdown --reboot 1
echo
echo "Rebooting in 1 minute"
echo
sleep 90
echo
check_exit_status
}
greeting
currentVersion
update
list
upgrade
reboot