Skip to content

Commit e80c9a5

Browse files
committed
Merge branch 'Issue-244' into no-mkalteriso
Done #244
2 parents 7e2eea8 + f0ce63e commit e80c9a5

File tree

6 files changed

+99
-71
lines changed

6 files changed

+99
-71
lines changed

build.sh

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -353,31 +353,32 @@ check_bool() {
353353
prepare_env() {
354354
# Check packages
355355
if [[ "${nodepend}" = false ]]; then
356-
local _check_failed=false _pkg _result
356+
local _check_failed=false _pkg _result=0 _version
357357
msg_info "Checking dependencies ..."
358358
for _pkg in ${dependence[@]}; do
359359
msg_debug -n "Checking ${_pkg} ..."
360-
_result=( $("${tools_dir}/package.py" -s "${_pkg}") )
361-
case "${_result[0]}" in
362-
"latest")
363-
[[ "${debug}" = true ]] && echo -ne " ${_result[1]}\n"
360+
_version="$("${tools_dir}/package.py" -s "${_pkg}")" || _result="${?}"
361+
case "${_result}" in
362+
"0")
363+
[[ "${debug}" = true ]] && echo -ne " ${_version}\n"
364364
;;
365-
"noversion")
365+
"1")
366366
echo; msg_warn "Failed to get the latest version of ${_pkg}."
367367
;;
368-
"nomatch")
368+
"2")
369369
[[ "${debug}" = true ]] && echo -ne " ${_result[1]}\n"
370370
msg_warn "The version of ${_pkg} installed in local does not match one of the latest.\nLocal: ${_result[1]} Latest: ${_result[2]}"
371371
;;
372-
"failed")
372+
"3")
373373
[[ "${debug}" = true ]] && echo
374374
msg_error "${_pkg} is not installed." ; _check_failed=true
375375
;;
376-
"error")
376+
"4")
377377
[[ "${debug}" = true ]] && echo
378378
msg_error "pyalpm is not installed." ; exit 1
379379
;;
380380
esac
381+
_result=0
381382
done
382383
if [[ "${_check_failed}" = true ]]; then exit 1; fi
383384
fi
@@ -487,7 +488,8 @@ prepare_build() {
487488

488489
local module_check
489490
module_check(){
490-
if [[ ! "$(bash "${tools_dir}/module.sh" check "${1}")" = "correct" ]]; then
491+
msg_debug "Checking ${1} module ..."
492+
if ! bash "${tools_dir}/module.sh" check "${1}"; then
491493
msg_error "Module ${1} is not available." "1";
492494
fi
493495
}
@@ -538,15 +540,12 @@ prepare_build() {
538540
check_bool boot_splash cleaning noconfirm nodepend customized_username customized_password noloopmod nochname tarball noiso noaur customized_syslinux norescue_entry debug bash_debug nocolor msgdebug noefi nosigcheck
539541

540542
# Check architecture for each channel
541-
if [[ ! "$(bash "${tools_dir}/channel.sh" --version "${alteriso_version}" -a ${arch} -n -b check "${channel_name}")" = "correct" ]]; then
543+
local _exit=0
544+
bash "${tools_dir}/channel.sh" --version "${alteriso_version}" -a ${arch} -n -b check "${channel_name}" || _exit="${?}"
545+
if (( "${_exit}" != 0 )) && (( "${_exit}" != 1 )); then
542546
msg_error "${channel_name} channel does not support current architecture (${arch})." "1"
543547
fi
544548

545-
# Check kernel for each channel
546-
if [[ ! "$(bash "${tools_dir}/kernel.sh" -c "${channel_name}" -a "${arch}" -s check "${kernel}")" = "correct" ]]; then
547-
msg_error "This kernel is currently not supported on this channel or architecture" "1"
548-
fi
549-
550549
# Unmount
551550
umount_chroot
552551
}
@@ -1304,15 +1303,15 @@ if [[ "${bash_debug}" = true ]]; then set -x -v; fi
13041303

13051304
# Check for a valid channel name
13061305
if [[ -n "${1+SET}" ]]; then
1307-
case "$(bash "${tools_dir}/channel.sh" --version "${alteriso_version}" -n check "${1}")" in
1308-
"incorrect")
1306+
case "$(bash "${tools_dir}/channel.sh" --version "${alteriso_version}" -n check "${1}"; printf "${?}")" in
1307+
"2")
13091308
msg_error "Invalid channel ${1}" "1"
13101309
;;
1311-
"directory")
1310+
"1")
13121311
channel_dir="${1}"
13131312
channel_name="$(basename "${1%/}")"
13141313
;;
1315-
"correct")
1314+
"0")
13161315
channel_dir="${script_path}/channels/${1}"
13171316
channel_name="${1}"
13181317
;;

