OSDN Git Service

[add] : Added pen4 xfce
[alterlinux/alterlinux.git] / tools / allpkglist.sh
1 #!/usr/bin/env bash
2
3 set -eu
4
5 load_config() {
6     local _file
7     for _file in "${@}"; do
8         if [[ -f "${_file}" ]]; then
9             source "${_file}"
10         fi
11     done
12 }
13
14 _help() {
15     echo "usage ${0} [options]"
16     echo
17     echo "Outputs the package list of all channels in one file"
18     echo
19     echo " General options:"
20     echo "    -a | --arch               Specify the architecture"
21     echo "    -o | --out                Specify the output dir"
22     echo "    -s | --stdout             Output to stdout (Ignore -o)"
23     echo "    -h | --help               This help message"
24     echo "         --aur                Include aur package to the list"
25 }
26
27 script_path="$( cd -P "$( dirname "$(readlink -f "$0")" )" && cd .. && pwd )"
28 tools_dir="${script_path}/tools"
29 out_dir=""
30 archs=("x86_64" "i686" "i486")
31 stdout=false
32 include_aur=false
33 pkglist=()
34
35 # Parse options
36 OPTS="a:o:hs"
37 OPTL="arch:,out:,help,stdout,aur"
38 if ! OPT=$(getopt -o ${OPTS} -l ${OPTL} -- "${@}"); then
39     exit 1
40 fi
41 eval set -- "${OPT}"
42 unset OPT OPTS OPTL
43
44 while true; do
45     case "${1}" in
46         -a | --arch)
47             IFS=" " read -ra archs <<< "${2}"
48             shift 2
49             ;;
50         -o | --out)
51             out_dir="${2}"
52             shift 2
53             ;;
54         -s | --stdout)
55             stdout=true
56             shift 1
57             ;;
58         -h | --help)
59             _help
60             exit 0
61             ;;
62         --aur)
63             include_aur=true
64             shift 1
65             ;;
66         --)
67             shift 1
68             break
69             ;;
70
71     esac
72 done
73
74
75 if [[ -z "${out_dir}" ]] || [[ "${stdout}" = true ]]; then
76     stdout=true
77 else
78     mkdir -p "${out_dir}"
79 fi
80
81 load_config() {
82     local _file
83     for _file in "${@}"; do
84         [[ -f "${_file}" ]] && source "${_file}"
85     done
86     return 0
87 }
88
89 for arch in "${archs[@]}"; do
90     for channel in $("${tools_dir}/channel.sh" show -a "${arch}" -b -d -k zen -f); do
91         readarray -t modules < <(
92             load_config "${script_path}/default.conf" "${script_path}/custom.conf"
93             load_config "${channel}/config.any" "${channel}/config.${arch}"
94             if [[ -n "${include_extra+SET}" ]]; then
95                 if [[ "${include_extra}" = true ]]; then
96                     modules=("base" "share" "share-extra" "calamares" "zsh-powerline")
97                 else
98                     modules=("base" "share")
99                 fi
100             fi
101             printf "%s\n" "${modules[@]}"
102         )
103
104         pkglist_opts=(-a "${arch}" -b -c "${channel}" -k zen -l en --line "${modules[@]}")
105
106         if [[ "${stdout}" = true ]]; then
107             readarray -O "${#pkglist[@]}" -t pkglist < <("${tools_dir}/pkglist.sh" "${pkglist_opts[@]}")
108             [[ "${include_aur}" = true ]] && readarray -O "${#pkglist[@]}" -t pkglist < <("${tools_dir}/pkglist.sh" --aur "${pkglist_opts[@]}") || true
109         else
110             (
111                 "${tools_dir}/pkglist.sh" -d "${pkglist_opts[@]}"
112                 [[ "${include_aur}" = true ]] && "${tools_dir}/pkglist.sh" --aur -d "${pkglist_opts[@]}" || true
113             ) 1> "${out_dir}/$(basename "${channel}").${arch}"
114         fi
115         
116     done
117 done
118
119 if [[ "${stdout}" = true ]]; then
120     readarray -t pkglist < <(printf "%s\n" "${pkglist[@]}" | sort |uniq)
121     printf "%s\n" "${pkglist[@]}"
122 fi