Browse Source

cleaner install.sh

main
pvincent 2 weeks ago
parent
commit
7488050aaf
  1. 54
      demo_source.sh
  2. 45
      install.sh
  3. 8
      none.sh

54
demo_source.sh

@ -1,54 +0,0 @@
#!/usr/bin/env bash
## CONSTANTS
## FUNCTIONS
function upgrade {
echo "UPGRADE: $*"
if sudo -E "$MIAOU_BASH_DIR"/bin/miaou-bash "$MIAOU_BASH_DIR"/none.sh 3>&1; then
:
else
>&2 echo -------------------------------------------------
>&2 echo "SORRY: installation process (version 0.0.0) has failed!"
>&2 echo "Either retry later when a next version will come up"
>&2 echo "Or report the errorstack printed out above by sending an email to: contact@artcode.re"
fi
}
function assert_supported_distro {
if ! grep -E '^ID=debian|^ID_LIKE=debian' /etc/os-release &&
! grep -E '^ID=arch|^ID_LIKE=arch' /etc/os-release; then
local distro
distro=$(grep -oP '^ID=\K(.*)' /etc/os-release)
>&2 echo "unsupported GNU/Linux distribution: $distro"
>&2 echo 'only debian-like OR arch-like currently supported'
return 10
fi
}
function assert_bash {
if [[ $(basename "$SHELL") != 'bash' ]]; then
>&2 echo "MIAOU ERROR: you are running on SHELL=$SHELL rather than 'bash'!"
return 11
fi
}
function sudo_root {
if [[ "$UID" -ne 0 ]] && ! sudo -vp 'SUDO privilege required: '; then
>&2 echo "canceled"
return 12
fi
}
## MAIN
set -Eeuo pipefail
if assert_supported_distro && assert_bash && sudo_root; then
if [[ ! -v MIAOU_BASH_DIR ]]; then
MIAOU_BASH_DIR=/opt/miaou-bash
export MIAOU_BASH_DIR
fi
upgrade "$@"
else
>&2 echo "MIAOU_BASH_ERROR: requirements failure"
fi

45
install.sh

@ -1,35 +1,41 @@
#!/usr/bin/env bash #!/usr/bin/env bash
## CONSTANTS ## CONSTANTS
BASE_ARCHIVE_URL='https://git.artcode.re/miaou/miaou-bash/archive' BASE_ARCHIVE_URL='https://git.artcode.re/miaou/miaou-bash/archive'
BASE_TAG_URL='https://git.artcode.re/api/v1/repos/miaou/miaou-bash/tags' BASE_TAG_URL='https://git.artcode.re/api/v1/repos/miaou/miaou-bash/tags'
BASH_SHELL='/bin/bash'
## FUNCTIONS ## FUNCTIONS
function upgrade { function upgrade {
echo UPGRADE
echo 'upgrading...'
execute_miaou_lib self-upgrade execute_miaou_lib self-upgrade
} }
function install { function install {
echo INSTALL
local latest_tag
latest_tag=$(
local release
release=$(
curl -s "$BASE_TAG_URL" | curl -s "$BASE_TAG_URL" |
grep '"name":' | grep '"name":' |
cut -d '"' -f4 cut -d '"' -f4
) )
echo "latest_tag=$latest_tag"
echo "deploying release=$release in process..."
local tempfile='/tmp/miaou-bash-latest.tar.gz' local tempfile='/tmp/miaou-bash-latest.tar.gz'
curl -so "$tempfile" "${BASE_ARCHIVE_URL}/${latest_tag}.tar.gz"
sudo tar -xzf "$tempfile" --directory "$(dirname "$MIAOU_BASH_DIR")"
if curl -so "$tempfile" "${BASE_ARCHIVE_URL}/${release}.tar.gz"; then
if sudo tar -xzf "$tempfile" --directory "$(dirname "$MIAOU_BASH_DIR")"; then
rm "$tempfile" rm "$tempfile"
execute_miaou_lib initiate
echo "miaou-bash successfully $deployment_type_adjective"
if execute_miaou_lib initiate; then
echo 'successfully deployed'
else
miaou_error 'unable to initiate further'
fi
else
miaou_error 'unable to uncompress archive'
fi
else
miaou_error 'unable to download release'
fi
} }
function assert_supported_distro { function assert_supported_distro {
@ -49,20 +55,27 @@ function once_installed {
"$(readlink /etc/inputrc)" == "$MIAOU_BASH_DIR"/etc/inputrc ]] "$(readlink /etc/inputrc)" == "$MIAOU_BASH_DIR"/etc/inputrc ]]
} }
function miaou_error {
>&2 echo --------------------------------------------------------------
>&2 echo "MIAOU_ERROR: $1"
>&2 echo "Either retry later when a newer version will come up,"
>&2 echo "Or report the errorstack printed out above to: contact@artcode.re"
}
function execute_miaou_lib { function execute_miaou_lib {
sudo -E "$MIAOU_BASH_DIR"/bin/miaou-bash "$MIAOU_BASH_DIR"/lib/"$1".bash
sudo -E "$MIAOU_BASH_DIR"/bin/miaou-bash "$MIAOU_BASH_DIR"/lib/"$1".sh 3>&1
} }
function assert_bash { function assert_bash {
if [[ $(basename "$SHELL") != 'bash' ]]; then if [[ $(basename "$SHELL") != 'bash' ]]; then
>&2 echo "MIAOU ERROR: you are running on SHELL=$SHELL rather than 'bash'!"
>&2 echo "running on SHELL=$SHELL rather than 'bash'!"
return 11 return 11
fi fi
} }
function sudo_root { function sudo_root {
if [[ "$UID" -ne 0 ]] && ! sudo -vp 'SUDO privilege required: '; then if [[ "$UID" -ne 0 ]] && ! sudo -vp 'SUDO privilege required: '; then
>&2 echo "canceled"
>&2 echo "unauthorized!"
return 12 return 12
fi fi
} }
@ -81,5 +94,5 @@ if assert_supported_distro && assert_bash && sudo_root; then
exec bash -l exec bash -l
fi fi
else else
>&2 echo "MIAOU_BASH_ERROR: requirements failure"
>&2 echo "MIAOU_ERROR: missing requirements"
fi fi

8
none.sh

@ -1,8 +0,0 @@
#!/usr/bin/miaou-bash
echo A
>&2 echo warning1
>&2 echo warning2
echo B
false
echo C
Loading…
Cancel
Save