最終更新 2 days ago

修正履歴 edfe6507a8bc7bdef7e72eb3c5e5586bc07d9e46

ubuntu_to_aos.sh Raw
1#!/bin/bash
2#==========================
3# Set up the environment
4#==========================
5set -e # exit on error
6set -o pipefail # exit on pipeline error
7set -u # treat unset variable as error
8export DEBIAN_FRONTEND=noninteractive
9export LATEST_VERSION="1.1.10"
10export CODE_NAME="noble"
11export OS_ID="AnduinOS"
12export CURRENT_VERSION=$(cat /etc/lsb-release | grep DISTRIB_RELEASE | cut -d "=" -f 2)
13
14#==========================
15# Color
16#==========================
17Green="\033[32m"
18Red="\033[31m"
19Yellow="\033[33m"
20Blue="\033[36m"
21Font="\033[0m"
22GreenBG="\033[42;37m"
23RedBG="\033[41;37m"
24OK="${Green}[ OK ]${Font}"
25ERROR="${Red}[FAILED]${Font}"
26WARNING="${Yellow}[ WARN ]${Font}"
27
28#==========================
29# Print Colorful Text
30#==========================
31function print_ok() {
32 echo -e "${OK} ${Blue} $1 ${Font}"
33}
34
35function print_error() {
36 echo -e "${ERROR} ${Red} $1 ${Font}"
37}
38
39function print_warn() {
40 echo -e "${WARNING} ${Yellow} $1 ${Font}"
41}
42
43#==========================
44# Judge function
45#==========================
46function judge() {
47 if [[ 0 -eq $? ]]; then
48 print_ok "$1 succeeded"
49 sleep 0.2
50 else
51 print_error "$1 failed"
52 exit 1
53 fi
54}
55#==========================
56
57# Clean up function
58#==========================
59function clean_up() {
60 # Clean up
61 print_ok "Cleaning up old files..."
62 sudo umount /mnt/anduinos_squashfs >/dev/null 2>&1 || true
63 sudo umount /mnt/anduinos_iso >/dev/null 2>&1 || true
64 sudo rm -rf /mnt/anduinos_squashfs >/dev/null 2>&1 || true
65 sudo rm -rf /mnt/anduinos_iso >/dev/null 2>&1 || true
66 sudo rm /tmp/AnduinOS-1.4.0* >/dev/null 2>&1 || true
67 judge "Cleanup"
68}
69
70clean_up
71
72print_ok "Checking system compatibility..."
73codename=$(lsb_release -cs)
74if [[ "$codename" != "questing" ]] then
75 print_error "This upgrade script only supports AnduinOS Noble, Verne, and Turing."
76 exit 1
77fi
78judge "System compatibility check"
79
80print_ok "Installing required packages (aria2, curl, lsb-release)..."
81sudo apt install -y aria2 curl lsb-release
82judge "Install required packages"
83
84# $LANG maybe en_US.UTF-8, so we use only the `en_US` part
85CURRENT_LANG=${LANG%%.*}
86DOWNLOAD_URL="https://download.anduinos.com/1.4/1.4.0/AnduinOS-1.4.0-${CURRENT_LANG}.torrent"
87HASH_URL="https://download.anduinos.com/1.4/1.4.0/AnduinOS-1.4.0-${CURRENT_LANG}.sha256"
88
89print_ok "Current system language detected: ${CURRENT_LANG}"
90print_ok "Attempting to download with URL: ${DOWNLOAD_URL}"
91
92# If download URL is not reachable, fallback to en_US
93if ! curl --head --silent --fail "$DOWNLOAD_URL" >/dev/null; then
94 print_warn "Language pack for ${CURRENT_LANG} not found, falling back to en_US"
95 DOWNLOAD_URL="https://download.anduinos.com/1.4/1.4.0/AnduinOS-1.4.0-en_US.torrent"
96 HASH_URL="https://download.anduinos.com/1.4/1.4.0/AnduinOS-1.4.0-en_US.sha256"
97fi
98
99# Ensure download URL is reachable
100if ! curl --head --silent --fail "$DOWNLOAD_URL" >/dev/null; then
101 print_error "Download URL is not reachable. Please check your network connection."
102 exit 1
103fi
104
105print_ok "Downloading AnduinOS 1.4.0 torrent, please wait..."
106curl -o /tmp/AnduinOS-1.4.0.torrent "$DOWNLOAD_URL"
107curl -o /tmp/AnduinOS-1.4.0.sha256 "$HASH_URL"
108judge "Download AnduinOS 1.4.0 torrent"
109
110print_ok "Starting download via aria2..."
111aria2c --allow-overwrite=true --seed-ratio=0.0 --seed-time=0 -x 16 -s 16 -k 1M -d /tmp /tmp/AnduinOS-1.4.0.torrent
112judge "Download AnduinOS 1.4.0 ISO"
113
114ISO_FILE_PATH=$(ls /tmp/AnduinOS-1.4.0*.iso | head -n 1)
115print_ok "Ensure downloaded ISO file exists..."
116if [[ -f "$ISO_FILE_PATH" ]]; then
117 print_ok "Downloaded ISO file found: $ISO_FILE_PATH"
118else
119 print_error "Downloaded ISO file not found."
120 exit 1
121fi
122
123SHA256_FILE_PATH="/tmp/AnduinOS-1.4.0.sha256"
124
125print_ok "Verifying download integrity..."
126ACTUAL_SHA256=$(sha256sum "$ISO_FILE_PATH" | awk '{print $1}')
127EXPECTED_SHA256=$(grep 'SHA256:' "$SHA256_FILE_PATH" | awk '{print $2}')
128if [[ "$ACTUAL_SHA256" == "$EXPECTED_SHA256" ]]; then
129 print_ok "SHA256 checksum verification passed."
130else
131 print_ok "Expected SHA256: $EXPECTED_SHA256"
132 print_ok "Actual SHA256: $ACTUAL_SHA256"
133 print_error "SHA256 checksum verification failed. The downloaded file may be corrupted."
134 exit 1
135fi
136
137print_ok "Mounting the ISO..."
138sudo mkdir -p /mnt/anduinos_iso
139sudo mount -o loop,ro "$ISO_FILE_PATH" /mnt/anduinos_iso
140judge "Mount ISO"
141
142print_ok "Verifying content in the ISO..."
143(
144 cd /mnt/anduinos_iso && \
145 sudo md5sum -c md5sum.txt && \
146 print_ok "Verify content succeeded."
147)
148print_ok "Content integrity verified."
149
150print_ok "Mounting the filesystem.squashfs..."
151sudo mkdir -p /mnt/anduinos_squashfs
152sudo mount -o loop,ro /mnt/anduinos_iso/casper/filesystem.squashfs /mnt/anduinos_squashfs
153judge "Mount filesystem.squashfs"
154
155print_ok "Updating package mirrors..."
156curl -s https://gitlab.aiursoft.cn/anduin/init-server/-/raw/master/mirror.sh?ref_type=heads | bash
157sudo apt update
158judge "Update package mirrors"
159
160# Reset apt settings
161print_ok "Resetting APT configuration files..."
162sudo rm /etc/apt/preferences.d/* >/dev/null 2>&1 || true
163judge "Reset APT configuration files"
164
165# Install missing package.
166print_ok "Installing missing packages from the new release..."
167MANIFEST_FILE="/mnt/anduinos_iso/casper/filesystem.manifest-desktop"
168PACKAGE_LIST=$(cut -d' ' -f1 "$MANIFEST_FILE" \
169 | grep -v '^linux-' \
170 | grep -v '^lib' \
171 | grep -v '^plymouth-' \
172 | grep -v '^software-properties-' \
173 | xargs)
174sudo apt install -y $PACKAGE_LIST
175judge "Install missing packages"
176
177print_ok "Removing obsolete packages..."
178sudo apt autoremove -y \
179 distro-info \
180 software-properties-gtk \
181 ubuntu-advantage-tools \
182 ubuntu-pro-client \
183 ubuntu-pro-client-l10n \
184 ubuntu-release-upgrader-gtk \
185 ubuntu-report \
186 ubuntu-settings \
187 update-notifier-common \
188 update-manager \
189 update-manager-core \
190 update-notifier \
191 ubuntu-release-upgrader-core \
192 ubuntu-advantage-desktop-daemon \
193 kgx
194judge "Remove obsolete packages"
195
196print_ok "Upgrading installed packages..."
197sudo apt upgrade -y
198sudo apt autoremove --purge -y
199judge "System package cleanup"
200
201print_ok "Upgrading GNOME Shell extensions..."
202sudo rsync -Aax --update --delete /mnt/anduinos_squashfs/usr/share/gnome-shell/extensions/ /usr/share/gnome-shell/extensions/
203judge "Upgrade GNOME Shell extensions"
204
205print_ok "Upgrading APT configuration files..."
206sudo rsync -Aax --update --delete /mnt/anduinos_squashfs/etc/apt/apt.conf.d/ /etc/apt/apt.conf.d/
207judge "Upgrade APT configuration files"
208
209print_ok "Upgrading APT preferences files..."
210sudo rsync -Aax --update --delete /mnt/anduinos_squashfs/etc/apt/preferences.d/ /etc/apt/preferences.d/
211judge "Upgrade APT preferences files"
212
213print_ok "Upgrading session files..."
214sudo rsync -Aax --update --delete /mnt/anduinos_squashfs/usr/share/gnome-session/sessions/ /usr/share/gnome-session/sessions/
215sudo rsync -Aax --update --delete /mnt/anduinos_squashfs/usr/share/wayland-sessions/ /usr/share/wayland-sessions/
216judge "Upgrade session files"
217
218print_ok "Upgrading pixmaps..."
219sudo rsync -Aax --update --delete /mnt/anduinos_squashfs/usr/share/pixmaps/ /usr/share/pixmaps/
220judge "Upgrade pixmaps"
221
222print_ok "Upgrading python-apt templates and distro info..."
223sudo rsync -Aax --update --delete /mnt/anduinos_squashfs/usr/share/python-apt/templates/ /usr/share/python-apt/templates/
224sudo rsync -Aax --update --delete /mnt/anduinos_squashfs/usr/share/distro-info/ /usr/share/distro-info/
225judge "Upgrade python-apt templates and distro info"
226
227
228print_ok "Upgrading deskmon service..."
229systemctl --user stop deskmon.service || true
230sudo cp /mnt/anduinos_squashfs/usr/local/bin/deskmon /usr/local/bin/deskmon
231sudo cp /mnt/anduinos_squashfs/etc/systemd/user/deskmon.service /etc/systemd/user/deskmon.service
232sudo cp /mnt/anduinos_squashfs/etc/systemd/user/default.target.wants/deskmon.service /etc/systemd/user/default.target.wants/deskmon.service
233systemctl --user daemon-reload
234systemctl --user start deskmon.service
235judge "Upgrade deskmon service"
236
237print_ok "Updating Mozilla Team PPA..."
238sudo rm -f /etc/apt/sources.list.d/mozillateam*
239sudo cp /mnt/anduinos_squashfs/etc/apt/sources.list.d/mozillateam* /etc/apt/sources.list.d/
240judge "Update Mozilla Team PPA"
241
242print_ok "Updating system version information..."
243sudo cp /mnt/anduinos_squashfs/usr/bin/do_anduinos_upgrade /usr/local/bin/do_anduinos_upgrade
244sudo cp /mnt/anduinos_squashfs/usr/bin/add-apt-repository /usr/bin/add-apt-repository
245sudo cp /mnt/anduinos_squashfs/etc/lsb-release /etc/lsb-release
246sudo cp /mnt/anduinos_squashfs/etc/issue /etc/issue
247sudo cp /mnt/anduinos_squashfs/etc/issue.net /etc/issue
248sudo cp /mnt/anduinos_squashfs/etc/os-release /etc/os-release
249sudo cp /mnt/anduinos_squashfs/usr/lib/os-release /usr/lib/os-release
250sudo cp /mnt/anduinos_squashfs/etc/legal /etc/legal
251sudo cp /mnt/anduinos_squashfs/etc/sysctl.d/20-apparmor-donotrestrict.conf /etc/sysctl.d/20-apparmor-donotrestrict.conf
252judge "Update system version information"
253
254print_ok "Applying dconf settings patch..."
255VERSION=$(grep -oP "VERSION_ID=\"\\K\\d+\\.\\d+" /etc/os-release)
256curl -sL https://gitlab.aiursoft.cn/anduin/anduinos/-/raw/$VERSION/src/mods/35-dconf-patch/dconf.ini?ref_type=heads | dconf load /org/gnome/
257judge "Apply dconf settings patch"
258
259print_ok "Upgrade completed! Please reboot your system to apply all changes."
260
261print_ok "Starting cleanup..."
262clean_up
263