Skip to content

Commit

Permalink
posix
Browse files Browse the repository at this point in the history
  • Loading branch information
junjiemars committed Oct 21, 2023
1 parent 1cc229c commit 86a5dd7
Showing 1 changed file with 63 additions and 31 deletions.
94 changes: 63 additions & 31 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,33 @@ grep=$(PATH=$PH command -v grep)
iconv=$(PATH=$PH command -v iconv)
ls=$(PATH=$PH command -v ls)
mkdir=$(PATH=$PH command -v mkdir)
printf=$(PATH=$PH command -v printf)
ps=$(PATH=$PH command -v ps)
rm=$(PATH=$PH command -v rm)
sed=$(PATH=$PH command -v sed)
sort=$(PATH=$PH command -v sort)
tr=$(PATH=$PH command -v tr)
uname=$(PATH=$PH command -v uname)
uniq=$(PATH=$PH command -v uniq)
xargs=$(PATH=$PH command -v xargs)

# check command options
check_echo_opt () {
# check the echo's "-n" option and "\c" capability
echo_c='\c'
if echo "test\c" | grep -q c; then
echo_c=
fi
echo_n=-n
if echo -n test | tr '\n' _ | grep -q _; then
echo_n=
fi
}
check_echo_opt

bootstrap_path () {
local p="$($dirname $0)"
local n="$(pwd)/.nore"
local p="`dirname $0`"
local n="${PWD}/.nore"

if [ -d "${p}" ]; then
p="`( cd \"${p}\" && pwd )`"
if [ -z "$p" -o "/dev/fd" = "$p" ]; then
echo "$n"
elif [ ! -f "${p}/auto/configure" ]; then
Expand All @@ -51,10 +63,10 @@ bootstrap_path () {
fi
}

ROOT="${ROOT:-$(bootstrap_path)}"
NORE_WORK="$(pwd)"
ROOT="${ROOT:-`bootstrap_path`}"
NORE_WORK="$PWD"

PLATFORM="$($uname -s 2>/dev/null)"
PLATFORM="`uname -s 2>/dev/null`"
GITHUB_R="${GITHUB_R:-https://raw.githubusercontent.com/junjiemars}"
GITHUB_H="${GITHUB_H:-https://github.com/junjiemars}"

Expand All @@ -64,7 +76,7 @@ NORE_BRANCH=master
for option
do
case "$option" in
-*=*) value=$(echo "$option" | $sed -e 's/[-_a-zA-Z0-9]*=//') ;;
-*=*) value=`echo "$option" | sed -e 's/[-_a-zA-Z0-9]*=//'` ;;
*) value="" ;;
esac

Expand All @@ -74,7 +86,7 @@ do
--work=*) NORE_WORK="$value" ;;

