OSDN Git Service

Merge remote-tracking branch 'FascodeNet/master'
[alterlinux/LFBS.git] / tools / pkglist-repo.sh
1 #!/usr/bin/env bash
2
3 set -e
4
5 script_path="$( cd -P "$( dirname "$(readlink -f "$0")" )" && cd .. && pwd )"
6 share_dir="${script_path}/channels/share"
7
8 boot_splash=false
9 pkgdir_name="packages-repo"
10
11 arch=""
12 channel_dir=""
13 codename=33
14 locale_name=""
15
16 #arch="x86_64"
17 #channel_dir="${script_path}/channels/xfce"
18 #kernel="zen"
19 #locale_name="en"
20
21 _help() {
22     echo "usage ${0} [options] [command]"
23     echo
24     echo "Get a list of packages to install on that channel"
25     echo
26     echo " General options:"
27     echo "    -a | --arch [arch]        Specify the architecture"
28     echo "    -b | --boot-splash        Enable boot splash"
29     echo "    -c | --channel            Specify the channel directory"
30     echo "    -k | --kernel             Specify the kernel"
31     echo "    -h | --help               This help message"
32 }
33
34 # Usage: getclm <number>
35 # 標準入力から値を受けとり、引数で指定された列を抽出します。
36 getclm() {
37     echo "$(cat -)" | cut -d " " -f "${1}"
38 }
39
40 # Message functions
41 msg_error() {
42     "${script_path}/tools/msg.sh" -s "5" -a "pkglist.sh" -l "Error" -r "red" error "${1}"
43 }
44
45 msg_info() {
46     "${script_path}/tools/msg.sh" -s "5" -a "pkglist.sh" -l "Info" -r "green" error "${1}"
47 }
48
49 msg_debug() {
50     "${script_path}/tools/msg.sh" -s "5" -a "pkglist.sh" -l "Debug" -r "magenta" error "${1}"
51 }
52
53
54 # Parse options
55 ARGUMENT="${@}"
56 _opt_short="a:bc:k:l:h"
57 _opt_long="arch:,boot-splash,channel:,codename:,locale:,help"
58 OPT=$(getopt -o ${_opt_short} -l ${_opt_long} -- ${ARGUMENT})
59 [[ ${?} != 0 ]] && exit 1
60
61 eval set -- "${OPT}"
62 unset OPT _opt_short _opt_long
63
64 while true; do
65     case ${1} in
66         -a | --arch)
67             arch="${2}"
68             shift 2
69             ;;
70         -b | --boot-splash)
71             boot_splash=true
72             shift 1
73             ;;
74         -c | --channel)
75             channel_dir="${2}"
76             shift 2
77             ;;
78         -k | --codename)
79             codename="${2}"
80             shift 2
81             ;;
82         -l | --locale)
83             locale_name="${2}"
84             shift 2
85             ;;
86         -h | --help)
87             _help
88             exit 0
89             ;;
90         --)
91             shift 1
92             break
93             ;;
94
95     esac
96 done
97
98
99 if [[ -z "${arch}" ]]; then
100     msg_error "Architecture not specified"
101     exit 1
102 elif [[ -z "${channel_dir}" ]]; then
103     msg_error "Channel directory not specified"
104     exit 1
105 elif [[ -z "${codename}" ]]; then
106     msg_error "codename not specified"
107     exit 1
108 elif [[ -z "${locale_name}" ]]; then
109     msg_error "Locale not specified"
110     exit 1
111 fi
112
113
114 pkgdir_name="packages-repo"
115
116 set +e
117
118
119 #-- Detect package list to load --#
120 # Add the files for each channel to the list of files to read.
121 _loadfilelist=(
122     # share packages
123     $(ls ${share_dir}/${pkgdir_name}.${arch}/*.${arch} 2> /dev/null)
124     "${share_dir}/${pkgdir_name}.${arch}/lang/${locale_name}.${arch}"
125
126     # channel packages
127     $(ls ${channel_dir}/${pkgdir_name}.${arch}/*.${arch} 2> /dev/null)
128     "${channel_dir}/${pkgdir_name}.${arch}/lang/${locale_name}.${arch}"
129 )
130
131 # Plymouth package list
132 if [[ "${boot_splash}" = true ]]; then
133     _loadfilelist+=(
134         $(ls ${share_dir}/${pkgdir_name}.${arch}/plymouth/*.${arch} 2> /dev/null)
135         $(ls ${channel_dir}/${pkgdir_name}.${arch}/plymouth/*.${arch} 2> /dev/null)
136     )
137 fi
138
139
140 #-- Read package list --#
141 # Read the file and remove comments starting with # and add it to the list of packages to install.
142 for _file in ${_loadfilelist[@]}; do
143     if [[ -f "${_file}" ]]; then
144         msg_debug "Loaded package file ${_file}"
145         _pkglist=( ${_pkglist[@]} "$(grep -h -v ^'#' ${_file})" )
146     fi
147 done
148
149 #-- Read exclude list --#
150 # Exclude packages from the share exclusion list
151 _excludefile=(
152     "${share_dir}/${pkgdir_name}.${arch}/exclude"
153     "${channel_dir}/${pkgdir_name}.${arch}/exclude"
154 )
155
156 for _file in ${_excludefile[@]}; do
157     if [[ -f "${_file}" ]]; then
158         _excludelist=( ${_excludelist[@]} $(grep -h -v ^'#' "${_file}") )
159     fi
160 done
161
162 #-- excludeに記述されたパッケージを除外 --#
163 # _pkglistを_subpkglistにコピーしexcludeのパッケージを除外し再代入
164 _subpkglist=(${_pkglist[@]})
165 unset _pkglist
166 for _pkg in ${_subpkglist[@]}; do
167     # もし変数_pkgの値が配列_excludelistに含まれていなかったらpkglistに追加する
168     if [[ ! $(printf '%s\n' "${_excludelist[@]}" | grep -qx "${_pkg}"; echo -n ${?} ) = 0 ]]; then
169         _pkglist=(${_pkglist[@]} "${_pkg}")
170     fi
171 done
172 unset _subpkglist
173
174 #-- excludeされたパッケージを表示 --#
175 if [[ -n "${_excludelist[*]}" ]]; then
176     msg_debug "The following packages have been removed from the installation list."
177     msg_debug "Excluded packages: ${_excludelist[*]}"
178 fi
179
180 # Sort the list of packages in abc order.
181 _pkglist=($(for _pkg in ${_pkglist[@]}; do echo "${_pkg}"; done | sort | perl -pe 's/\n/ /g'))
182
183 echo "${_pkglist[@]}" | sed -e "s/\${codename}/${codename}/g" >&1