Last active
June 29, 2024 16:20
-
-
Save Bryan2333/1d527e9f348e722f3ef422f55fa84b6d to your computer and use it in GitHub Desktop.
本地仓库localrepo相关脚本
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env fish | |
if ! fish_is_root_user | |
echo "This script must be run as root!" | |
exit 1 | |
end | |
if ! type -q rsync | |
echo "Please install rsync first!" | |
exit 1 | |
end | |
set REPO_PATH "/srv/http/localrepo" | |
set REPO_FILE "localrepo.db.tar.xz" | |
function add_package | |
set -l FILES $argv | |
for FILE in $FILES | |
if test -f $FILE && string match -qr ".pkg.tar." -- "$FILE" | |
set -l FILE_NAME (path basename $FILE) | |
rsync -v -og --chown=root:root --chmod=644 --remove-source-files $FILE $REPO_PATH/ | |
repo-add $REPO_PATH/$REPO_FILE $REPO_PATH/$FILE_NAME | |
else | |
echo "$FILE is not a valid package!" | |
end | |
end | |
end | |
function remove_package | |
set -l PACKAGES $argv | |
for PACKAGE in $PACKAGES | |
repo-remove $REPO_PATH/$REPO_FILE $PACKAGE 2>/dev/null | |
find $REPO_PATH -type f -iname "*$PACKAGE*" -exec rm -vf {} \; | |
end | |
end | |
switch $argv[1] | |
case add | |
if test (count $argv) -lt 2 | |
echo "You need to provide package files." | |
exit 1 | |
else | |
add_package $argv[2..-1] | |
end | |
case remove | |
if test (count $argv) -lt 2 | |
echo "You need to provide package names." | |
exit 1 | |
else | |
remove_package $argv[2..-1] | |
end | |
case '*' | |
echo "Usage: localrepo [add|remove]" | |
exit 1 | |
end | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment