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