5 script_path="$( cd -P "$( dirname "$(readlink -f "$0")" )" && cd .. && pwd )"
6 module_dir="${script_path}/modules"
10 pkgdir_name="packages"
16 additional_exclude_pkg=()
25 echo "usage ${0} [options] [module 1] [module 2]..."
27 echo "Get a list of packages to install on that channel"
29 echo " General options:"
30 echo " -a | --arch [arch] Specify the architecture"
31 echo " -b | --boot-splash Enable boot splash"
32 echo " -c | --channel [dir] Specify the channel directory"
33 echo " -d | --debug Enable debug message"
34 echo " -e | --exclude [pkgs] List of packages to be additionally excluded"
35 echo " -k | --kernel [kernel] Specify the kernel"
36 echo " -l | --locale [locale] Specify the locale"
37 echo " -m | --memtest86 Enable memtest86 package"
38 echo " -h | --help This help message"
39 echo " --aur AUR packages"
40 echo " --line Line break the output"
43 # Execute command for each module
44 # It will be executed with {} replaced with the module name.
45 # for_module <command>
46 for_module(){ local module && for module in "${modules[@]}"; do eval "${@//"{}"/${module}}"; done; }
50 local _args=(-s "5" -a "pkglist.sh")
51 [[ "${nocolor}" = true ]] && _args+=("--nocolor")
52 "${script_path}/tools/msg.sh" "${_args[@]}" "${@}"
56 msg_common -l "Error" -r "red" -p "stderr" error "${1}" &
60 msg_common -l "Info" -r "green" -p "stderr" info "${1}" &
64 if [[ "${debug}" = true ]]; then
65 msg_common -l "Debug" -r "magenta" -p "stderr" debug "${1}" &
73 OPTL="arch:,boot-splash,channel:,debug,exclude:,kernel:,locale:,memtest86,aur,help,line,nocolor"
74 if ! OPT=$(getopt -o ${OPTS} -l ${OPTL} -- "${ARGUMENT[@]}"); then
79 unset OPT OPTS OPTL ARGUMENT
100 IFS=" " read -r -a additional_exclude_pkg <<< "${2}"
116 pkgdir_name="packages_aur"
139 for module in "${@}"; do
140 if "${script_path}/tools/module.sh" check "${module}"; then
143 msg_debug "Module ${module} was not found"
147 if [[ -z "${arch}" ]] || [[ "${arch}" = "" ]]; then
148 msg_error "Architecture not specified"
150 elif [[ -z "${channel_dir}" ]] || [[ "${channel_dir}" = "" ]]; then
151 msg_error "Channel directory not specified"
153 elif [[ -z "${kernel}" ]] || [[ "${kernel}" = "" ]]; then
154 msg_error "kernel not specified"
156 elif [[ -z "${locale_name}" ]] || [[ "${locale_name}" = "" ]]; then
157 msg_error "Locale not specified"
163 #-- Detect package list to load --#
164 # Add the files for each channel to the list of files to read.
165 readarray -t _loadfilelist < <(ls ${channel_dir}/${pkgdir_name}.${arch}/*.${arch} 2> /dev/null)
168 "${channel_dir}/${pkgdir_name}.${arch}/lang/${locale_name}.${arch}"
169 "${channel_dir}/${pkgdir_name}.${arch}/kernel/${kernel}.${arch}"
172 # module package list
173 for_module '_loadfilelist+=($(ls ${module_dir}/{}/${pkgdir_name}.${arch}/*.${arch} 2> /dev/null))'
174 for_module '_loadfilelist+=(${module_dir}/{}/${pkgdir_name}.${arch}/lang/${locale_name}.${arch})'
175 for_module '_loadfilelist+=(${module_dir}/{}/${pkgdir_name}.${arch}/kernel/${kernel}.${arch})'
177 # Plymouth package list
178 if [[ "${boot_splash}" = true ]]; then
179 readarray -t -O "${#_loadfilelist[@]}" _loadfilelist < <(ls ${channel_dir}/${pkgdir_name}.${arch}/plymouth/*.${arch} 2> /dev/null)
180 for_module '_loadfilelist+=($(ls ${module_dir}/{}/${pkgdir_name}.${arch}/plymouth/*.${arch} 2> /dev/null))'
183 # memtest86 package list
184 if [[ "${memtest86}" = true ]]; then
185 readarray -t -O "${#_loadfilelist[@]}" _loadfilelist <(ls ${channel_dir}/${pkgdir_name}.${arch}/memtest86/*.${arch} 2> /dev/null)
187 for_module '_loadfilelist+=($(ls ${module_dir}/{}/${pkgdir_name}.${arch}/memtest86/*.${arch} 2> /dev/null))'
190 #-- Read package list --#
191 # Read the file and remove comments starting with # and add it to the list of packages to install.
193 for _file in "${_loadfilelist[@]}"; do
194 if [[ -f "${_file}" ]]; then
195 msg_debug "Loaded package file ${_file}"
196 #_pkglist=( ${_pkglist[@]} "$(grep -h -v ^'#' ${_file})" )
197 readarray -t -O "${#_pkglist[@]}" _pkglist < <(grep -h -v ^'#' "${_file}")
199 msg_debug "The file was not found ${_file}"
203 #-- Read exclude list --#
204 # Exclude packages from the share exclusion list
205 _excludefile=("${channel_dir}/packages.${arch}/exclude" "${channel_dir}/packages_aur.${arch}/exclude")
206 for_module '_excludefile+=("${module_dir}/{}/packages.${arch}/exclude" "${module_dir}/{}/packages_aur.${arch}/exclude")'
208 for _file in "${_excludefile[@]}"; do
209 if [[ -f "${_file}" ]]; then
210 #_excludelist+=($(grep -h -v ^'#' "${_file}") )
211 readarray -t -O "${#_excludelist[@]}" _excludelist < <(grep -h -v ^'#' "${_file}")
215 #-- additional_exclude_pkg のパッケージを_excludelistに追加 --#
216 if (( "${#additional_exclude_pkg[@]}" >= 1 )); then
217 _excludelist+=("${additional_exclude_pkg[@]}")
218 msg_debug "Additional excluded packages: ${additional_exclude_pkg[*]}"
221 #-- パッケージリストをソートし重複を削除 --#
222 #_pkglist=($(printf "%s\n" "${_pkglist[@]}" | sort | uniq | tr "\n" " "))
223 readarray -t _pkglist < <(printf "%s\n" "${_pkglist[@]}" | sort | uniq)
225 #-- excludeに記述されたパッケージを除外 --#
226 for _pkg in "${_excludelist[@]}"; do
227 #_pkglist=($(printf "%s\n" "${_pkglist[@]}" | grep -xv "${_pkg}" | tr "\n" " "))
228 readarray -t _pkglist < <(printf "%s\n" "${_pkglist[@]}" | grep -xv "${_pkg}")
231 #-- excludeされたパッケージを表示 --#
232 if (( "${#_excludelist[@]}" >= 1 )); then
233 msg_debug "The following packages have been removed from the installation list."
234 msg_debug "Excluded packages: ${_excludelist[*]}"
236 msg_debug "No packages are excluded."
241 if [[ "${line}" = true ]]; then
242 printf "%s\n" "${_pkglist[@]}"
244 echo "${_pkglist[*]}" >&1