From 804f926847eb8ce2d0716ecdbdcf345e788c0b0b Mon Sep 17 00:00:00 2001 From: Tianyi Jing Date: Thu, 7 Sep 2023 19:58:28 +0800 Subject: [PATCH] feat: add support for openKylin --- src/mirrors/openkylin.sh | 60 ++++++++++++++++++++++++++++++++++++++ tests/inside/openkylin.sh | 8 +++++ tests/outside/openkylin.sh | 13 +++++++++ 3 files changed, 81 insertions(+) create mode 100644 src/mirrors/openkylin.sh create mode 100644 tests/inside/openkylin.sh create mode 100755 tests/outside/openkylin.sh diff --git a/src/mirrors/openkylin.sh b/src/mirrors/openkylin.sh new file mode 100644 index 0000000..880d33a --- /dev/null +++ b/src/mirrors/openkylin.sh @@ -0,0 +1,60 @@ +check() { + source_os_release + [ "$NAME" = "openKylin" ] +} + +install() { + config_file="/etc/apt/sources.list" + source_os_release + + codename=${VERSION_CODENAME} + set_sudo + + $sudo cp ${config_file} ${config_file}.bak || { + print_error "Failed to backup ${config_file}" + return 1 + } + + new_file=$(sed -E -e "s|https?://([^/]+)/openkylin|${http}://hustmirror.cn/openkylin|" $config_file) + { + cat << EOF | $sudo tee ${config_file} > /dev/null +# ${gen_tag} +${new_file} +EOF + } || { + print_error "Failed to add mirror to ${config_file}" + return 1 + } + + confirm_y "Do you want to apt update?" && { + $sudo apt update || { + print_error "apt update failed" + return 1 + } + } +} + +uninstall() { + config_file="/etc/apt/sources.list" + set_sudo + $sudo mv ${config_file}.bak ${config_file} || { + print_error "Failed to recover ${config_file}" + return 1 + } +} + +is_deployed() { + config_file="/etc/apt/sources.list" + result=0 + $sudo grep -q "${gen_tag}" ${config_file} || result=$? + return $result +} + +can_recover() { + bak_file="/etc/apt/sources.list.bak" + result=0 + test -f $bak_file || result=$? + return $result +} + +# vim: set filetype=sh ts=4 sw=4 noexpandtab: diff --git a/tests/inside/openkylin.sh b/tests/inside/openkylin.sh new file mode 100644 index 0000000..5c68356 --- /dev/null +++ b/tests/inside/openkylin.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e + +config_file="/etc/apt/sources.list" +update_command="apt-get update" +recover_item="openkylin" + +source "$(realpath ${BASH_SOURCE%/*})/run_test.sh" diff --git a/tests/outside/openkylin.sh b/tests/outside/openkylin.sh new file mode 100755 index 0000000..ab4b0d3 --- /dev/null +++ b/tests/outside/openkylin.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -e + +source "$(realpath ${BASH_SOURCE%/*}/..)/utils.sh" + +images="openkylinux/yangtze" +test_file="openkylin.sh" + +for image in $images +do + run_docker +done + -- Gitee