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