mirror of
https://github.com/tw93/Mole.git
synced 2026-03-24 15:10:08 +00:00
51
install.sh
51
install.sh
@@ -266,6 +266,45 @@ get_installed_version() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resolve_install_channel() {
|
||||||
|
case "${MOLE_VERSION:-}" in
|
||||||
|
main | latest)
|
||||||
|
printf 'nightly\n'
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
dev)
|
||||||
|
printf 'dev\n'
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [[ "${MOLE_EDGE_INSTALL:-}" == "true" ]]; then
|
||||||
|
printf 'nightly\n'
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf 'stable\n'
|
||||||
|
}
|
||||||
|
|
||||||
|
write_install_channel_metadata() {
|
||||||
|
local channel="$1"
|
||||||
|
local metadata_file="$CONFIG_DIR/install_channel"
|
||||||
|
|
||||||
|
local tmp_file
|
||||||
|
tmp_file=$(mktemp "${CONFIG_DIR}/install_channel.XXXXXX") || return 1
|
||||||
|
{
|
||||||
|
printf 'CHANNEL=%s\n' "$channel"
|
||||||
|
} > "$tmp_file" || {
|
||||||
|
rm -f "$tmp_file" 2> /dev/null || true
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
mv -f "$tmp_file" "$metadata_file" || {
|
||||||
|
rm -f "$tmp_file" 2> /dev/null || true
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# CLI parsing (supports main/latest and version tokens).
|
# CLI parsing (supports main/latest and version tokens).
|
||||||
parse_args() {
|
parse_args() {
|
||||||
local -a args=("$@")
|
local -a args=("$@")
|
||||||
@@ -712,6 +751,12 @@ perform_install() {
|
|||||||
installed_version="$source_version"
|
installed_version="$source_version"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
local install_channel
|
||||||
|
install_channel="$(resolve_install_channel)"
|
||||||
|
if ! write_install_channel_metadata "$install_channel"; then
|
||||||
|
log_warning "Could not write install channel metadata"
|
||||||
|
fi
|
||||||
|
|
||||||
# Edge installs get a suffix to make the version explicit.
|
# Edge installs get a suffix to make the version explicit.
|
||||||
if [[ "${MOLE_EDGE_INSTALL:-}" == "true" ]]; then
|
if [[ "${MOLE_EDGE_INSTALL:-}" == "true" ]]; then
|
||||||
installed_version="${installed_version}-edge"
|
installed_version="${installed_version}-edge"
|
||||||
@@ -795,6 +840,12 @@ perform_update() {
|
|||||||
updated_version="$target_version"
|
updated_version="$target_version"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
local install_channel
|
||||||
|
install_channel="$(resolve_install_channel)"
|
||||||
|
if ! write_install_channel_metadata "$install_channel"; then
|
||||||
|
log_warning "Could not write install channel metadata"
|
||||||
|
fi
|
||||||
|
|
||||||
echo -e "${GREEN}${ICON_SUCCESS}${NC} Updated to latest version, $updated_version"
|
echo -e "${GREEN}${ICON_SUCCESS}${NC} Updated to latest version, $updated_version"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
18
mole
18
mole
@@ -87,6 +87,18 @@ is_homebrew_install() {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get_install_channel() {
|
||||||
|
local channel_file="$SCRIPT_DIR/install_channel"
|
||||||
|
local channel="stable"
|
||||||
|
if [[ -f "$channel_file" ]]; then
|
||||||
|
channel=$(sed -n 's/^CHANNEL=\(.*\)$/\1/p' "$channel_file" | head -1)
|
||||||
|
fi
|
||||||
|
case "$channel" in
|
||||||
|
nightly | dev | stable) printf '%s\n' "$channel" ;;
|
||||||
|
*) printf 'stable\n' ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
# Background update notice
|
# Background update notice
|
||||||
check_for_updates() {
|
check_for_updates() {
|
||||||
local msg_cache="$HOME/.cache/mole/update_message"
|
local msg_cache="$HOME/.cache/mole/update_message"
|
||||||
@@ -205,7 +217,13 @@ show_version() {
|
|||||||
install_method="Homebrew"
|
install_method="Homebrew"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
local channel
|
||||||
|
channel=$(get_install_channel)
|
||||||
|
|
||||||
printf '\nMole version %s\n' "$VERSION"
|
printf '\nMole version %s\n' "$VERSION"
|
||||||
|
if [[ "$channel" == "nightly" ]]; then
|
||||||
|
printf 'Channel: Nightly\n'
|
||||||
|
fi
|
||||||
printf 'macOS: %s\n' "$os_ver"
|
printf 'macOS: %s\n' "$os_ver"
|
||||||
printf 'Architecture: %s\n' "$arch"
|
printf 'Architecture: %s\n' "$arch"
|
||||||
printf 'Kernel: %s\n' "$kernel"
|
printf 'Kernel: %s\n' "$kernel"
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ setup_file() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
teardown_file() {
|
teardown_file() {
|
||||||
|
rm -f "$PROJECT_ROOT/install_channel"
|
||||||
rm -rf "$HOME"
|
rm -rf "$HOME"
|
||||||
if [[ -n "${ORIGINAL_HOME:-}" ]]; then
|
if [[ -n "${ORIGINAL_HOME:-}" ]]; then
|
||||||
export HOME="$ORIGINAL_HOME"
|
export HOME="$ORIGINAL_HOME"
|
||||||
@@ -47,6 +48,7 @@ SCRIPT
|
|||||||
setup() {
|
setup() {
|
||||||
rm -rf "$HOME/.config"
|
rm -rf "$HOME/.config"
|
||||||
mkdir -p "$HOME"
|
mkdir -p "$HOME"
|
||||||
|
rm -f "$PROJECT_ROOT/install_channel"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "mole --help prints command overview" {
|
@test "mole --help prints command overview" {
|
||||||
@@ -63,6 +65,18 @@ setup() {
|
|||||||
[[ "$output" == *"$expected_version"* ]]
|
[[ "$output" == *"$expected_version"* ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "mole --version shows nightly channel metadata" {
|
||||||
|
expected_version="$(grep '^VERSION=' "$PROJECT_ROOT/mole" | head -1 | sed 's/VERSION=\"\(.*\)\"/\1/')"
|
||||||
|
cat > "$PROJECT_ROOT/install_channel" <<'EOF'
|
||||||
|
CHANNEL=nightly
|
||||||
|
EOF
|
||||||
|
|
||||||
|
run env HOME="$HOME" "$PROJECT_ROOT/mole" --version
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "$output" == *"Mole version $expected_version"* ]]
|
||||||
|
[[ "$output" == *"Channel: Nightly"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
@test "mole unknown command returns error" {
|
@test "mole unknown command returns error" {
|
||||||
run env HOME="$HOME" "$PROJECT_ROOT/mole" unknown-command
|
run env HOME="$HOME" "$PROJECT_ROOT/mole" unknown-command
|
||||||
[ "$status" -ne 0 ]
|
[ "$status" -ne 0 ]
|
||||||
|
|||||||
Reference in New Issue
Block a user