OSDN Git Service

[update] : libldac
[alterlinux/alterlinux-pkgbuilds.git] / get_from_aur.sh
index 29b7ad4..7c68346 100755 (executable)
@@ -12,8 +12,11 @@ script_name=$(basename ${0})
 
 script_path="$(readlink -f ${0%/*})"
 arch="x86_64"
+repo="alter-stable"
 debug=false
-
+force=false
+skip=false
+nocolor=false
 
 set -e
 
@@ -23,7 +26,9 @@ _usage() {
     echo
     echo " General options:"
     echo
-    echo "    -a | --arch <arch>        Specify the architecture."
+    echo "    -a | --arch <arch>        Specify the architecture"
+    echo "    -f | --force              Overwrite existing directory"
+    echo "    -s | --skip               Skip if PKGBUILD already exists"
     echo "    -r | --repo <repo>        Specify the repository name"
     echo "    -h | --help               This help messageExecuted via administrator web and Yama D Saba APIs"
 
@@ -104,7 +109,11 @@ _msg_info() {
         esac
     done
     shift $((OPTIND - 1))
-    echo ${echo_opts} "$( echo_color -t '36' "[${script_name}]")    $( echo_color -t '32' 'Info') ${*}"
+    if [[ "${nocolor}" = true ]]; then
+        echo ${echo_opts} "[${script_name}]    Info ${*}"
+    else
+        echo ${echo_opts} "$( echo_color -t '36' "[${script_name}]")    $( echo_color -t '32' 'Info') ${*}"
+    fi
 }
 
 
@@ -121,7 +130,11 @@ _msg_warn() {
         esac
     done
     shift $((OPTIND - 1))
-    echo ${echo_opts} "$( echo_color -t '36' "[${script_name}]") $( echo_color -t '33' 'Warning') ${*}" >&2
+    if [[ "${nocolor}" = true ]]; then
+        echo ${echo_opts} "[${script_name}] Warning ${*}"
+    else
+        echo ${echo_opts} "$( echo_color -t '36' "[${script_name}]") $( echo_color -t '33' 'Warning') ${*}" >&2
+    fi
 }
 
 
@@ -139,7 +152,11 @@ _msg_debug() {
     done
     shift $((OPTIND - 1))
     if [[ "${debug}" = true ]]; then
-        echo ${echo_opts} "$( echo_color -t '36' "[${script_name}]")   $( echo_color -t '35' 'Debug') ${*}"
+        if [[ "${nocolor}" = true ]]; then
+            echo ${echo_opts} "[${script_name}]   Debug ${*}"
+        else
+            echo ${echo_opts} "$( echo_color -t '36' "[${script_name}]")   $( echo_color -t '35' 'Debug') ${*}"
+        fi
     fi
 }
 
@@ -159,7 +176,11 @@ _msg_error() {
         esac
     done
     shift $((OPTIND - 1))
-    echo ${echo_opts} "$( echo_color -t '36' "[${script_name}]")   $( echo_color -t '31' 'Error') ${1}" >&2
+    if [[ "${nocolor}" = true ]]; then
+        echo ${echo_opts} "[${script_name}]   Error ${1}"
+    else
+        echo ${echo_opts} "$( echo_color -t '36' "[${script_name}]")   $( echo_color -t '31' 'Error') ${1}" >&2
+    fi
     if [[ -n "${2:-}" ]]; then
         exit ${2}
     fi
@@ -190,8 +211,8 @@ if [[ -z "${@}" ]]; then
     _usage 0
 fi
 
-_opt_short="h,r:,a:"
-_opt_long="help,repo:,arch:"
+_opt_short="h,r:,a:sf"
+_opt_long="help,repo:,arch:,skip,force,nocolor"
 
 OPT=$(getopt -o ${_opt_short} -l ${_opt_long} -- "${@}")
 if [[ ${?} != 0 ]]; then
@@ -217,6 +238,18 @@ while :; do
             arch="${2}"
             shift 2
             ;;
+        --force | -f)
+            force=true
+            shift 1
+            ;;
+        --skip | -s)
+            skip=true
+            shift 1
+            ;;
+        --nocolor)
+            nocolor=true
+            shift 1
+            ;;
         --) 
             shift 1
             break
@@ -231,6 +264,16 @@ done
 echo ${@}
 
 for pkg in ${@}; do
+    if [[ "${force}" = true ]]; then
+        rm -rf "${script_path}/${repo}/${arch}/${pkg}"
+    elif [[ -d "${script_path}/${repo}/${arch}/${pkg}" ]]; then
+        _msg_error "${pkg} has already been added."
+        if [[ "${skip}" = true ]]; then
+            continue
+        else
+            exit 1
+        fi
+    fi
     mkdir -p "${script_path}/${repo}/${arch}/${pkg}"
     git clone "https://aur.archlinux.org/${pkg}.git" "${script_path}/${repo}/${arch}/${pkg}"
     rm -rf "${script_path}/${repo}/${arch}/${pkg}/.git"