1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#!/bin/bash
VERSION="0.1"
DESCRIPTION="Command/Subcommand line script template"
usage() {
echo "Usage: $0 (install|add_repo) args" 1>&2; exit 1;
}
function disable_repos {
# Disable all repos
for repo in "${repos[@]}"; do
zypper modifyrepo -d $repo
done
# Add OBS repository
zypper ar $OBS_REPOSITORY_URL obs_repository
}
function enable_repos {
# Remove our obs repository
zypper rr obs_repository
# Enable all repos
for repo in "${repos[@]}"; do
zypper modifyrepo -e $repo
done
}
install() {
shift # remove the subcommand
# Get enables repos and store them so we can enable them in the end.
readarray -t repos <<< "$(zypper ls -E | grep "Yes" | awk '{print $1}' )"
[ ! -z "$OBS_REPOSITORY_URL" ] && disable_repos
zypper ref
# TODO: use the "-r" option to avoid disabling/enabling repos
zypper --no-gpg-checks -n in "$@"
[ ! -z "$OBS_REPOSITORY_URL" ] && enable_repos
}
# Currently only this format is supported:
# obs_pkg_mgr add_repo <URI> <alias>
# obs_pkg_mgr add_repo <URI> <alias>
add_repo() {
shift # remove the subcommand
# No need to refresh the repo if we are inside OBS
if [ ! -z "$OBS_REPOSITORY_URL" ]; then
zypper ar -C -G "$@"
else
zypper ar -G "$@"
fi
}
case "$1" in
install)
install "$@"
;;
add_repo)
add_repo "$@"
;;
*)
usage
exit 1
;;
esac
exit 0;
|