X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=tools%2Fchannel.sh;h=72bd04142503cc108fe0b427afbbe82c5fce688b;hb=1268baff6e8a489644a6399e959dc5a566ede335;hp=40dde7ad9c30f2b50a34d00e5f8c824783ba728e;hpb=b7f23c7a937b06f2161ef7097ec64c965e743c96;p=alterlinux%2Falterlinux.git diff --git a/tools/channel.sh b/tools/channel.sh index 40dde7ad..72bd0414 100755 --- a/tools/channel.sh +++ b/tools/channel.sh @@ -9,7 +9,8 @@ opt_nochkver=false opt_nobuiltin=false opt_fullpath=false opt_nocheck=false -alteriso_version="3.0" +opt_line=false +alteriso_version="3.1" mode="" arch="all" kernel="all" @@ -23,6 +24,7 @@ _help() { echo " check [name] Returns whether the specified channel name is valid." echo " desc [name] Display a description of the specified channel" echo " show Display a list of channels" + echo " ver Display a version declared on the channel" echo " help This help message" echo echo " General options:" @@ -37,13 +39,20 @@ _help() { echo " -h | --help This help message" echo echo " --nocheck Do not check the channel with desc command.This option helps speed up." + echo " --line Line break the output" + echo + echo " check command exit code" + echo " 0 (correct) Normal available channel" + echo " 1 (directory) Channel outside the channel directory" + echo " 2 (incorrect) Unavailable channel" + echo " 3 Other error" } gen_channel_list() { local _dirname for _dirname in $(ls -l "${script_path}"/channels/ | awk '$1 ~ /d/ {print $9}'); do - if [[ -n $(ls "${script_path}"/channels/${_dirname}) ]] && [[ "$(cat "${script_path}/channels/${_dirname}/alteriso" 2> /dev/null)" = "alteriso=${alteriso_version}" ]] || [[ "${opt_nochkver}" = true ]]; then - if [[ ! "${arch}" = "all" ]] && [[ -z "$(cat "${script_path}/channels/${_dirname}/architecture" 2> /dev/null | grep -h -v ^'#' | grep -x "${arch}")" ]] || [[ "${_dirname}" = "share" ]] || [[ "${_dirname}" = "share-extra" ]]; then + if [[ -n $(ls "${script_path}"/channels/${_dirname}) ]] && check_alteriso_version "${_dirname}/" || [[ "${opt_nochkver}" = true ]]; then + if [[ ! "${arch}" = "all" ]] && [[ -z "$(cat "${script_path}/channels/${_dirname}/architecture" 2> /dev/null | grep -h -v ^'#' | grep -x "${arch}")" ]]; then continue elif [[ ! "${kernel}" = "all" ]] && [[ -f "${channel_dir}/kernel_list-${arch}" ]] && [[ -z $( ( cat "${script_path}/channels/${_dirname}/kernel_list-${arch}" | grep -h -v ^'#' | grep -x "${kernel}" ) 2> /dev/null) ]]; then continue @@ -55,7 +64,8 @@ gen_channel_list() { channellist+=("${_dirname}") fi else - channellist+=("$(echo ${_dirname} | sed 's/\.[^\.]*$//')") + #channellist+=("$(echo ${_dirname} | sed 's/\.[^\.]*$//')") + readarray -t -O "${#channellist[@]}" channellist < <(echo "${_dirname}" | sed 's/\.[^\.]*$//') fi elif [[ ! -d "${script_path}/channels/${_dirname}.add" ]] && [[ "${opt_only_add}" = false ]]; then if [[ "${opt_fullpath}" = true ]]; then @@ -73,23 +83,62 @@ gen_channel_list() { fi } +# check?alteriso_version +get_alteriso_version(){ + local _channel + if [[ ! -d "${script_path}/channels/${1}" ]]; then + _channel="${script_path}/channels/${1}.add" + else + _channel="${script_path}/channels/${1}" + fi + if [[ ! -d "${_channel}" ]]; then + echo "${1} was not found." >&2 + exit 1 + fi + if [[ ! -f "${_channel}/alteriso" ]]; then + if (( $(find ./ -maxdepth 1 -mindepth 1 -name "*.x86_64" -o -name ".i686" -o -name "*.any" 2> /dev/null | wc -l) == 0 )); then + echo "2.0" + fi + else + echo "$( + source "${_channel}/alteriso" + echo "${alteriso}" + )" + fi +} + +check_alteriso_version(){ + #if [[ "$(get_alteriso_version "${1%.add}")" = "${alteriso_version}" ]]; then + if [[ "$(get_alteriso_version "${1%.add}" | cut -d "." -f 1)" = "$(echo "${alteriso_version}" | cut -d "." -f 1)" ]]; then + return 0 + else + return 1 + fi +} + check() { + local _channel_name + gen_channel_list if [[ ! "${#}" = "1" ]]; then _help - exit 1 + exit 3 fi if [[ $(printf '%s\n' "${channellist[@]}" | grep -qx "${1}"; echo -n ${?} ) -eq 0 ]]; then - echo "correct" - elif [[ -d "${1}" ]] && [[ -n $(ls "${1}") ]] && [[ ! "$(basename "${1%/}")" = "share" ]] && [[ ! "$(basename "${1%/}")" = "share-extra" ]]; then - local _channel_name="$(basename "${1%/}")" - if [[ "$(cat "${script_path}/channels/${_dirname}/alteriso" 2> /dev/null)" = "alteriso=${alteriso_version}" ]] || [[ "${opt_nochkver}" = true ]]; then - echo "directory" + #echo "correct" + exit 0 + elif [[ -d "${1}" ]] && [[ -n $(ls "${1}") ]]; then + _channel_name="$(basename "${1%/}")" + if check_alteriso_version "${_channel_name}" || [[ "${opt_nochkver}" = true ]]; then + #echo "directory" + exit 1 else - echo "incorrect" + #echo "incorrect" + exit 2 fi else - echo "incorrect" + #echo "incorrect" + exit 2 fi } @@ -99,7 +148,7 @@ desc() { _help exit 1 fi - if [[ "${opt_nocheck}" = false ]] && [[ ! "$(bash "${script_path}/tools/channel.sh" -a ${arch} -n -b check "${1}")" = "correct" ]]; then + if [[ "${opt_nocheck}" = false ]] && ! bash "${script_path}/tools/channel.sh" -a ${arch} -n -b check "${1}"; then exit 1 fi local _channel @@ -108,7 +157,7 @@ desc() { else _channel="${1}" fi - if [[ ! "$(cat "${script_path}/channels/${_channel}/alteriso" 2> /dev/null)" = "alteriso=${alteriso_version}" ]] && [[ "${opt_nochkver}" = false ]]; then + if ! check_alteriso_version "${_channel}" && [[ "${opt_nochkver}" = false ]]; then "${script_path}/tools/msg.sh" --noadjust -l 'ERROR:' --noappname error "Not compatible with AlterISO3" elif [[ -f "${script_path}/channels/${_channel}/description.txt" ]]; then echo -ne "$(cat "${script_path}/channels/${_channel}/description.txt")\n" @@ -120,23 +169,26 @@ desc() { show() { gen_channel_list if (( "${#channellist[*]}" > 0)); then - echo "${channellist[*]}" + if [[ "${opt_line}" = true ]]; then + printf "%s\n" "${channellist[@]}" + else + echo "${channellist[*]}" + fi fi } # Parse options -ARGUMENT="${@}" -opt_short="a:bdfk:nov:h" -opt_long="arch:,nobuiltin,dirname,fullpath,kernel:,only-add,nochkver,version:,help,nocheck" -OPT=$(getopt -o ${opt_short} -l ${opt_long} -- ${ARGUMENT}) -[[ ${?} != 0 ]] && exit 1 - +OPTS="a:bdfk:nov:h" +OPTL="arch:,nobuiltin,dirname,fullpath,kernel:,only-add,nochkver,version:,help,nocheck,line" +if ! OPT=$(getopt -o ${OPTS} -l ${OPTL} -- "${@}"); then + exit 1 +fi eval set -- "${OPT}" -unset OPT opt_short opt_long +unset OPT OPTS OPTL while true; do - case ${1} in + case "${1}" in -a | --arch) arch="${2}" shift 2 @@ -177,6 +229,10 @@ while true; do opt_nocheck=true shift 1 ;; + --line) + opt_line=true + shift 1 + ;; --) shift 1 break @@ -194,9 +250,10 @@ else fi case "${mode}" in - "check" ) check ${@} ;; - "show" ) show ;; - "desc" ) desc ${@} ;; - "help" ) _help; exit 0 ;; - * ) _help; exit 1 ;; + "check" ) check "${@}" ;; + "show" ) show ;; + "desc" ) desc "${@}" ;; + "ver" ) get_alteriso_version "${@}" ;; + "help" ) _help; exit 0 ;; + * ) _help; exit 1 ;; esac