tools/channel.sh

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ _help() {
3838
echo " -h | --help This help message"
3939
echo
4040
echo " --nocheck Do not check the channel with desc command.This option helps speed up."
41+
echo
42+
echo " check command exit code"
43+
echo " 0 (correct) Normal available channel"
44+
echo " 1 (directory) Channel outside the channel directory"
45+
echo " 2 (incorrect) Unavailable channel"
46+
echo " 3 Other error"
4147
}
4248

4349
gen_channel_list() {
@@ -111,19 +117,23 @@ check() {
111117
gen_channel_list
112118
if [[ ! "${#}" = "1" ]]; then
113119
_help
114-
exit 1
120+
exit 3
115121
fi
116122
if [[ $(printf '%s\n' "${channellist[@]}" | grep -qx "${1}"; echo -n ${?} ) -eq 0 ]]; then
117-
echo "correct"
123+
#echo "correct"
124+
exit 0
118125
elif [[ -d "${1}" ]] && [[ -n $(ls "${1}") ]]; then
119126
local _channel_name="$(basename "${1%/}")"
120127
if ! check_alteriso_version "${_channel}" || [[ "${opt_nochkver}" = true ]]; then
121-
echo "directory"
128+
#echo "directory"
129+
exit 1
122130
else
123-
echo "incorrect"
131+
#echo "incorrect"
132+
exit 2
124133
fi
125134
else
126-
echo "incorrect"
135+
#echo "incorrect"
136+
exit 2
127137
fi
128138
}
129139

@@ -133,7 +143,7 @@ desc() {
133143
_help
134144
exit 1
135145
fi
136-
if [[ "${opt_nocheck}" = false ]] && [[ ! "$(bash "${script_path}/tools/channel.sh" -a ${arch} -n -b check "${1}")" = "correct" ]]; then
146+
if [[ "${opt_nocheck}" = false ]] && ! bash "${script_path}/tools/channel.sh" -a ${arch} -n -b check "${1}"; then
137147
exit 1
138148
fi
139149
local _channel

tools/kernel.sh

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,20 @@ _help() {
1515
echo "Scripts that perform kernel-related processing "
1616
echo
1717
echo " General command:"
18-
echo " check [name] Determine if the kernel is available"
19-
echo " show Shows a list of available kernels"
20-
echo " get [name] Prints the specified kernel settings"
21-
echo " help This help message"
18+
echo " check [name] Determine if the kernel is available"
19+
echo " show Shows a list of available kernels"
20+
echo " get [name] Prints the specified kernel settings"
21+
echo " help This help message"
2222
echo
2323
echo " General options:"
2424
echo " -a | --arch [arch] Specify the architecture"
2525
echo " -c | --channel Specify the channel"
2626
echo " -s | --script Enable script mode"
2727
echo " -h | --help This help message"
28+
echo
29+
echo " Script mode usage:"
30+
echo " check Returns 0 if the check was successful, 1 otherwise."
31+
printf ' get eval $(%s -s -a <arch> -c <channel> get <kernel>)\n' "$(basename ${0})"
2832
}
2933

3034
# Usage: getclm <number>
@@ -46,6 +50,8 @@ gen_kernel_list() {
4650
local _list _kernel
4751
if [[ -n "${channel}" ]] && [[ -f "${script_path}/channels/${channel}/kernel_list-${arch}" ]]; then
4852
_list="${script_path}/channels/${channel}/kernel_list-${arch}"
53+
elif [[ -n "${channel}" ]] && [[ -f "${script_path}/channels/${channel}/kernel-${arch}" ]]; then
54+
_list="${script_path}/channels/${channel}/kernel-${arch}"
4955
else
5056
_list="${script_path}/system/kernel-${arch}"
5157
fi
@@ -61,10 +67,10 @@ check() {
6167
exit 1
6268
fi
6369
if [[ $(printf '%s\n' "${kernellist[@]}" | grep -qx "${1}"; echo -n ${?} ) -eq 0 ]]; then
64-
echo "correct"
70+
#echo "correct"
6571
exit 0
6672
else
67-
echo "incorrect"
73+
#echo "incorrect"
6874
exit 1
6975
fi
7076
}

tools/locale.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,20 @@ _help() {
1515
echo "Scripts that perform locale-related processing "
1616
echo
1717
echo " General command:"
18-
echo " check [name] Determine if the locale is available"
19-
echo " show Shows a list of available locales"
20-
echo " get [name] Prints the specified locale settings"
21-
echo " help This help message"
18+
echo " check [name] Determine if the locale is available"
19+
echo " show Shows a list of available locales"
20+
echo " get [name] Prints the specified locale settings"
21+
echo " help This help message"
2222
echo
2323
echo " General options:"
2424
echo " -a | --arch [arch] Specify the architecture"
2525
echo " -c | --channel Specify the channel"
26+
echo " -s | --script Enable script mode"
2627
echo " -h | --help This help message"
28+
echo
29+
echo " Script mode usage:"
30+
echo " check Returns 0 if the check was successful, 1 otherwise."
31+
printf ' get eval $(%s -s -a <arch> -c <channel> get <locale>)\n' "$(basename ${0})"
2732
}
2833

2934
# Usage: getclm <number>
@@ -55,10 +60,10 @@ check() {
5560
exit 1
5661
fi
5762
if [[ $(printf '%s\n' "${localelist[@]}" | grep -qx "${1}"; echo -n ${?} ) -eq 0 ]]; then
58-
echo "correct"
63+
#echo "correct"
5964
exit 0
6065
else
61-
echo "incorrect"
66+
#echo "incorrect"
6267
exit 1
6368
fi
6469
}

tools/module.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@ _help() {
3131
echo " General options:"
3232
echo " -v | --version [ver] Specifies the AlterISO version"
3333
echo " -h | --help This help message"
34+
echo
35+
echo " check exit code:"
36+
echo " 0 (correct) 1 (incorrect) 2 (other)"
3437
}
3538

3639
check(){
3740
if (( "${#}" == 0 )) || (( "${#}" >= 2 ));then
3841
_help
39-
exit 1
42+
exit 2
4043
fi
4144
local _version
4245
if [[ -f "${module_dir}/${1}/alteriso" ]]; then
@@ -46,10 +49,10 @@ check(){
4649
unset alteriso
4750
)"
4851
if (( "$(echo "${_version}" | cut -d "." -f 1)" == "$(echo "${alteriso_version}" | cut -d "." -f 1)" )); then
49-
echo "correct"
52+
exit 0
5053
fi
5154
else
52-
echo "incorrect"
55+
exit 1
5356
fi
5457
}
5558

tools/package.py

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
]
2323

2424
epilog = """
25-
script mode output:
26-
latest The latest package is installed
27-
noversion Failed to get the latest version of the package, but the package is installed
28-
nomatch The version of the package installed in local does not match one of the latest
29-
failed Package not installed
25+
exit code:
26+
0 (latest) The latest package is installed
27+
1 (noversion) Failed to get the latest version of the package, but the package is installed
28+
2 (nomatch) The version of the package installed in local does not match one of the latest
29+
3 (failed) Package not installed
30+
4 Other error
3031
"""
3132

3233
def msg_info(string):
@@ -54,30 +55,31 @@ def compare(package):
5455
pkg_from_sync = get_from_syncdb(package)
5556

5657
if pkg_from_local is None:
57-
if args.script:
58-
return ["failed"]
59-
else:
58+
# failed
59+
if not args.script:
6060
msg_error(f"{package} is not installed.")
61-
return 1
61+
return 3
62+
6263
elif pkg_from_sync is None:
63-
if args.script:
64-
return ["noversion"]
65-
else:
64+
# noversion
65+
if not args.script:
6666
msg_warn(f"Failed to get the latest version of {package}.")
67-
return 1
68-
67+
return 1
68+
69+
# スクリプトモード時にパッケージバージョンを表示
70+
if args.script:
71+
print(pkg_from_local.version)
72+
6973
if pkg_from_local.version == pkg_from_sync.version:
70-
if args.script:
71-
return ["latest", pkg_from_local.version]
72-
else:
73-
msg_info(f"The latest version of {package} is installed.")
74-
return 0
74+
# latest
75+
if not args.script:
76+
msg_info(f"The latest version of {package} {pkg_from_local.version} is installed.")
77+
return 0
7578
else:
76-
if args.script:
77-
return ["nomatch", pkg_from_local.version, pkg_from_sync.version]
78-
else:
79+
# nomatch
80+
if not args.script:
7981
msg_warn(f"The version of {package} does not match one of the latest.\nLocal: {pkg_from_local.version} Latest: {pkg_from_sync.version}")
80-
return 1
82+
return 2
8183

8284
if __name__ == "__main__":
8385
script_dir = os.path.dirname(os.path.abspath(__file__))
@@ -111,7 +113,7 @@ def compare(package):
111113
exit()
112114
else:
113115
msg_error("pyalpm is not installed.")
114-
sys.exit(1)
116+
sys.exit(4)
115117

116118
handle = pyalpm.Handle(".", "/var/lib/pacman")
117119

@@ -121,9 +123,12 @@ def compare(package):
121123
localdb = handle.get_localdb()
122124
syncdbs = handle.get_syncdbs()
123125

124-
if args.script:
125-
result = compare(args.package)
126-
print(" ".join(result))
127-
else:
128-
return_code = compare(args.package)
129-
sys.exit(return_code)
126+
#if args.script:
127+
# result = compare(args.package)
128+
# print(" ".join(result))
129+
#else:
130+
# return_code = compare(args.package)
131+
# sys.exit(return_code)
132+
133+
return_code = compare(args.package)
134+
sys.exit(return_code)

0 commit comments

Comments
 (0)