最後活躍 2 weeks ago

ZeTian 已修改 2 weeks ago. 還原成這個修訂版本

1 file changed, 3 insertions, 2 deletions

do_anduinos_distupgrade.sh

@@ -229,13 +229,13 @@ function convert_old_to_new_format() {
229 229 bash -c "cat > /etc/apt/sources.list.d/ubuntu.sources" <<EOF
230 230 Types: deb
231 231 URIs: ${MIRROR_URL}
232 - Suites: plucky plucky-updates plucky-backports
232 + Suites: questing questing-updates questing-backports
233 233 Components: main restricted universe multiverse
234 234 Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
235 235
236 236 Types: deb
237 237 URIs: ${SECURITY_URL}
238 - Suites: plucky-security
238 + Suites: questing-security
239 239 Components: main restricted universe multiverse
240 240 Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
241 241 EOF
@@ -254,6 +254,7 @@ function replace_plucky_with_questing() {
254 254 rollback_on_error
255 255 fi
256 256
257 + # todo: replace 1.2.x(oracular)
257 258 sed -i 's/plucky/questing/g' /etc/apt/sources.list.d/ubuntu.sources
258 259 judge "Replace plucky with questing"
259 260

ZeTian 已修改 2 weeks ago. 還原成這個修訂版本

1 file changed, 2 insertions, 2 deletions

do_anduinos_distupgrade.sh

@@ -3,7 +3,7 @@
3 3 #=================================================
4 4 # AnduinOS Upgrade Script
5 5 #=================================================
6 - # This script upgrades AnduinOS from 1.3.7 (plucky)
6 + # This script upgrades AnduinOS
7 7 # to 1.4.0 (questing).
8 8 #
9 9 # Run this script as root.
@@ -370,7 +370,7 @@ function restore_ppa_sources() {
370 370 function main() {
371 371 print_ok "Starting AnduinOS upgrade process..."
372 372
373 - echo -e "${Yellow}WARNING: This script will upgrade your system from 1.3.7 (plucky) to 1.4.0 (questing).${Font}"
373 + echo -e "${Yellow}WARNING: This script will upgrade your system to 1.4.0 (questing).${Font}"
374 374 echo -e "${Yellow}Please ensure you have backed up important data before proceeding.${Font}"
375 375 read -p "Do you want to continue? (y/N): " confirm
376 376 if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then

ZeTian 已修改 3 weeks ago. 還原成這個修訂版本

1 file changed, 1 insertion, 2 deletions

do_anduinos_distupgrade.sh

@@ -422,5 +422,4 @@ function main() {
422 422 print_warn "Please reboot your system to complete the upgrade."
423 423 }
424 424
425 - # main
426 - update_release_files
425 + main

ZeTian 已修改 3 weeks ago. 還原成這個修訂版本

1 file changed, 25 insertions, 10 deletions

do_anduinos_distupgrade.sh

@@ -307,21 +307,35 @@ function update_release_files() {
307 307 # Update /etc/os-release
308 308 if [ -f "/etc/os-release" ]; then
309 309 print_ok "Updating /etc/os-release..."
310 - sed -i 's/UBUNTU_CODENAME=plucky/UBUNTU_CODENAME=questing/g' /etc/os-release
311 - sed -i 's/VERSION_CODENAME=plucky/VERSION_CODENAME=questing/g' /etc/os-release
312 - sed -i 's/VERSION_ID="1\.3\.7"/VERSION_ID="1.4.0"/g' /etc/os-release
313 - sed -i 's/VERSION="1\.3\.7 (plucky)"/VERSION="1.4.0 (questing)"/g' /etc/os-release
314 - sed -i 's/PRETTY_NAME="AnduinOS 1\.3\.7"/PRETTY_NAME="AnduinOS 1.4.0"/g' /etc/os-release
315 - sed -i 's/PRETTY_NAME="AnduinOS 1\.3\.7"/PRETTY_NAME="AnduinOS 1.4.0"/g' /etc/os-release
310 + bash -c "cat > /etc/os-release" <<EOF
311 + PRETTY_NAME="AnduinOS 1.4.0"
312 + NAME="AnduinOS"
313 + VERSION_ID="1.4.0"
314 + VERSION="1.4.0 (questing)"
315 + VERSION_CODENAME=questing
316 + ID=ubuntu
317 + ID_LIKE=debian
318 + HOME_URL="https://www.anduinos.com/"
319 + SUPPORT_URL="https://github.com/Anduin2017/AnduinOS/discussions"
320 + BUG_REPORT_URL="https://github.com/Anduin2017/AnduinOS/issues"
321 + PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
322 + UBUNTU_CODENAME=questing
323 + EOF
324 +
316 325 judge "Update /etc/os-release"
317 326 fi
318 327
319 328 # Update /etc/lsb-release
320 329 if [ -f "/etc/lsb-release" ]; then
321 330 print_ok "Updating /etc/lsb-release..."
322 - sed -i 's/DISTRIB_RELEASE=1\.3\.7/DISTRIB_RELEASE=1.4.0/g' /etc/lsb-release
323 - sed -i 's/DISTRIB_CODENAME=plucky/DISTRIB_CODENAME=questing/g' /etc/lsb-release
324 - sed -i 's/DISTRIB_DESCRIPTION="AnduinOS 1\.3\.7"/DISTRIB_DESCRIPTION="AnduinOS 1.4.0"/g' /etc/lsb-release
331 +
332 + bash -c "cat > /etc/lsb-release" <<EOF
333 + DISTRIB_ID=AnduinOS
334 + DISTRIB_RELEASE=1.4.0
335 + DISTRIB_CODENAME=questing
336 + DISTRIB_DESCRIPTION="AnduinOS 1.4.0"
337 + EOF
338 +
325 339 judge "Update /etc/lsb-release"
326 340 fi
327 341
@@ -408,4 +422,5 @@ function main() {
408 422 print_warn "Please reboot your system to complete the upgrade."
409 423 }
410 424
411 - main
425 + # main
426 + update_release_files

ZeTian 已修改 4 weeks ago. 還原成這個修訂版本

沒有任何變更

ZeTian 已修改 4 weeks ago. 還原成這個修訂版本

1 file changed, 94 insertions, 5 deletions

do_anduinos_distupgrade.sh

@@ -10,7 +10,7 @@
10 10 # or user with privileges.
11 11 #
12 12 # Example:
13 - # ./do_anduinos_distupgrade.sh
13 + # sudo ./do_anduinos_distupgrade.sh
14 14 #=================================================
15 15
16 16 set -e
@@ -44,14 +44,96 @@ function print_warn() {
44 44 echo -e "${WARNING} ${Yellow} $1 ${Font}"
45 45 }
46 46
47 + function rollback_on_error() {
48 + print_error "An error occurred during the upgrade process"
49 + print_warn "Starting rollback procedure..."
50 +
51 + # Restore ubuntu.sources if backup exists
52 + if [ -f "$UBUNTU_SOURCE_BACKUP/ubuntu.sources" ]; then
53 + print_ok "Restoring ubuntu.sources..."
54 + cp "$UBUNTU_SOURCE_BACKUP/ubuntu.sources" /etc/apt/sources.list.d/
55 + print_ok "Restored ubuntu.sources"
56 + fi
57 +
58 + # Restore sources.list if backup exists
59 + if [ -f "$UBUNTU_SOURCE_BACKUP/sources.list" ]; then
60 + print_ok "Restoring sources.list..."
61 + cp "$UBUNTU_SOURCE_BACKUP/sources.list" /etc/apt/
62 + print_ok "Restored sources.list"
63 + fi
64 +
65 + # Restore PPA sources
66 + if [ -d "$PPA_BACKUP_DIR" ]; then
67 + ppa_count=$(ls -1 "$PPA_BACKUP_DIR" 2>/dev/null | wc -l)
68 +
69 + if [ "$ppa_count" -gt 0 ]; then
70 + print_ok "Restoring PPA sources..."
71 + for file in "$PPA_BACKUP_DIR"/*; do
72 + if [ -f "$file" ]; then
73 + cp "$file" /etc/apt/sources.list.d/
74 + print_ok "Restored $(basename "$file")"
75 + fi
76 + done
77 + fi
78 + fi
79 +
80 + # Remove temporary apt configuration if exists
81 + if [ -f "/etc/apt/apt.conf.d/99-local-versions" ]; then
82 + rm -f /etc/apt/apt.conf.d/99-local-versions
83 + print_ok "Removed temporary apt configuration"
84 + fi
85 +
86 + # Run apt update to restore repository state
87 + print_ok "Running apt update to restore repository state..."
88 + apt update || true
89 +
90 + print_warn "Rollback completed"
91 + print_warn "Your system has been restored to the previous state"
92 + print_warn "Backup files are preserved in: $BACKUP_DIR"
93 + print_error "Please check the error messages above and try again"
94 +
95 + exit 1
96 + }
97 +
47 98 function judge() {
48 99 if [[ 0 -eq $? ]]; then
49 100 print_ok "$1 succeeded"
50 101 sleep 0.2
51 102 else
52 103 print_error "$1 failed"
104 + rollback_on_error
105 + fi
106 + }
107 +
108 + function check_disk_space() {
109 + print_ok "Checking available disk space..."
110 +
111 + # Get available space in /tmp (in KB)
112 + local tmp_space=$(df /tmp | awk 'NR==2 {print $4}')
113 + # Get available space in / (in KB)
114 + local root_space=$(df / | awk 'NR==2 {print $4}')
115 +
116 + # Convert to MB
117 + local tmp_space_mb=$((tmp_space / 1024))
118 + local root_space_mb=$((root_space / 1024))
119 +
120 + # Required space: 2GB = 2048MB
121 + local required_space=2048
122 +
123 + print_ok "Available space in /tmp: ${tmp_space_mb}MB"
124 + print_ok "Available space in /: ${root_space_mb}MB"
125 +
126 + if [ "$tmp_space_mb" -lt "$required_space" ]; then
127 + print_error "Insufficient disk space in /tmp. Required: ${required_space}MB, Available: ${tmp_space_mb}MB"
53 128 exit 1
54 129 fi
130 +
131 + if [ "$root_space_mb" -lt "$required_space" ]; then
132 + print_error "Insufficient disk space in /. Required: ${required_space}MB, Available: ${root_space_mb}MB"
133 + exit 1
134 + fi
135 +
136 + print_ok "Disk space check passed"
55 137 }
56 138
57 139 function update_system() {
@@ -112,7 +194,7 @@ function detect_apt_format() {
112 194 return 1
113 195 else
114 196 print_error "Cannot detect APT source format"
115 - exit 1
197 + rollback_on_error
116 198 fi
117 199 }
118 200
@@ -121,7 +203,7 @@ function convert_old_to_new_format() {
121 203
122 204 if [ ! -f "/etc/apt/sources.list" ] || [ ! -s "/etc/apt/sources.list" ]; then
123 205 print_error "/etc/apt/sources.list not found or empty"
124 - exit 1
206 + rollback_on_error
125 207 fi
126 208
127 209 # Backup the old sources.list
@@ -169,7 +251,7 @@ function replace_plucky_with_questing() {
169 251
170 252 if [ ! -f "/etc/apt/sources.list.d/ubuntu.sources" ]; then
171 253 print_error "/etc/apt/sources.list.d/ubuntu.sources not found"
172 - exit 1
254 + rollback_on_error
173 255 fi
174 256
175 257 sed -i 's/plucky/questing/g' /etc/apt/sources.list.d/ubuntu.sources
@@ -188,6 +270,10 @@ function install_coreutils_uutils() {
188 270 }
189 271
190 272 function run_dist_upgrade() {
273 + print_ok "Simulating apt dist-upgrade first..."
274 + apt -s dist-upgrade
275 + judge "apt -s dist-upgrade"
276 +
191 277 print_ok "Running apt dist-upgrade in non-interactive mode..."
192 278
193 279 # Set environment for non-interactive mode
@@ -280,10 +366,13 @@ function main() {
280 366
281 367 # Check if running as root
282 368 if [[ "$(id -u)" -ne 0 ]]; then
283 - print_error "This script must not be run as root. Please run as a normal user with privileges."
369 + print_error "This script must be run as root."
284 370 exit 1
285 371 fi
286 372
373 + # Step 0: Check disk space
374 + check_disk_space
375 +
287 376 # Step 1: Update current system
288 377 update_system
289 378

ZeTian 已修改 1 month ago. 還原成這個修訂版本

1 file changed, 30 insertions, 30 deletions

do_anduinos_distupgrade.sh

@@ -6,11 +6,11 @@
6 6 # This script upgrades AnduinOS from 1.3.7 (plucky)
7 7 # to 1.4.0 (questing).
8 8 #
9 - # Do NOT run this script as root. Run it as a normal
10 - # user with sudo privileges.
9 + # Run this script as root.
10 + # or user with privileges.
11 11 #
12 12 # Example:
13 - # bash ./upgrade.sh
13 + # ./do_anduinos_distupgrade.sh
14 14 #=================================================
15 15
16 16 set -e
@@ -56,9 +56,9 @@ function judge() {
56 56
57 57 function update_system() {
58 58 print_ok "Running apt update and upgrade..."
59 - sudo apt update
59 + apt update
60 60 judge "apt update"
61 - sudo apt upgrade -y
61 + apt upgrade -y
62 62 judge "apt upgrade"
63 63 }
64 64
@@ -69,13 +69,13 @@ function backup_ubuntu_sources() {
69 69
70 70 # Backup ubuntu.sources if exists
71 71 if [ -f "/etc/apt/sources.list.d/ubuntu.sources" ]; then
72 - sudo cp /etc/apt/sources.list.d/ubuntu.sources "$UBUNTU_SOURCE_BACKUP/"
72 + cp /etc/apt/sources.list.d/ubuntu.sources "$UBUNTU_SOURCE_BACKUP/"
73 73 print_ok "Backed up ubuntu.sources"
74 74 fi
75 75
76 76 # Backup sources.list if it exists and is not empty
77 77 if [ -f "/etc/apt/sources.list" ] && [ -s "/etc/apt/sources.list" ]; then
78 - sudo cp /etc/apt/sources.list "$UBUNTU_SOURCE_BACKUP/"
78 + cp /etc/apt/sources.list "$UBUNTU_SOURCE_BACKUP/"
79 79 print_ok "Backed up sources.list"
80 80 fi
81 81
@@ -91,7 +91,7 @@ function backup_and_remove_ppa() {
91 91 if [ -d "/etc/apt/sources.list.d" ]; then
92 92 for file in /etc/apt/sources.list.d/*; do
93 93 if [ -f "$file" ] && [ "$(basename "$file")" != "ubuntu.sources" ]; then
94 - sudo mv "$file" "$PPA_BACKUP_DIR/"
94 + mv "$file" "$PPA_BACKUP_DIR/"
95 95 print_ok "Moved $(basename "$file") to backup"
96 96 fi
97 97 done
@@ -125,7 +125,7 @@ function convert_old_to_new_format() {
125 125 fi
126 126
127 127 # Backup the old sources.list
128 - sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
128 + cp /etc/apt/sources.list /etc/apt/sources.list.backup
129 129
130 130 # Extract mirror URLs from existing sources.list
131 131 # Try to detect main archive mirror
@@ -144,7 +144,7 @@ function convert_old_to_new_format() {
144 144 print_ok "Detected security URL: $SECURITY_URL"
145 145
146 146 # Create new ubuntu.sources file using detected mirrors
147 - sudo bash -c "cat > /etc/apt/sources.list.d/ubuntu.sources" <<EOF
147 + bash -c "cat > /etc/apt/sources.list.d/ubuntu.sources" <<EOF
148 148 Types: deb
149 149 URIs: ${MIRROR_URL}
150 150 Suites: plucky plucky-updates plucky-backports
@@ -159,7 +159,7 @@ Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
159 159 EOF
160 160
161 161 # Clear the old sources.list
162 - sudo bash -c 'echo "# This file is deprecated. See /etc/apt/sources.list.d/ubuntu.sources" > /etc/apt/sources.list'
162 + bash -c 'echo "# This file is deprecated. See /etc/apt/sources.list.d/ubuntu.sources" > /etc/apt/sources.list'
163 163
164 164 judge "Convert to new format"
165 165 }
@@ -172,18 +172,18 @@ function replace_plucky_with_questing() {
172 172 exit 1
173 173 fi
174 174
175 - sudo sed -i 's/plucky/questing/g' /etc/apt/sources.list.d/ubuntu.sources
175 + sed -i 's/plucky/questing/g' /etc/apt/sources.list.d/ubuntu.sources
176 176 judge "Replace plucky with questing"
177 177
178 178 print_ok "Running apt update with questing repositories..."
179 - sudo apt update
179 + apt update
180 180 judge "apt update with questing"
181 181 }
182 182
183 183 function install_coreutils_uutils() {
184 184 print_ok "Installing coreutils-from-uutils..."
185 185
186 - sudo apt install -y coreutils-from-uutils
186 + apt install -y coreutils-from-uutils
187 187 judge "Install coreutils-from-uutils"
188 188 }
189 189
@@ -194,7 +194,7 @@ function run_dist_upgrade() {
194 194 export DEBIAN_FRONTEND=noninteractive
195 195
196 196 # Configure dpkg to keep local versions by default
197 - sudo bash -c 'cat > /etc/apt/apt.conf.d/99-local-versions <<EOF
197 + bash -c 'cat > /etc/apt/apt.conf.d/99-local-versions <<EOF
198 198 Dpkg::Options {
199 199 "--force-confdef";
200 200 "--force-confold";
@@ -202,7 +202,7 @@ Dpkg::Options {
202 202 EOF'
203 203
204 204 # Run dist-upgrade
205 - sudo bash -c 'DEBIAN_FRONTEND=noninteractive APT_LISTCHANGES_FRONTEND=none \
205 + bash -c 'DEBIAN_FRONTEND=noninteractive APT_LISTCHANGES_FRONTEND=none \
206 206 apt-get -y dist-upgrade \
207 207 -o Dpkg::Options::="--force-confdef" \
208 208 -o Dpkg::Options::="--force-confold"'
@@ -210,7 +210,7 @@ EOF'
210 210 judge "apt dist-upgrade"
211 211
212 212 # Remove temporary configuration
213 - sudo rm -f /etc/apt/apt.conf.d/99-local-versions
213 + rm -f /etc/apt/apt.conf.d/99-local-versions
214 214
215 215 unset DEBIAN_FRONTEND
216 216 }
@@ -221,21 +221,21 @@ function update_release_files() {
221 221 # Update /etc/os-release
222 222 if [ -f "/etc/os-release" ]; then
223 223 print_ok "Updating /etc/os-release..."
224 - sudo sed -i 's/UBUNTU_CODENAME=plucky/UBUNTU_CODENAME=questing/g' /etc/os-release
225 - sudo sed -i 's/VERSION_CODENAME=plucky/VERSION_CODENAME=questing/g' /etc/os-release
226 - sudo sed -i 's/VERSION_ID="1\.3\.7"/VERSION_ID="1.4.0"/g' /etc/os-release
227 - sudo sed -i 's/VERSION="1\.3\.7 (plucky)"/VERSION="1.4.0 (questing)"/g' /etc/os-release
228 - sudo sed -i 's/PRETTY_NAME="AnduinOS 1\.3\.7"/PRETTY_NAME="AnduinOS 1.4.0"/g' /etc/os-release
229 - sudo sed -i 's/PRETTY_NAME="AnduinOS 1\.3\.7"/PRETTY_NAME="AnduinOS 1.4.0"/g' /etc/os-release
224 + sed -i 's/UBUNTU_CODENAME=plucky/UBUNTU_CODENAME=questing/g' /etc/os-release
225 + sed -i 's/VERSION_CODENAME=plucky/VERSION_CODENAME=questing/g' /etc/os-release
226 + sed -i 's/VERSION_ID="1\.3\.7"/VERSION_ID="1.4.0"/g' /etc/os-release
227 + sed -i 's/VERSION="1\.3\.7 (plucky)"/VERSION="1.4.0 (questing)"/g' /etc/os-release
228 + sed -i 's/PRETTY_NAME="AnduinOS 1\.3\.7"/PRETTY_NAME="AnduinOS 1.4.0"/g' /etc/os-release
229 + sed -i 's/PRETTY_NAME="AnduinOS 1\.3\.7"/PRETTY_NAME="AnduinOS 1.4.0"/g' /etc/os-release
230 230 judge "Update /etc/os-release"
231 231 fi
232 232
233 233 # Update /etc/lsb-release
234 234 if [ -f "/etc/lsb-release" ]; then
235 235 print_ok "Updating /etc/lsb-release..."
236 - sudo sed -i 's/DISTRIB_RELEASE=1\.3\.7/DISTRIB_RELEASE=1.4.0/g' /etc/lsb-release
237 - sudo sed -i 's/DISTRIB_CODENAME=plucky/DISTRIB_CODENAME=questing/g' /etc/lsb-release
238 - sudo sed -i 's/DISTRIB_DESCRIPTION="AnduinOS 1\.3\.7"/DISTRIB_DESCRIPTION="AnduinOS 1.4.0"/g' /etc/lsb-release
236 + sed -i 's/DISTRIB_RELEASE=1\.3\.7/DISTRIB_RELEASE=1.4.0/g' /etc/lsb-release
237 + sed -i 's/DISTRIB_CODENAME=plucky/DISTRIB_CODENAME=questing/g' /etc/lsb-release
238 + sed -i 's/DISTRIB_DESCRIPTION="AnduinOS 1\.3\.7"/DISTRIB_DESCRIPTION="AnduinOS 1.4.0"/g' /etc/lsb-release
239 239 judge "Update /etc/lsb-release"
240 240 fi
241 241
@@ -251,13 +251,13 @@ function restore_ppa_sources() {
251 251 if [ "$ppa_count" -gt 0 ]; then
252 252 for file in "$PPA_BACKUP_DIR"/*; do
253 253 if [ -f "$file" ]; then
254 - sudo mv "$file" /etc/apt/sources.list.d/
254 + mv "$file" /etc/apt/sources.list.d/
255 255 print_ok "Restored $(basename "$file")"
256 256 fi
257 257 done
258 258
259 259 print_ok "Running apt update with restored PPAs..."
260 - sudo apt update
260 + apt update
261 261 judge "Restore PPA sources and update"
262 262 else
263 263 print_ok "No PPA sources to restore"
@@ -279,8 +279,8 @@ function main() {
279 279 fi
280 280
281 281 # Check if running as root
282 - if [[ "$(id -u)" -eq 0 ]]; then
283 - print_error "This script must not be run as root. Please run as a normal user with sudo privileges."
282 + if [[ "$(id -u)" -ne 0 ]]; then
283 + print_error "This script must not be run as root. Please run as a normal user with privileges."
284 284 exit 1
285 285 fi
286 286

ZeTian 已修改 1 month ago. 還原成這個修訂版本

1 file changed, 5 insertions, 1 deletion

do_anduinos_distupgrade.sh

@@ -202,7 +202,11 @@ Dpkg::Options {
202 202 EOF'
203 203
204 204 # Run dist-upgrade
205 - sudo apt dist-upgrade -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"
205 + sudo bash -c 'DEBIAN_FRONTEND=noninteractive APT_LISTCHANGES_FRONTEND=none \
206 + apt-get -y dist-upgrade \
207 + -o Dpkg::Options::="--force-confdef" \
208 + -o Dpkg::Options::="--force-confold"'
209 +
206 210 judge "apt dist-upgrade"
207 211
208 212 # Remove temporary configuration

ZeTian 已修改 1 month ago. 還原成這個修訂版本

1 file changed, 14 insertions, 17 deletions

do_anduinos_distupgrade.sh

@@ -202,11 +202,7 @@ Dpkg::Options {
202 202 EOF'
203 203
204 204 # Run dist-upgrade
205 - # sudo apt dist-upgrade -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"
206 - sudo bash -c 'DEBIAN_FRONTEND=noninteractive APT_LISTCHANGES_FRONTEND=none \
207 - apt-get -y dist-upgrade \
208 - -o Dpkg::Options::="--force-confdef" \
209 - -o Dpkg::Options::="--force-confold"'
205 + sudo apt dist-upgrade -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"
210 206 judge "apt dist-upgrade"
211 207
212 208 # Remove temporary configuration
@@ -224,8 +220,9 @@ function update_release_files() {
224 220 sudo sed -i 's/UBUNTU_CODENAME=plucky/UBUNTU_CODENAME=questing/g' /etc/os-release
225 221 sudo sed -i 's/VERSION_CODENAME=plucky/VERSION_CODENAME=questing/g' /etc/os-release
226 222 sudo sed -i 's/VERSION_ID="1\.3\.7"/VERSION_ID="1.4.0"/g' /etc/os-release
227 - sudo sed -i 's/VERSION="1\.3\.7/VERSION="1.4.0/g' /etc/os-release
228 - sudo sed -i 's/PRETTY_NAME="AnduinOS 1\.3\.7"/PRETTY_NAME="AnduinOS 1.4.0"/g' /etc/os-release
223 + sudo sed -i 's/VERSION="1\.3\.7 (plucky)"/VERSION="1.4.0 (questing)"/g' /etc/os-release
224 + sudo sed -i 's/PRETTY_NAME="AnduinOS 1\.3\.7"/PRETTY_NAME="AnduinOS 1.4.0"/g' /etc/os-release
225 + sudo sed -i 's/PRETTY_NAME="AnduinOS 1\.3\.7"/PRETTY_NAME="AnduinOS 1.4.0"/g' /etc/os-release
229 226 judge "Update /etc/os-release"
230 227 fi
231 228
@@ -283,33 +280,33 @@ function main() {
283 280 exit 1
284 281 fi
285 282
286 - # Update current system
283 + # Step 1: Update current system
287 284 update_system
288 285
289 - # Backup Ubuntu official sources
286 + # Step 2: Backup Ubuntu official sources
290 287 backup_ubuntu_sources
291 288
292 - # Backup and remove PPA sources
289 + # Step 3: Backup and remove PPA sources
293 290 backup_and_remove_ppa
294 291
295 - # Detect and convert APT format if needed
292 + # Step 4: Detect and convert APT format if needed
296 293 if ! detect_apt_format; then
297 294 convert_old_to_new_format
298 295 fi
299 296
300 - # Replace plucky with questing
297 + # Step 5: Replace plucky with questing
301 298 replace_plucky_with_questing
302 299
303 - # Install coreutils-from-uutils
300 + # Step 6: Install coreutils-from-uutils
304 301 install_coreutils_uutils
305 302
306 - # Run dist-upgrade
303 + # Step 7: Run dist-upgrade
307 304 run_dist_upgrade
308 305
309 - # Update release files
306 + # Step 8: Update release files
310 307 update_release_files
311 308
312 - # Restore PPA sources
309 + # Step 9: Restore PPA sources
313 310 restore_ppa_sources
314 311
315 312 print_ok "Upgrade completed successfully!"
@@ -318,4 +315,4 @@ function main() {
318 315 print_warn "Please reboot your system to complete the upgrade."
319 316 }
320 317
321 - main
318 + main

ZeTian 已修改 1 month ago. 還原成這個修訂版本

1 file changed, 321 insertions

do_anduinos_distupgrade.sh(檔案已創建)

@@ -0,0 +1,321 @@
1 + #!/bin/bash
2 +
3 + #=================================================
4 + # AnduinOS Upgrade Script
5 + #=================================================
6 + # This script upgrades AnduinOS from 1.3.7 (plucky)
7 + # to 1.4.0 (questing).
8 + #
9 + # Do NOT run this script as root. Run it as a normal
10 + # user with sudo privileges.
11 + #
12 + # Example:
13 + # bash ./upgrade.sh
14 + #=================================================
15 +
16 + set -e
17 + set -o pipefail
18 + set -u
19 +
20 + Green="\033[32m"
21 + Red="\033[31m"
22 + Yellow="\033[33m"
23 + Blue="\033[36m"
24 + Font="\033[0m"
25 + GreenBG="\033[42;37m"
26 + RedBG="\033[41;37m"
27 + OK="${Green}[ OK ]${Font}"
28 + ERROR="${Red}[FAILED]${Font}"
29 + WARNING="${Yellow}[ WARN ]${Font}"
30 +
31 + BACKUP_DIR="/tmp/anduinos_upgrade_backup_$(date +%Y%m%d_%H%M%S)"
32 + PPA_BACKUP_DIR="$BACKUP_DIR/ppa"
33 + UBUNTU_SOURCE_BACKUP="$BACKUP_DIR/ubuntu_sources"
34 +
35 + function print_ok() {
36 + echo -e "${OK} ${Blue} $1 ${Font}"
37 + }
38 +
39 + function print_error() {
40 + echo -e "${ERROR} ${Red} $1 ${Font}"
41 + }
42 +
43 + function print_warn() {
44 + echo -e "${WARNING} ${Yellow} $1 ${Font}"
45 + }
46 +
47 + function judge() {
48 + if [[ 0 -eq $? ]]; then
49 + print_ok "$1 succeeded"
50 + sleep 0.2
51 + else
52 + print_error "$1 failed"
53 + exit 1
54 + fi
55 + }
56 +
57 + function update_system() {
58 + print_ok "Running apt update and upgrade..."
59 + sudo apt update
60 + judge "apt update"
61 + sudo apt upgrade -y
62 + judge "apt upgrade"
63 + }
64 +
65 + function backup_ubuntu_sources() {
66 + print_ok "Backing up Ubuntu official sources..."
67 +
68 + mkdir -p "$UBUNTU_SOURCE_BACKUP"
69 +
70 + # Backup ubuntu.sources if exists
71 + if [ -f "/etc/apt/sources.list.d/ubuntu.sources" ]; then
72 + sudo cp /etc/apt/sources.list.d/ubuntu.sources "$UBUNTU_SOURCE_BACKUP/"
73 + print_ok "Backed up ubuntu.sources"
74 + fi
75 +
76 + # Backup sources.list if it exists and is not empty
77 + if [ -f "/etc/apt/sources.list" ] && [ -s "/etc/apt/sources.list" ]; then
78 + sudo cp /etc/apt/sources.list "$UBUNTU_SOURCE_BACKUP/"
79 + print_ok "Backed up sources.list"
80 + fi
81 +
82 + judge "Backup Ubuntu sources"
83 + }
84 +
85 + function backup_and_remove_ppa() {
86 + print_ok "Backing up and temporarily removing PPA sources..."
87 +
88 + mkdir -p "$PPA_BACKUP_DIR"
89 +
90 + # Move all files in /etc/apt/sources.list.d/ except ubuntu.sources
91 + if [ -d "/etc/apt/sources.list.d" ]; then
92 + for file in /etc/apt/sources.list.d/*; do
93 + if [ -f "$file" ] && [ "$(basename "$file")" != "ubuntu.sources" ]; then
94 + sudo mv "$file" "$PPA_BACKUP_DIR/"
95 + print_ok "Moved $(basename "$file") to backup"
96 + fi
97 + done
98 + fi
99 +
100 + print_ok "PPA sources moved to: $PPA_BACKUP_DIR"
101 + judge "Backup and remove PPA sources"
102 + }
103 +
104 + function detect_apt_format() {
105 + print_ok "Detecting APT source format..."
106 +
107 + if [ -f "/etc/apt/sources.list.d/ubuntu.sources" ]; then
108 + print_ok "Detected new DEB822 format (ubuntu.sources)"
109 + return 0
110 + elif [ -f "/etc/apt/sources.list" ] && [ -s "/etc/apt/sources.list" ]; then
111 + print_ok "Detected old format (sources.list)"
112 + return 1
113 + else
114 + print_error "Cannot detect APT source format"
115 + exit 1
116 + fi
117 + }
118 +
119 + function convert_old_to_new_format() {
120 + print_ok "Converting old format to new DEB822 format..."
121 +
122 + if [ ! -f "/etc/apt/sources.list" ] || [ ! -s "/etc/apt/sources.list" ]; then
123 + print_error "/etc/apt/sources.list not found or empty"
124 + exit 1
125 + fi
126 +
127 + # Backup the old sources.list
128 + sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
129 +
130 + # Extract mirror URLs from existing sources.list
131 + # Try to detect main archive mirror
132 + MIRROR_URL=$(grep -E "^deb " /etc/apt/sources.list | grep -v "security" | head -1 | awk '{print $2}')
133 + if [ -z "$MIRROR_URL" ]; then
134 + MIRROR_URL="http://archive.ubuntu.com/ubuntu/"
135 + fi
136 +
137 + # Try to detect security mirror
138 + SECURITY_URL=$(grep -E "^deb " /etc/apt/sources.list | grep "security" | head -1 | awk '{print $2}')
139 + if [ -z "$SECURITY_URL" ]; then
140 + SECURITY_URL="http://security.ubuntu.com/ubuntu/"
141 + fi
142 +
143 + print_ok "Detected mirror URL: $MIRROR_URL"
144 + print_ok "Detected security URL: $SECURITY_URL"
145 +
146 + # Create new ubuntu.sources file using detected mirrors
147 + sudo bash -c "cat > /etc/apt/sources.list.d/ubuntu.sources" <<EOF
148 + Types: deb
149 + URIs: ${MIRROR_URL}
150 + Suites: plucky plucky-updates plucky-backports
151 + Components: main restricted universe multiverse
152 + Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
153 +
154 + Types: deb
155 + URIs: ${SECURITY_URL}
156 + Suites: plucky-security
157 + Components: main restricted universe multiverse
158 + Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
159 + EOF
160 +
161 + # Clear the old sources.list
162 + sudo bash -c 'echo "# This file is deprecated. See /etc/apt/sources.list.d/ubuntu.sources" > /etc/apt/sources.list'
163 +
164 + judge "Convert to new format"
165 + }
166 +
167 + function replace_plucky_with_questing() {
168 + print_ok "Replacing plucky with questing in ubuntu.sources..."
169 +
170 + if [ ! -f "/etc/apt/sources.list.d/ubuntu.sources" ]; then
171 + print_error "/etc/apt/sources.list.d/ubuntu.sources not found"
172 + exit 1
173 + fi
174 +
175 + sudo sed -i 's/plucky/questing/g' /etc/apt/sources.list.d/ubuntu.sources
176 + judge "Replace plucky with questing"
177 +
178 + print_ok "Running apt update with questing repositories..."
179 + sudo apt update
180 + judge "apt update with questing"
181 + }
182 +
183 + function install_coreutils_uutils() {
184 + print_ok "Installing coreutils-from-uutils..."
185 +
186 + sudo apt install -y coreutils-from-uutils
187 + judge "Install coreutils-from-uutils"
188 + }
189 +
190 + function run_dist_upgrade() {
191 + print_ok "Running apt dist-upgrade in non-interactive mode..."
192 +
193 + # Set environment for non-interactive mode
194 + export DEBIAN_FRONTEND=noninteractive
195 +
196 + # Configure dpkg to keep local versions by default
197 + sudo bash -c 'cat > /etc/apt/apt.conf.d/99-local-versions <<EOF
198 + Dpkg::Options {
199 + "--force-confdef";
200 + "--force-confold";
201 + }
202 + EOF'
203 +
204 + # Run dist-upgrade
205 + # sudo apt dist-upgrade -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"
206 + sudo bash -c 'DEBIAN_FRONTEND=noninteractive APT_LISTCHANGES_FRONTEND=none \
207 + apt-get -y dist-upgrade \
208 + -o Dpkg::Options::="--force-confdef" \
209 + -o Dpkg::Options::="--force-confold"'
210 + judge "apt dist-upgrade"
211 +
212 + # Remove temporary configuration
213 + sudo rm -f /etc/apt/apt.conf.d/99-local-versions
214 +
215 + unset DEBIAN_FRONTEND
216 + }
217 +
218 + function update_release_files() {
219 + print_ok "Updating release information files..."
220 +
221 + # Update /etc/os-release
222 + if [ -f "/etc/os-release" ]; then
223 + print_ok "Updating /etc/os-release..."
224 + sudo sed -i 's/UBUNTU_CODENAME=plucky/UBUNTU_CODENAME=questing/g' /etc/os-release
225 + sudo sed -i 's/VERSION_CODENAME=plucky/VERSION_CODENAME=questing/g' /etc/os-release
226 + sudo sed -i 's/VERSION_ID="1\.3\.7"/VERSION_ID="1.4.0"/g' /etc/os-release
227 + sudo sed -i 's/VERSION="1\.3\.7/VERSION="1.4.0/g' /etc/os-release
228 + sudo sed -i 's/PRETTY_NAME="AnduinOS 1\.3\.7"/PRETTY_NAME="AnduinOS 1.4.0"/g' /etc/os-release
229 + judge "Update /etc/os-release"
230 + fi
231 +
232 + # Update /etc/lsb-release
233 + if [ -f "/etc/lsb-release" ]; then
234 + print_ok "Updating /etc/lsb-release..."
235 + sudo sed -i 's/DISTRIB_RELEASE=1\.3\.7/DISTRIB_RELEASE=1.4.0/g' /etc/lsb-release
236 + sudo sed -i 's/DISTRIB_CODENAME=plucky/DISTRIB_CODENAME=questing/g' /etc/lsb-release
237 + sudo sed -i 's/DISTRIB_DESCRIPTION="AnduinOS 1\.3\.7"/DISTRIB_DESCRIPTION="AnduinOS 1.4.0"/g' /etc/lsb-release
238 + judge "Update /etc/lsb-release"
239 + fi
240 +
241 + print_ok "Release files updated successfully"
242 + }
243 +
244 + function restore_ppa_sources() {
245 + print_ok "Restoring PPA sources..."
246 +
247 + if [ -d "$PPA_BACKUP_DIR" ]; then
248 + ppa_count=$(ls -1 "$PPA_BACKUP_DIR" 2>/dev/null | wc -l)
249 +
250 + if [ "$ppa_count" -gt 0 ]; then
251 + for file in "$PPA_BACKUP_DIR"/*; do
252 + if [ -f "$file" ]; then
253 + sudo mv "$file" /etc/apt/sources.list.d/
254 + print_ok "Restored $(basename "$file")"
255 + fi
256 + done
257 +
258 + print_ok "Running apt update with restored PPAs..."
259 + sudo apt update
260 + judge "Restore PPA sources and update"
261 + else
262 + print_ok "No PPA sources to restore"
263 + fi
264 + else
265 + print_warn "PPA backup directory not found, skipping restore"
266 + fi
267 + }
268 +
269 + function main() {
270 + print_ok "Starting AnduinOS upgrade process..."
271 +
272 + echo -e "${Yellow}WARNING: This script will upgrade your system from 1.3.7 (plucky) to 1.4.0 (questing).${Font}"
273 + echo -e "${Yellow}Please ensure you have backed up important data before proceeding.${Font}"
274 + read -p "Do you want to continue? (y/N): " confirm
275 + if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then
276 + print_error "Upgrade process aborted by user."
277 + exit 1
278 + fi
279 +
280 + # Check if running as root
281 + if [[ "$(id -u)" -eq 0 ]]; then
282 + print_error "This script must not be run as root. Please run as a normal user with sudo privileges."
283 + exit 1
284 + fi
285 +
286 + # Update current system
287 + update_system
288 +
289 + # Backup Ubuntu official sources
290 + backup_ubuntu_sources
291 +
292 + # Backup and remove PPA sources
293 + backup_and_remove_ppa
294 +
295 + # Detect and convert APT format if needed
296 + if ! detect_apt_format; then
297 + convert_old_to_new_format
298 + fi
299 +
300 + # Replace plucky with questing
301 + replace_plucky_with_questing
302 +
303 + # Install coreutils-from-uutils
304 + install_coreutils_uutils
305 +
306 + # Run dist-upgrade
307 + run_dist_upgrade
308 +
309 + # Update release files
310 + update_release_files
311 +
312 + # Restore PPA sources
313 + restore_ppa_sources
314 +
315 + print_ok "Upgrade completed successfully!"
316 + print_ok "Your system has been upgraded to AnduinOS 1.4.0 (questing)"
317 + print_ok "Backup files are stored in: $BACKUP_DIR"
318 + print_warn "Please reboot your system to complete the upgrade."
319 + }
320 +
321 + main
上一頁 下一頁