diff --git a/Makefile b/Makefile index fe7b8fb6127e25d9d5dc590989a53b826bc822eb..a473d6408488f9a1e31d130a5177c1bf3ae27c21 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,7 @@ OUT_DIR := output OUT_FILE := $(OUT_DIR)/hustmirror-cli OUT_MIRROR_DIR := $(OUT_DIR)/mirrors OUT_MIRROR_FILES := $(patsubst $(MIRROR_DIR)/%,$(OUT_MIRROR_DIR)/%,$(MIRROR_FILES)) +INSTALL_DIR := /usr/local/bin/ all: $(OUT_FILE) @echo "Done, object script is $(OUT_FILE)." @@ -18,6 +19,9 @@ all: $(OUT_FILE) test: $(OUT_FILE) @tests/test.sh +install: $(OUT_FILE) + @cp $(OUT_FILE) $(INSTALL_DIR) + $(OUT_FILE): $(TEMPLATE_FILE) $(OUT_MIRROR_FILES) $(INCLUDE_FILES) $(OTHER_FILES) @mkdir -p $(OUT_DIR) @echo "Process $<" diff --git a/scripts/template-instantiate.py b/scripts/template-instantiate.py index 20cf67b89b463af6125cca64c46eea883f04f312..06f14a3afc269b263d6583d40a17c789f38d315f 100755 --- a/scripts/template-instantiate.py +++ b/scripts/template-instantiate.py @@ -30,6 +30,7 @@ def replace_mirrors(str): for file in files: with open(file, 'r') as f: str += f.read() + str += '\n' str += '# END MIRRORS\n' return str diff --git a/src/mirrors/blackarch.sh b/src/mirrors/blackarch.sh new file mode 100644 index 0000000000000000000000000000000000000000..235f526ad2d1e1000a106dbdb5bea8d4a2a60816 --- /dev/null +++ b/src/mirrors/blackarch.sh @@ -0,0 +1,50 @@ +_blackarch_config_file="/etc/pacman.d/blackarch-mirrorlist" + +check() { + source_os_release + [ "$NAME" = "Arch Linux" ] +} + +install() { + config_file=$_blackarch_config_file + set_sudo + + $sudo cp ${config_file} ${config_file}.bak || { + print_error "Failed to backup ${config_file}" + return 1 + } + + old_config=$(cat ${config_file}) + { + cat << EOF | $sudo tee ${config_file} > /dev/null +# ${gen_tag} +Server = ${http}://${domain}/blackarch/\$repo/os/\$arch +${old_config} +EOF + } || { + print_error "Failed to add mirror to ${config_file}" + return 1 + } +} + +is_deployed() { + config_file=$_blackarch_config_file + pattern="^[^#]*Server\s*=\s*${http}://${domain}/blackarch/\\\$repo/os/\\\$arch" + grep -qE "${pattern}" ${config_file} +} + +can_recover() { + bak_file=${_blackarch_config_file}.bak + result=0 + test -f $bak_file || result=$? + return $result +} + +uninstall() { + config_file=$_blackarch_config_file + set_sudo + $sudo mv ${config_file}.bak ${config_file} || { + print_error "Failed to recover ${config_file}" + return 1 + } +}