*)
command="$(echo "$option" | tr '[:upper:]' '[:lower:]')"
command="`echo $option | tr '[:upper:]' '[:lower:]'`"
;;
esac
done
Expand Down Expand Up @@ -108,9 +120,10 @@ on_linux () {

check_nore () {
local r="junjiemars/nore"
if $git -C "${ROOT}" remote -v 2>/dev/null | $grep -q ${r}; then
if [ "$(check_nore_branch)" != "${NORE_BRANCH}" -a "${ROOT}" != "$(pwd)/.nore" ]; then
ROOT="$(pwd)/.nore"
if $(git -C "${ROOT}" remote -v 2>/dev/null | grep -q "${r}"); then
if [ "`check_nore_branch`" != "${NORE_BRANCH}" ] \
&& [ "${ROOT}" != "${PWD}/.nore" ]; then
ROOT="${PWD}/.nore"
test -d "${ROOT}" && rm -rf "${ROOT}"
return 1
else
Expand Down Expand Up @@ -154,6 +167,22 @@ cat_configure () {
# generated by Nore (${GITHUB_H}/nore)
#------------------------------------------------
check_echo_opt () {
# check the echo's "-n" option and "\c" capability
if echo "test\c" | grep -q c; then
echo_c=
if echo -n test | tr '\n' _ | grep -q _; then
echo_n=
else
echo_n=-n
fi
else
echo_n=
echo_c='\c'
fi
}
check_echo_opt
NORE_ROOT="${ROOT%/}"
NORE_BRANCH="${b}"
NORE_L_BOOT="\${NORE_ROOT}/bootstrap.sh"
Expand Down Expand Up @@ -181,7 +210,7 @@ do
esac
done
case "\$(echo \${NORE_L_CONF_COMMAND} | tr '[:upper:]' '[:lower:]')" in
case "\`echo \${NORE_L_CONF_COMMAND} | tr '[:upper:]' '[:lower:]'\`" in
upgrade)
if [ -f \${NORE_L_BOOT} ]; then
\$NORE_L_BOOT --branch=\${NORE_BRANCH} upgrade
Expand Down Expand Up @@ -271,6 +300,8 @@ else
echo
fi
# eof
END

chmod u+x "$new_conf"
Expand Down Expand Up @@ -440,17 +471,18 @@ END
echo_yes_or_no () {
local c="$1"
if [ 0 -eq $c ]; then
$printf "yes\n"
echo "yes"
else
$printf "no\n"
echo "no"
fi
return $c
}
echo_elapsed_seconds () {
local begin=$1
local end="`date +%s`"
$printf "\n... elpased %d seconds\n" $(( ${end}-${begin} ))
echo
echo "... elpased $(( ${end}-${begin} )) seconds."
}
exit_checking () {
Expand All @@ -465,7 +497,7 @@ exit_checking () {
download_gmake () {
local env_dir="${1:-${HOME}/.nore}"
local ver="4.2.90"
local tgz="gnumake-${ver}-$($uname -m).tar.gz"
local tgz="gnumake-${ver}-`uname -m`.tar.gz"
local url="${GITHUB_H}/make/releases/download/${ver}/${tgz}"
local bin="${env_dir}/make.exe"
local t=0
Expand All @@ -492,39 +524,39 @@ echo
echo "configure Nore on $PLATFORM ..."
echo
$printf " + checking make ... "
if $(make -v 1>/dev/null 2>&1); then
echo $echo_n " + checking make ... $echo_c"
if `make -v 1>/dev/null 2>&1`; then
echo_yes_or_no $?
else
echo_yes_or_no $?
if on_windows_nt; then
$printf " + downloading make ... "
echo_yes_or_no $(download_gmake "${HOME}/.nore"; echo $?)
if `on_windows_nt`; then
echo $echo_n " + downloading make ... $echo_c"
echo_yes_or_no `download_gmake "${HOME}/.nore"; echo $?`
fi
fi
[ -d "${ROOT}" ] || mkdir -p "${ROOT}"
# [ -d "${ROOT}" ] || mkdir -p "${ROOT}"
$printf " + checking nore ... "
echo $echo_n " + checking nore ... $echo_c"
if check_nore; then
echo_yes_or_no $?
if [ "yes" = "$NORE_UPGRADE" ]; then
$printf " + upgrading nore ... "
echo $echo_n " + upgrading nore ... $echo_c"
echo_yes_or_no `upgrade_nore ; echo $?`
exit_checking $? $BEGIN
fi
else
echo_yes_or_no $?
$printf $echo_n " + cloning nore ... "
echo_yes_or_no $(clone_nore ; echo $?)
echo $echo_n " + cloning nore ... $echo_c"
echo_yes_or_no `clone_nore ; echo $?`
exit_checking $? $BEGIN
fi
$printf " + generating configure ... "
echo_yes_or_no $(cat_configure ; echo $?)
echo $echo_n " + generating configure ... $echo_c"
echo_yes_or_no `cat_configure ; echo $?`
exit_checking $? $BEGIN
$printf " + generating ~/.nore/cc-env.sh ... "
echo $echo_n " + generating ~/.nore/cc-env.sh ... $echo_c"
echo_yes_or_no $(cat_cc_env "${HOME}/.nore/cc-env.sh"; echo $?)
exit_checking $? $BEGIN
Expand Down

0 comments on commit 86a5dd7

Please sign in to comment.