5 # Email : hayao@fascode.net
7 # (c) 2019-2020 Fascode Network.
9 # Repository management script
10 # Executed via administrator web and API of YamaD Server
13 script_name=$(basename ${0})
15 script_path="$(readlink -f ${0%/*})"
18 git_url="https://github.com/FascodeNet/alterlinux-pkgbuilds"
19 repo_name="alter-stable"
21 work_dir="${script_path}/work"
22 repo_dir="${script_path}/repo"
32 echo "usage ${0} [options] [repository] [command]"
34 echo " General options:"
36 echo " -a | --arch <arch> Specify the architecture"
37 echo " -r | --repodir <dir> Specify the repository dir"
38 echo " -g | --giturl <url> Specify the URL of the repository where the PKGBUILD list is stored"
39 echo " -w | --workdir <dir> Specify the work dir"
40 echo " -h | --help This help messageExecuted via administrator web and Yama D Saba APIs"
42 echo " list List packages"
43 echo " build BUold all packages"
45 if [[ -n "${1:-}" ]]; then
52 # usage: echo_color -b <backcolor> -t <textcolor> -d <decoration> [Text]
75 # You can specify multiple decorations with ;.
76 # 0 => All attributs off (ノーマル)
78 # 4 => Underscore (下線)
80 # 7 => Reverse video on (色反転)
94 while getopts 'b:t:d:n' arg; do
96 b) backcolor="${OPTARG}" ;;
97 t) textcolor="${OPTARG}" ;;
98 d) decotypes="${OPTARG}" ;;
99 n) echo_opts="-n -e" ;;
103 shift $((OPTIND - 1))
105 echo ${echo_opts} "\e[$([[ -v backcolor ]] && echo -n "${backcolor}"; [[ -v textcolor ]] && echo -n ";${textcolor}"; [[ -v decotypes ]] && echo -n ";${decotypes}")m${*}\e[m"
109 # Show an INFO message
116 while getopts 'n' arg; do
118 n) echo_opts="${echo_opts} -n" ;;
121 shift $((OPTIND - 1))
122 echo ${echo_opts} "$( echo_color -t '36' "[${script_name}]") $( echo_color -t '32' 'Info') ${*}"
126 # Show an Warning message
133 while getopts 'n' arg; do
135 n) echo_opts="${echo_opts} -n" ;;
138 shift $((OPTIND - 1))
139 echo ${echo_opts} "$( echo_color -t '36' "[${script_name}]") $( echo_color -t '33' 'Warning') ${*}" >&2
143 # Show an debug message
150 while getopts 'n' arg; do
152 n) echo_opts="${echo_opts} -n" ;;
155 shift $((OPTIND - 1))
156 if [[ "${debug}" = true ]]; then
157 echo ${echo_opts} "$( echo_color -t '36' "[${script_name}]") $( echo_color -t '35' 'Debug') ${*}"
162 # Show an ERROR message then exit with status
164 # $2: exit code number (with 0 does not exit)
171 while getopts 'n' arg; do
173 n) echo_opts="${echo_opts} -n" ;;
176 shift $((OPTIND - 1))
177 echo ${echo_opts} "$( echo_color -t '36' "[${script_name}]") $( echo_color -t '31' 'Error') ${1}" >&2
178 if [[ -n "${2:-}" ]]; then
184 # Delete the file if it exists.
185 # For directories, rm -rf is used.
186 # If the file does not exist, skip it.
187 # remove <file> <file> ...
192 for _file in "${_list[@]}"; do
193 if [[ -f ${_file} ]]; then
194 _msg_debug "Removeing ${_file}"
196 elif [[ -d ${_file} ]]; then
197 _msg_debug "Removeing ${_file}"
204 # check_file <path> <description>
206 local file_path="${1}"
207 local file_description="${2}"
208 if [[ ! -f "${file_path}" ]]; then
209 _msg_error "${file_description} (${file_path}) does not exist." "1"
214 # check_command <command>
217 check_file "$(which ${command})" "${command}"
222 mkdir -p "${repo_dir}/${repo_name}/${arch}"
223 mkdir -p "${work_dir}"
224 check_command makepkg
231 if [[ "${UID}" = 0 ]]; then
232 _msg_error "It cannot be run by the root user."
233 _msg_error "Be sure to execute it from a general user." "1"
238 cd "${repo_dir}/${repo_name}/${arch}"
239 rm -rf *.db.* *.files.* *.db *.files
240 repo-add "${repo_name}.db.tar.gz" $(ls ./*.pkg.tar.* | grep -v .sig | grep -v .sh)
245 cd "${repo_dir}/${repo_name}/${arch}"
247 for pkg in $(ls ./*.pkg.tar.* | grep -v .sig | grep -v .sh); do
248 _msg_info "Signing ${pkg}..."
249 gpg --detach-sign ${pkg}
257 rm -rf "${work_dir}/git_work"
258 mkdir -p "${work_dir}/lockfile/${repo_name}/${arch}"
259 mkdir -p "${work_dir}/pkgs/${repo_name}/${arch}"
260 git clone "${git_url}" "${work_dir}/git_work"
261 local init_dir=$(pwd)
264 cd "${work_dir}/git_work/${repo_name}/${arch}"
266 if [[ "${pkgs[@]}" = "ALL" ]]; then
267 build_list=($(ls 2> /dev/null))
269 build_list=(${pkgs[@]})
272 for pkg in ${build_list[@]}; do
274 if [[ ! -f "${work_dir}/lockfile/${repo_name}/${arch}/${pkg}" ]]; then
275 makepkg --syncdeps --rmdeps --clean --cleanbuild --force --noconfirm --needed --skippgpcheck
276 mv *.pkg.tar.* "${work_dir}/pkgs/${repo_name}/${arch}"
277 touch "${work_dir}/lockfile/${repo_name}/${arch}/${pkg}"
279 _msg_info "${pkg} is already built."
285 _msg_info "Copying package to repository directory..."
286 cp "${work_dir}/pkgs/${repo_name}/${arch}/"* "${repo_dir}/${repo_name}/${arch}"
288 sudo rm -rf "${work_dir}/git_work"
299 if [[ -z "${@}" ]]; then
304 _opt_short="h,a:,g:,r:,w:"
305 _opt_long="help,arch:,giturl:,repodir:,workdir:"
306 OPT=$(getopt -o ${_opt_short} -l ${_opt_long} -- "${@}")
307 if [[ ${?} != 0 ]]; then
343 _msg_error "Invalid argument '${1}'"
349 if [[ -n "${1}" ]]; then
351 repo_config="${script_path}/${repo_name}"
352 if [[ ! -f "${repo_config}" ]]; then
353 _msg_error "Repository [${repo_name}] does not exist." "1"
355 source "${repo_config}"
361 if [[ -n "${2}" ]]; then
363 "list") command="list" ;;
364 "build") command="build" ;;
365 *) _msg_error "Invalid command '${2}'" "1" ;;