do_anduinos_distupgrade.sh
· 12 KiB · Bash
Sin formato
#!/bin/bash
#=================================================
# AnduinOS Upgrade Script
#=================================================
# This script upgrades AnduinOS
# to 1.4.0 (questing).
#
# Run this script as root.
# or user with privileges.
#
# Example:
# sudo ./do_anduinos_distupgrade.sh
#=================================================
set -e
set -o pipefail
set -u
Green="\033[32m"
Red="\033[31m"
Yellow="\033[33m"
Blue="\033[36m"
Font="\033[0m"
GreenBG="\033[42;37m"
RedBG="\033[41;37m"
OK="${Green}[ OK ]${Font}"
ERROR="${Red}[FAILED]${Font}"
WARNING="${Yellow}[ WARN ]${Font}"
BACKUP_DIR="/tmp/anduinos_upgrade_backup_$(date +%Y%m%d_%H%M%S)"
PPA_BACKUP_DIR="$BACKUP_DIR/ppa"
UBUNTU_SOURCE_BACKUP="$BACKUP_DIR/ubuntu_sources"
function print_ok() {
echo -e "${OK} ${Blue} $1 ${Font}"
}
function print_error() {
echo -e "${ERROR} ${Red} $1 ${Font}"
}
function print_warn() {
echo -e "${WARNING} ${Yellow} $1 ${Font}"
}
function rollback_on_error() {
print_error "An error occurred during the upgrade process"
print_warn "Starting rollback procedure..."
# Restore ubuntu.sources if backup exists
if [ -f "$UBUNTU_SOURCE_BACKUP/ubuntu.sources" ]; then
print_ok "Restoring ubuntu.sources..."
cp "$UBUNTU_SOURCE_BACKUP/ubuntu.sources" /etc/apt/sources.list.d/
print_ok "Restored ubuntu.sources"
fi
# Restore sources.list if backup exists
if [ -f "$UBUNTU_SOURCE_BACKUP/sources.list" ]; then
print_ok "Restoring sources.list..."
cp "$UBUNTU_SOURCE_BACKUP/sources.list" /etc/apt/
print_ok "Restored sources.list"
fi
# Restore PPA sources
if [ -d "$PPA_BACKUP_DIR" ]; then
ppa_count=$(ls -1 "$PPA_BACKUP_DIR" 2>/dev/null | wc -l)
if [ "$ppa_count" -gt 0 ]; then
print_ok "Restoring PPA sources..."
for file in "$PPA_BACKUP_DIR"/*; do
if [ -f "$file" ]; then
cp "$file" /etc/apt/sources.list.d/
print_ok "Restored $(basename "$file")"
fi
done
fi
fi
# Remove temporary apt configuration if exists
if [ -f "/etc/apt/apt.conf.d/99-local-versions" ]; then
rm -f /etc/apt/apt.conf.d/99-local-versions
print_ok "Removed temporary apt configuration"
fi
# Run apt update to restore repository state
print_ok "Running apt update to restore repository state..."
apt update || true
print_warn "Rollback completed"
print_warn "Your system has been restored to the previous state"
print_warn "Backup files are preserved in: $BACKUP_DIR"
print_error "Please check the error messages above and try again"
exit 1
}
function judge() {
if [[ 0 -eq $? ]]; then
print_ok "$1 succeeded"
sleep 0.2
else
print_error "$1 failed"
rollback_on_error
fi
}
function check_disk_space() {
print_ok "Checking available disk space..."
# Get available space in /tmp (in KB)
local tmp_space=$(df /tmp | awk 'NR==2 {print $4}')
# Get available space in / (in KB)
local root_space=$(df / | awk 'NR==2 {print $4}')
# Convert to MB
local tmp_space_mb=$((tmp_space / 1024))
local root_space_mb=$((root_space / 1024))
# Required space: 2GB = 2048MB
local required_space=2048
print_ok "Available space in /tmp: ${tmp_space_mb}MB"
print_ok "Available space in /: ${root_space_mb}MB"
if [ "$tmp_space_mb" -lt "$required_space" ]; then
print_error "Insufficient disk space in /tmp. Required: ${required_space}MB, Available: ${tmp_space_mb}MB"
exit 1
fi
if [ "$root_space_mb" -lt "$required_space" ]; then
print_error "Insufficient disk space in /. Required: ${required_space}MB, Available: ${root_space_mb}MB"
exit 1
fi
print_ok "Disk space check passed"
}
function update_system() {
print_ok "Running apt update and upgrade..."
apt update
judge "apt update"
apt upgrade -y
judge "apt upgrade"
}
function backup_ubuntu_sources() {
print_ok "Backing up Ubuntu official sources..."
mkdir -p "$UBUNTU_SOURCE_BACKUP"
# Backup ubuntu.sources if exists
if [ -f "/etc/apt/sources.list.d/ubuntu.sources" ]; then
cp /etc/apt/sources.list.d/ubuntu.sources "$UBUNTU_SOURCE_BACKUP/"
print_ok "Backed up ubuntu.sources"
fi
# Backup sources.list if it exists and is not empty
if [ -f "/etc/apt/sources.list" ] && [ -s "/etc/apt/sources.list" ]; then
cp /etc/apt/sources.list "$UBUNTU_SOURCE_BACKUP/"
print_ok "Backed up sources.list"
fi
judge "Backup Ubuntu sources"
}
function backup_and_remove_ppa() {
print_ok "Backing up and temporarily removing PPA sources..."
mkdir -p "$PPA_BACKUP_DIR"
# Move all files in /etc/apt/sources.list.d/ except ubuntu.sources
if [ -d "/etc/apt/sources.list.d" ]; then
for file in /etc/apt/sources.list.d/*; do
if [ -f "$file" ] && [ "$(basename "$file")" != "ubuntu.sources" ]; then
mv "$file" "$PPA_BACKUP_DIR/"
print_ok "Moved $(basename "$file") to backup"
fi
done
fi
print_ok "PPA sources moved to: $PPA_BACKUP_DIR"
judge "Backup and remove PPA sources"
}
function detect_apt_format() {
print_ok "Detecting APT source format..."
if [ -f "/etc/apt/sources.list.d/ubuntu.sources" ]; then
print_ok "Detected new DEB822 format (ubuntu.sources)"
return 0
elif [ -f "/etc/apt/sources.list" ] && [ -s "/etc/apt/sources.list" ]; then
print_ok "Detected old format (sources.list)"
return 1
else
print_error "Cannot detect APT source format"
rollback_on_error
fi
}
function convert_old_to_new_format() {
print_ok "Converting old format to new DEB822 format..."
if [ ! -f "/etc/apt/sources.list" ] || [ ! -s "/etc/apt/sources.list" ]; then
print_error "/etc/apt/sources.list not found or empty"
rollback_on_error
fi
# Backup the old sources.list
cp /etc/apt/sources.list /etc/apt/sources.list.backup
# Extract mirror URLs from existing sources.list
# Try to detect main archive mirror
MIRROR_URL=$(grep -E "^deb " /etc/apt/sources.list | grep -v "security" | head -1 | awk '{print $2}')
if [ -z "$MIRROR_URL" ]; then
MIRROR_URL="http://archive.ubuntu.com/ubuntu/"
fi
# Try to detect security mirror
SECURITY_URL=$(grep -E "^deb " /etc/apt/sources.list | grep "security" | head -1 | awk '{print $2}')
if [ -z "$SECURITY_URL" ]; then
SECURITY_URL="http://security.ubuntu.com/ubuntu/"
fi
print_ok "Detected mirror URL: $MIRROR_URL"
print_ok "Detected security URL: $SECURITY_URL"
# Create new ubuntu.sources file using detected mirrors
bash -c "cat > /etc/apt/sources.list.d/ubuntu.sources" <<EOF
Types: deb
URIs: ${MIRROR_URL}
Suites: plucky plucky-updates plucky-backports
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Types: deb
URIs: ${SECURITY_URL}
Suites: plucky-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
EOF
# Clear the old sources.list
bash -c 'echo "# This file is deprecated. See /etc/apt/sources.list.d/ubuntu.sources" > /etc/apt/sources.list'
judge "Convert to new format"
}
function replace_plucky_with_questing() {
print_ok "Replacing plucky with questing in ubuntu.sources..."
if [ ! -f "/etc/apt/sources.list.d/ubuntu.sources" ]; then
print_error "/etc/apt/sources.list.d/ubuntu.sources not found"
rollback_on_error
fi
sed -i 's/plucky/questing/g' /etc/apt/sources.list.d/ubuntu.sources
judge "Replace plucky with questing"
print_ok "Running apt update with questing repositories..."
apt update
judge "apt update with questing"
}
function install_coreutils_uutils() {
print_ok "Installing coreutils-from-uutils..."
apt install -y coreutils-from-uutils
judge "Install coreutils-from-uutils"
}
function run_dist_upgrade() {
print_ok "Simulating apt dist-upgrade first..."
apt -s dist-upgrade
judge "apt -s dist-upgrade"
print_ok "Running apt dist-upgrade in non-interactive mode..."
# Set environment for non-interactive mode
export DEBIAN_FRONTEND=noninteractive
# Configure dpkg to keep local versions by default
bash -c 'cat > /etc/apt/apt.conf.d/99-local-versions <<EOF
Dpkg::Options {
"--force-confdef";
"--force-confold";
}
EOF'
# Run dist-upgrade
bash -c 'DEBIAN_FRONTEND=noninteractive APT_LISTCHANGES_FRONTEND=none \
apt-get -y dist-upgrade \
-o Dpkg::Options::="--force-confdef" \
-o Dpkg::Options::="--force-confold"'
judge "apt dist-upgrade"
# Remove temporary configuration
rm -f /etc/apt/apt.conf.d/99-local-versions
unset DEBIAN_FRONTEND
}
function update_release_files() {
print_ok "Updating release information files..."
# Update /etc/os-release
if [ -f "/etc/os-release" ]; then
print_ok "Updating /etc/os-release..."
bash -c "cat > /etc/os-release" <<EOF
PRETTY_NAME="AnduinOS 1.4.0"
NAME="AnduinOS"
VERSION_ID="1.4.0"
VERSION="1.4.0 (questing)"
VERSION_CODENAME=questing
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.anduinos.com/"
SUPPORT_URL="https://github.com/Anduin2017/AnduinOS/discussions"
BUG_REPORT_URL="https://github.com/Anduin2017/AnduinOS/issues"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=questing
EOF
judge "Update /etc/os-release"
fi
# Update /etc/lsb-release
if [ -f "/etc/lsb-release" ]; then
print_ok "Updating /etc/lsb-release..."
bash -c "cat > /etc/lsb-release" <<EOF
DISTRIB_ID=AnduinOS
DISTRIB_RELEASE=1.4.0
DISTRIB_CODENAME=questing
DISTRIB_DESCRIPTION="AnduinOS 1.4.0"
EOF
judge "Update /etc/lsb-release"
fi
print_ok "Release files updated successfully"
}
function restore_ppa_sources() {
print_ok "Restoring PPA sources..."
if [ -d "$PPA_BACKUP_DIR" ]; then
ppa_count=$(ls -1 "$PPA_BACKUP_DIR" 2>/dev/null | wc -l)
if [ "$ppa_count" -gt 0 ]; then
for file in "$PPA_BACKUP_DIR"/*; do
if [ -f "$file" ]; then
mv "$file" /etc/apt/sources.list.d/
print_ok "Restored $(basename "$file")"
fi
done
print_ok "Running apt update with restored PPAs..."
apt update
judge "Restore PPA sources and update"
else
print_ok "No PPA sources to restore"
fi
else
print_warn "PPA backup directory not found, skipping restore"
fi
}
function main() {
print_ok "Starting AnduinOS upgrade process..."
echo -e "${Yellow}WARNING: This script will upgrade your system to 1.4.0 (questing).${Font}"
echo -e "${Yellow}Please ensure you have backed up important data before proceeding.${Font}"
read -p "Do you want to continue? (y/N): " confirm
if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then
print_error "Upgrade process aborted by user."
exit 1
fi
# Check if running as root
if [[ "$(id -u)" -ne 0 ]]; then
print_error "This script must be run as root."
exit 1
fi
# Step 0: Check disk space
check_disk_space
# Step 1: Update current system
update_system
# Step 2: Backup Ubuntu official sources
backup_ubuntu_sources
# Step 3: Backup and remove PPA sources
backup_and_remove_ppa
# Step 4: Detect and convert APT format if needed
if ! detect_apt_format; then
convert_old_to_new_format
fi
# Step 5: Replace plucky with questing
replace_plucky_with_questing
# Step 6: Install coreutils-from-uutils
install_coreutils_uutils
# Step 7: Run dist-upgrade
run_dist_upgrade
# Step 8: Update release files
update_release_files
# Step 9: Restore PPA sources
restore_ppa_sources
print_ok "Upgrade completed successfully!"
print_ok "Your system has been upgraded to AnduinOS 1.4.0 (questing)"
print_ok "Backup files are stored in: $BACKUP_DIR"
print_warn "Please reboot your system to complete the upgrade."
}
main
| 1 | #!/bin/bash |
| 2 | |
| 3 | #================================================= |
| 4 | # AnduinOS Upgrade Script |
| 5 | #================================================= |
| 6 | # This script upgrades AnduinOS |
| 7 | # to 1.4.0 (questing). |
| 8 | # |
| 9 | # Run this script as root. |
| 10 | # or user with privileges. |
| 11 | # |
| 12 | # Example: |
| 13 | # sudo ./do_anduinos_distupgrade.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 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 | |
| 98 | function judge() { |
| 99 | if [[ 0 -eq $? ]]; then |
| 100 | print_ok "$1 succeeded" |
| 101 | sleep 0.2 |
| 102 | else |
| 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" |
| 128 | exit 1 |
| 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" |
| 137 | } |
| 138 | |
| 139 | function update_system() { |
| 140 | print_ok "Running apt update and upgrade..." |
| 141 | apt update |
| 142 | judge "apt update" |
| 143 | apt upgrade -y |
| 144 | judge "apt upgrade" |
| 145 | } |
| 146 | |
| 147 | function backup_ubuntu_sources() { |
| 148 | print_ok "Backing up Ubuntu official sources..." |
| 149 | |
| 150 | mkdir -p "$UBUNTU_SOURCE_BACKUP" |
| 151 | |
| 152 | # Backup ubuntu.sources if exists |
| 153 | if [ -f "/etc/apt/sources.list.d/ubuntu.sources" ]; then |
| 154 | cp /etc/apt/sources.list.d/ubuntu.sources "$UBUNTU_SOURCE_BACKUP/" |
| 155 | print_ok "Backed up ubuntu.sources" |
| 156 | fi |
| 157 | |
| 158 | # Backup sources.list if it exists and is not empty |
| 159 | if [ -f "/etc/apt/sources.list" ] && [ -s "/etc/apt/sources.list" ]; then |
| 160 | cp /etc/apt/sources.list "$UBUNTU_SOURCE_BACKUP/" |
| 161 | print_ok "Backed up sources.list" |
| 162 | fi |
| 163 | |
| 164 | judge "Backup Ubuntu sources" |
| 165 | } |
| 166 | |
| 167 | function backup_and_remove_ppa() { |
| 168 | print_ok "Backing up and temporarily removing PPA sources..." |
| 169 | |
| 170 | mkdir -p "$PPA_BACKUP_DIR" |
| 171 | |
| 172 | # Move all files in /etc/apt/sources.list.d/ except ubuntu.sources |
| 173 | if [ -d "/etc/apt/sources.list.d" ]; then |
| 174 | for file in /etc/apt/sources.list.d/*; do |
| 175 | if [ -f "$file" ] && [ "$(basename "$file")" != "ubuntu.sources" ]; then |
| 176 | mv "$file" "$PPA_BACKUP_DIR/" |
| 177 | print_ok "Moved $(basename "$file") to backup" |
| 178 | fi |
| 179 | done |
| 180 | fi |
| 181 | |
| 182 | print_ok "PPA sources moved to: $PPA_BACKUP_DIR" |
| 183 | judge "Backup and remove PPA sources" |
| 184 | } |
| 185 | |
| 186 | function detect_apt_format() { |
| 187 | print_ok "Detecting APT source format..." |
| 188 | |
| 189 | if [ -f "/etc/apt/sources.list.d/ubuntu.sources" ]; then |
| 190 | print_ok "Detected new DEB822 format (ubuntu.sources)" |
| 191 | return 0 |
| 192 | elif [ -f "/etc/apt/sources.list" ] && [ -s "/etc/apt/sources.list" ]; then |
| 193 | print_ok "Detected old format (sources.list)" |
| 194 | return 1 |
| 195 | else |
| 196 | print_error "Cannot detect APT source format" |
| 197 | rollback_on_error |
| 198 | fi |
| 199 | } |
| 200 | |
| 201 | function convert_old_to_new_format() { |
| 202 | print_ok "Converting old format to new DEB822 format..." |
| 203 | |
| 204 | if [ ! -f "/etc/apt/sources.list" ] || [ ! -s "/etc/apt/sources.list" ]; then |
| 205 | print_error "/etc/apt/sources.list not found or empty" |
| 206 | rollback_on_error |
| 207 | fi |
| 208 | |
| 209 | # Backup the old sources.list |
| 210 | cp /etc/apt/sources.list /etc/apt/sources.list.backup |
| 211 | |
| 212 | # Extract mirror URLs from existing sources.list |
| 213 | # Try to detect main archive mirror |
| 214 | MIRROR_URL=$(grep -E "^deb " /etc/apt/sources.list | grep -v "security" | head -1 | awk '{print $2}') |
| 215 | if [ -z "$MIRROR_URL" ]; then |
| 216 | MIRROR_URL="http://archive.ubuntu.com/ubuntu/" |
| 217 | fi |
| 218 | |
| 219 | # Try to detect security mirror |
| 220 | SECURITY_URL=$(grep -E "^deb " /etc/apt/sources.list | grep "security" | head -1 | awk '{print $2}') |
| 221 | if [ -z "$SECURITY_URL" ]; then |
| 222 | SECURITY_URL="http://security.ubuntu.com/ubuntu/" |
| 223 | fi |
| 224 | |
| 225 | print_ok "Detected mirror URL: $MIRROR_URL" |
| 226 | print_ok "Detected security URL: $SECURITY_URL" |
| 227 | |
| 228 | # Create new ubuntu.sources file using detected mirrors |
| 229 | bash -c "cat > /etc/apt/sources.list.d/ubuntu.sources" <<EOF |
| 230 | Types: deb |
| 231 | URIs: ${MIRROR_URL} |
| 232 | Suites: plucky plucky-updates plucky-backports |
| 233 | Components: main restricted universe multiverse |
| 234 | Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg |
| 235 | |
| 236 | Types: deb |
| 237 | URIs: ${SECURITY_URL} |
| 238 | Suites: plucky-security |
| 239 | Components: main restricted universe multiverse |
| 240 | Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg |
| 241 | EOF |
| 242 | |
| 243 | # Clear the old sources.list |
| 244 | bash -c 'echo "# This file is deprecated. See /etc/apt/sources.list.d/ubuntu.sources" > /etc/apt/sources.list' |
| 245 | |
| 246 | judge "Convert to new format" |
| 247 | } |
| 248 | |
| 249 | function replace_plucky_with_questing() { |
| 250 | print_ok "Replacing plucky with questing in ubuntu.sources..." |
| 251 | |
| 252 | if [ ! -f "/etc/apt/sources.list.d/ubuntu.sources" ]; then |
| 253 | print_error "/etc/apt/sources.list.d/ubuntu.sources not found" |
| 254 | rollback_on_error |
| 255 | fi |
| 256 | |
| 257 | sed -i 's/plucky/questing/g' /etc/apt/sources.list.d/ubuntu.sources |
| 258 | judge "Replace plucky with questing" |
| 259 | |
| 260 | print_ok "Running apt update with questing repositories..." |
| 261 | apt update |
| 262 | judge "apt update with questing" |
| 263 | } |
| 264 | |
| 265 | function install_coreutils_uutils() { |
| 266 | print_ok "Installing coreutils-from-uutils..." |
| 267 | |
| 268 | apt install -y coreutils-from-uutils |
| 269 | judge "Install coreutils-from-uutils" |
| 270 | } |
| 271 | |
| 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 | |
| 277 | print_ok "Running apt dist-upgrade in non-interactive mode..." |
| 278 | |
| 279 | # Set environment for non-interactive mode |
| 280 | export DEBIAN_FRONTEND=noninteractive |
| 281 | |
| 282 | # Configure dpkg to keep local versions by default |
| 283 | bash -c 'cat > /etc/apt/apt.conf.d/99-local-versions <<EOF |
| 284 | Dpkg::Options { |
| 285 | "--force-confdef"; |
| 286 | "--force-confold"; |
| 287 | } |
| 288 | EOF' |
| 289 | |
| 290 | # Run dist-upgrade |
| 291 | bash -c 'DEBIAN_FRONTEND=noninteractive APT_LISTCHANGES_FRONTEND=none \ |
| 292 | apt-get -y dist-upgrade \ |
| 293 | -o Dpkg::Options::="--force-confdef" \ |
| 294 | -o Dpkg::Options::="--force-confold"' |
| 295 | |
| 296 | judge "apt dist-upgrade" |
| 297 | |
| 298 | # Remove temporary configuration |
| 299 | rm -f /etc/apt/apt.conf.d/99-local-versions |
| 300 | |
| 301 | unset DEBIAN_FRONTEND |
| 302 | } |
| 303 | |
| 304 | function update_release_files() { |
| 305 | print_ok "Updating release information files..." |
| 306 | |
| 307 | # Update /etc/os-release |
| 308 | if [ -f "/etc/os-release" ]; then |
| 309 | print_ok "Updating /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 | |
| 325 | judge "Update /etc/os-release" |
| 326 | fi |
| 327 | |
| 328 | # Update /etc/lsb-release |
| 329 | if [ -f "/etc/lsb-release" ]; then |
| 330 | print_ok "Updating /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 | |
| 339 | judge "Update /etc/lsb-release" |
| 340 | fi |
| 341 | |
| 342 | print_ok "Release files updated successfully" |
| 343 | } |
| 344 | |
| 345 | function restore_ppa_sources() { |
| 346 | print_ok "Restoring PPA sources..." |
| 347 | |
| 348 | if [ -d "$PPA_BACKUP_DIR" ]; then |
| 349 | ppa_count=$(ls -1 "$PPA_BACKUP_DIR" 2>/dev/null | wc -l) |
| 350 | |
| 351 | if [ "$ppa_count" -gt 0 ]; then |
| 352 | for file in "$PPA_BACKUP_DIR"/*; do |
| 353 | if [ -f "$file" ]; then |
| 354 | mv "$file" /etc/apt/sources.list.d/ |
| 355 | print_ok "Restored $(basename "$file")" |
| 356 | fi |
| 357 | done |
| 358 | |
| 359 | print_ok "Running apt update with restored PPAs..." |
| 360 | apt update |
| 361 | judge "Restore PPA sources and update" |
| 362 | else |
| 363 | print_ok "No PPA sources to restore" |
| 364 | fi |
| 365 | else |
| 366 | print_warn "PPA backup directory not found, skipping restore" |
| 367 | fi |
| 368 | } |
| 369 | |
| 370 | function main() { |
| 371 | print_ok "Starting AnduinOS upgrade process..." |
| 372 | |
| 373 | echo -e "${Yellow}WARNING: This script will upgrade your system to 1.4.0 (questing).${Font}" |
| 374 | echo -e "${Yellow}Please ensure you have backed up important data before proceeding.${Font}" |
| 375 | read -p "Do you want to continue? (y/N): " confirm |
| 376 | if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then |
| 377 | print_error "Upgrade process aborted by user." |
| 378 | exit 1 |
| 379 | fi |
| 380 | |
| 381 | # Check if running as root |
| 382 | if [[ "$(id -u)" -ne 0 ]]; then |
| 383 | print_error "This script must be run as root." |
| 384 | exit 1 |
| 385 | fi |
| 386 | |
| 387 | # Step 0: Check disk space |
| 388 | check_disk_space |
| 389 | |
| 390 | # Step 1: Update current system |
| 391 | update_system |
| 392 | |
| 393 | # Step 2: Backup Ubuntu official sources |
| 394 | backup_ubuntu_sources |
| 395 | |
| 396 | # Step 3: Backup and remove PPA sources |
| 397 | backup_and_remove_ppa |
| 398 | |
| 399 | # Step 4: Detect and convert APT format if needed |
| 400 | if ! detect_apt_format; then |
| 401 | convert_old_to_new_format |
| 402 | fi |
| 403 | |
| 404 | # Step 5: Replace plucky with questing |
| 405 | replace_plucky_with_questing |
| 406 | |
| 407 | # Step 6: Install coreutils-from-uutils |
| 408 | install_coreutils_uutils |
| 409 | |
| 410 | # Step 7: Run dist-upgrade |
| 411 | run_dist_upgrade |
| 412 | |
| 413 | # Step 8: Update release files |
| 414 | update_release_files |
| 415 | |
| 416 | # Step 9: Restore PPA sources |
| 417 | restore_ppa_sources |
| 418 | |
| 419 | print_ok "Upgrade completed successfully!" |
| 420 | print_ok "Your system has been upgraded to AnduinOS 1.4.0 (questing)" |
| 421 | print_ok "Backup files are stored in: $BACKUP_DIR" |
| 422 | print_warn "Please reboot your system to complete the upgrade." |
| 423 | } |
| 424 | |
| 425 | main |