Utoljára aktív 2 weeks ago

Revízió 02a849d87f5252dc3febcefd0c05a003586fe0ea

do_anduinos_distupgrade.sh Eredeti
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# Run this script as root.
10# or user with privileges.
11#
12# Example:
13# ./do_anduinos_distupgrade.sh
14#=================================================
15
16set -e
17set -o pipefail
18set -u
19
20Green="\033[32m"
21Red="\033[31m"
22Yellow="\033[33m"
23Blue="\033[36m"
24Font="\033[0m"
25GreenBG="\033[42;37m"
26RedBG="\033[41;37m"
27OK="${Green}[ OK ]${Font}"
28ERROR="${Red}[FAILED]${Font}"
29WARNING="${Yellow}[ WARN ]${Font}"
30
31BACKUP_DIR="/tmp/anduinos_upgrade_backup_$(date +%Y%m%d_%H%M%S)"
32PPA_BACKUP_DIR="$BACKUP_DIR/ppa"
33UBUNTU_SOURCE_BACKUP="$BACKUP_DIR/ubuntu_sources"
34
35function print_ok() {
36 echo -e "${OK} ${Blue} $1 ${Font}"
37}
38
39function print_error() {
40 echo -e "${ERROR} ${Red} $1 ${Font}"
41}
42
43function print_warn() {
44 echo -e "${WARNING} ${Yellow} $1 ${Font}"
45}
46
47function 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
57function update_system() {
58 print_ok "Running apt update and upgrade..."
59 apt update
60 judge "apt update"
61 apt upgrade -y
62 judge "apt upgrade"
63}
64
65function 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 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 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
85function 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 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
104function 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
119function 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 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 bash -c "cat > /etc/apt/sources.list.d/ubuntu.sources" <<EOF
148Types: deb
149URIs: ${MIRROR_URL}
150Suites: plucky plucky-updates plucky-backports
151Components: main restricted universe multiverse
152Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
153
154Types: deb
155URIs: ${SECURITY_URL}
156Suites: plucky-security
157Components: main restricted universe multiverse
158Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
159EOF
160
161 # Clear the old sources.list
162 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
167function 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 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 apt update
180 judge "apt update with questing"
181}
182
183function install_coreutils_uutils() {
184 print_ok "Installing coreutils-from-uutils..."
185
186 apt install -y coreutils-from-uutils
187 judge "Install coreutils-from-uutils"
188}
189
190function 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 bash -c 'cat > /etc/apt/apt.conf.d/99-local-versions <<EOF
198Dpkg::Options {
199 "--force-confdef";
200 "--force-confold";
201}
202EOF'
203
204 # Run dist-upgrade
205 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
210 judge "apt dist-upgrade"
211
212 # Remove temporary configuration
213 rm -f /etc/apt/apt.conf.d/99-local-versions
214
215 unset DEBIAN_FRONTEND
216}
217
218function 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 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 judge "Update /etc/os-release"
231 fi
232
233 # Update /etc/lsb-release
234 if [ -f "/etc/lsb-release" ]; then
235 print_ok "Updating /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 judge "Update /etc/lsb-release"
240 fi
241
242 print_ok "Release files updated successfully"
243}
244
245function restore_ppa_sources() {
246 print_ok "Restoring PPA sources..."
247
248 if [ -d "$PPA_BACKUP_DIR" ]; then
249 ppa_count=$(ls -1 "$PPA_BACKUP_DIR" 2>/dev/null | wc -l)
250
251 if [ "$ppa_count" -gt 0 ]; then
252 for file in "$PPA_BACKUP_DIR"/*; do
253 if [ -f "$file" ]; then
254 mv "$file" /etc/apt/sources.list.d/
255 print_ok "Restored $(basename "$file")"
256 fi
257 done
258
259 print_ok "Running apt update with restored PPAs..."
260 apt update
261 judge "Restore PPA sources and update"
262 else
263 print_ok "No PPA sources to restore"
264 fi
265 else
266 print_warn "PPA backup directory not found, skipping restore"
267 fi
268}
269
270function main() {
271 print_ok "Starting AnduinOS upgrade process..."
272
273 echo -e "${Yellow}WARNING: This script will upgrade your system from 1.3.7 (plucky) to 1.4.0 (questing).${Font}"
274 echo -e "${Yellow}Please ensure you have backed up important data before proceeding.${Font}"
275 read -p "Do you want to continue? (y/N): " confirm
276 if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then
277 print_error "Upgrade process aborted by user."
278 exit 1
279 fi
280
281 # Check if running as root
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 exit 1
285 fi
286
287 # Step 1: Update current system
288 update_system
289
290 # Step 2: Backup Ubuntu official sources
291 backup_ubuntu_sources
292
293 # Step 3: Backup and remove PPA sources
294 backup_and_remove_ppa
295
296 # Step 4: Detect and convert APT format if needed
297 if ! detect_apt_format; then
298 convert_old_to_new_format
299 fi
300
301 # Step 5: Replace plucky with questing
302 replace_plucky_with_questing
303
304 # Step 6: Install coreutils-from-uutils
305 install_coreutils_uutils
306
307 # Step 7: Run dist-upgrade
308 run_dist_upgrade
309
310 # Step 8: Update release files
311 update_release_files
312
313 # Step 9: Restore PPA sources
314 restore_ppa_sources
315
316 print_ok "Upgrade completed successfully!"
317 print_ok "Your system has been upgraded to AnduinOS 1.4.0 (questing)"
318 print_ok "Backup files are stored in: $BACKUP_DIR"
319 print_warn "Please reboot your system to complete the upgrade."
320}
321
322main