Skip to content

Commit

Permalink
feat(repos): Upgrade systems to DEB822 format sources on groovy
Browse files Browse the repository at this point in the history
  • Loading branch information
isantop authored and mmstick committed Oct 20, 2020
1 parent bad9d79 commit 2736463
Showing 1 changed file with 66 additions and 2 deletions.
68 changes: 66 additions & 2 deletions src/release/repos.rs
Expand Up @@ -12,6 +12,9 @@ use ubuntu_version::Codename;
const BACKUP_MAIN_FILE: &str = "/etc/apt/sources.list.save";
const MAIN_FILE: &str = "/etc/apt/sources.list";
const PPA_DIR: &str = "/etc/apt/sources.list.d";
const NEW_MAIN_FILE: &str = "/etc/apt/sources.list.d/system.sources";
const APPS_FILE: &str = "/etc/apt/sources.list.d/pop-os-apps.sources";
const POP_PPA_FILE: &str = "/etc/apt/sources.list.d/pop-os-ppa.list";
const PROPRIETARY_URL: &str = "http://apt.pop-os.org/proprietary";

/// Backup the sources lists
Expand Down Expand Up @@ -215,14 +218,75 @@ fn replace_with_old_releases_(
Ok(())
}

pub fn create_new_sources_list(release: &str) -> io::Result<()> {
fs::write(MAIN_FILE, default_sources(release))?;
pub fn create_new_sources_list(release: &str) -> anyhow::Result<()> {
// Switchover is the release where DEB822-format sources were adopted.
// Currently 'groovy'
let switchover = "groovy";
let new_timestamp = release.parse::<Codename>()?.release_timestamp();
let switchover_timestamp = switchover.parse::<Codename>()?.release_timestamp();
if new_timestamp >= switchover_timestamp {
// new sources
fs::write(NEW_MAIN_FILE, new_system_sources(release))?;
fs::write(APPS_FILE, pop_apps_source(release))?;
fs::write(POP_PPA_FILE, pop_ppa_source(release))?;
fs::write(MAIN_FILE, new_sources_file())?;
} else {
// old sources
fs::write(MAIN_FILE, default_sources(release))?;
}

// TODO: Ensure that the GPG keys are added for the Ubuntu archives.

Ok(())
}

pub fn new_system_sources(release: &str) -> String {
format!(
r#"X-Repolib-Name: Pop_OS System Sources
Enabled: yes
Types: deb deb-src
URIs: http://us.archive.ubuntu.com/ubuntu/
Suites: {0} {0}-security {0}-updates {0}-backports
Components: main restricted universe multiverse
X-Repolib-Default-Mirror: http://us.archive.ubuntu.com/ubuntu/
"#,
release
)
}

pub fn new_sources_file() -> String {
format!(
r#"## This file is deprecated in Pop!_OS.
## See `man deb822` and /etc/apt/sources.list.d/system.sources.
"#
)
}

pub fn pop_apps_source(release: &str) -> String {
format!(
r#"X-Repolib-Name: Pop_OS Apps
Enabled: yes
Types: deb
URIs: http://apt.pop-os.org/proprietary
Suites: {0}
Components: main
"#,
release
)
}

pub fn pop_ppa_source(release: &str) -> String {
format!(
r#"## This file was generated by pop-upgrade
#
## X-Repolib-Name: Pop_OS PPA
deb http://ppa.launchpad.net/system76/pop/ubuntu {0} main
deb-src http://ppa.launchpad.net/system76/pop/ubuntu {0} main
"#,
release
)
}

pub fn default_sources(release: &str) -> String {
format!(
r#"# Ubuntu Repositories
Expand Down

0 comments on commit 2736463

Please sign in to comment.