You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.3 KiB
48 lines
1.3 KiB
#!/usr/bin/env miaou-bash
|
|
|
|
# CONSTANTS
|
|
|
|
#FIXME: source from functions.bash
|
|
readonly DESTINATION=/opt
|
|
readonly MAIN_TAR_GZ_URL="https://git.artcode.re/miaou/miaou-bash/archive/main.tar.gz"
|
|
|
|
# FUNCTIONS
|
|
|
|
#FIXME: source from functions.bash
|
|
function bootstrap {
|
|
if [[ ! -d "$DESTINATION/miaou-bash" ]]; then
|
|
local temp_dir
|
|
temp_dir=$(mktemp -d)
|
|
pushd "$temp_dir" >/dev/null || return 2
|
|
curl -s -O $MAIN_TAR_GZ_URL
|
|
tar -xzf main.tar.gz --directory "$DESTINATION"
|
|
echo "directory: miaou-bash successfully deployed to $DESTINATION"
|
|
popd >/dev/null || return 3
|
|
fi
|
|
|
|
local source_bin="$DESTINATION/miaou-bash/bin/miaou-bash"
|
|
local dest_bin="/usr/bin/miaou-bash"
|
|
if ! cmp -s "$source_bin" "$dest_bin"; then
|
|
cp -f "$source_bin" "$dest_bin"
|
|
echo "executable: /usr/bin/miaou-bash freshly created"
|
|
fi
|
|
|
|
export MIAOU_BASH_DIR="$DESTINATION/miaou-bash"
|
|
}
|
|
|
|
# MAIN
|
|
|
|
[[ "$UID" -ne 0 ]] && echo 'root privilege required' && exit 1
|
|
[[ ! -v MIAOU_BASH_DIR ]] && export MIAOU_BASH_DIR="$DESTINATION/miaou-bash"
|
|
current=$(miaou-bash --version)
|
|
latest=$("$MIAOU_BASH_DIR/tools/wget_semver" artcode miaou/miaou-bash)
|
|
|
|
if [[ "$current" == "$latest" ]]; then
|
|
echo "up-to-date version: $current"
|
|
else
|
|
rm -rf "$MIAOU_BASH_DIR"
|
|
bootstrap
|
|
miaou-bash "$MIAOU_BASH_DIR/lib/init.bash"
|
|
echo "miaou-bash successfully updated"
|
|
miaou-bash --version
|
|
fi
|