|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +## Detect OS |
| 6 | +OS="$(uname -s)" |
| 7 | +ARCH="$(uname -m)" |
| 8 | + |
| 9 | +function detect_linux_distro() { |
| 10 | + if [ -f /etc/os-release ]; then |
| 11 | + . /etc/os-release |
| 12 | + echo "$ID" |
| 13 | + else |
| 14 | + echo "unknown" |
| 15 | + fi |
| 16 | +} |
| 17 | + |
| 18 | +function install_fresh_brew() { |
| 19 | + if ! command -v brew &>/dev/null; then |
| 20 | + echo "Error: Homebrew is not installed. Install it from https://brew.sh" |
| 21 | + exit 1 |
| 22 | + fi |
| 23 | + |
| 24 | + brew tap sinelaw/fresh |
| 25 | + brew install fresh-editor |
| 26 | +} |
| 27 | + |
| 28 | +function install_fresh_arch() { |
| 29 | + if command -v yay &>/dev/null; then |
| 30 | + yay -S fresh-editor-bin |
| 31 | + elif command -v paru &>/dev/null; then |
| 32 | + paru -S fresh-editor-bin |
| 33 | + else |
| 34 | + echo "Installing fresh-editor from AUR manually" |
| 35 | + local tmpdir |
| 36 | + tmpdir="$(mktemp -d)" |
| 37 | + git clone https://aur.archlinux.org/fresh-editor-bin.git "$tmpdir/fresh-editor-bin" |
| 38 | + cd "$tmpdir/fresh-editor-bin" |
| 39 | + makepkg --syncdeps --install |
| 40 | + cd - |
| 41 | + rm -rf "$tmpdir" |
| 42 | + fi |
| 43 | +} |
| 44 | + |
| 45 | +function install_fresh_deb() { |
| 46 | + echo "Downloading latest .deb package" |
| 47 | + |
| 48 | + local deb_url |
| 49 | + |
| 50 | + deb_url="$(curl -s https://api.github.com/repos/sinelaw/fresh/releases/latest \ |
| 51 | + | grep "browser_download_url.*_$(dpkg --print-architecture)\.deb" \ |
| 52 | + | cut -d '"' -f 4)" |
| 53 | + |
| 54 | + if [ -z "$deb_url" ]; then |
| 55 | + echo "Error: Could not find .deb download URL for architecture $(dpkg --print-architecture)" |
| 56 | + exit 1 |
| 57 | + fi |
| 58 | + |
| 59 | + local tmpfile |
| 60 | + tmpfile="$(mktemp --suffix=.deb)" |
| 61 | + |
| 62 | + curl -sL "$deb_url" -o "$tmpfile" |
| 63 | + sudo dpkg -i "$tmpfile" |
| 64 | + rm -f "$tmpfile" |
| 65 | +} |
| 66 | + |
| 67 | +function install_fresh_rpm() { |
| 68 | + echo "Downloading latest .rpm package" |
| 69 | + |
| 70 | + local rpm_url |
| 71 | + |
| 72 | + rpm_url="$(curl -s https://api.github.com/repos/sinelaw/fresh/releases/latest \ |
| 73 | + | grep "browser_download_url.*\.$(uname -m)\.rpm" \ |
| 74 | + | cut -d '"' -f 4)" |
| 75 | + |
| 76 | + if [ -z "$rpm_url" ]; then |
| 77 | + echo "Error: Could not find .rpm download URL for architecture $(uname -m)" |
| 78 | + exit 1 |
| 79 | + fi |
| 80 | + |
| 81 | + local tmpfile |
| 82 | + tmpfile="$(mktemp --suffix=.rpm)" |
| 83 | + |
| 84 | + curl -sL "$rpm_url" -o "$tmpfile" |
| 85 | + sudo rpm -U "$tmpfile" |
| 86 | + rm -f "$tmpfile" |
| 87 | +} |
| 88 | + |
| 89 | +function install_fresh_gentoo() { |
| 90 | + echo "Installing fresh-editor from GURU overlay" |
| 91 | + sudo emerge --ask app-editors/fresh |
| 92 | +} |
| 93 | + |
| 94 | +function install_fresh_binary() { |
| 95 | + echo "No native package method available. Installing from pre-built binary" |
| 96 | + |
| 97 | + local target="" |
| 98 | + case "$OS" in |
| 99 | + Linux) |
| 100 | + target="${ARCH}-unknown-linux-gnu" |
| 101 | + ;; |
| 102 | + Darwin) |
| 103 | + target="${ARCH}-apple-darwin" |
| 104 | + ;; |
| 105 | + *) |
| 106 | + echo "Error: Unsupported OS '$OS' for binary install." |
| 107 | + exit 1 |
| 108 | + ;; |
| 109 | + esac |
| 110 | + |
| 111 | + ## Normalize arch name (x86_64 is already correct, arm64 -> aarch64) |
| 112 | + target="${target/arm64/aarch64}" |
| 113 | + |
| 114 | + local tarball="fresh-editor-${target}.tar.xz" |
| 115 | + local download_url |
| 116 | + download_url="$(curl -s https://api.github.com/repos/sinelaw/fresh/releases/latest \ |
| 117 | + | grep "browser_download_url.*${target}\.tar\.xz\"" \ |
| 118 | + | cut -d '"' -f 4)" |
| 119 | + |
| 120 | + if [ -z "$download_url" ]; then |
| 121 | + echo "Error: Could not find binary release for target '$target'" |
| 122 | + exit 1 |
| 123 | + fi |
| 124 | + |
| 125 | + local tmpdir |
| 126 | + tmpdir="$(mktemp -d)" |
| 127 | + echo "Downloading $download_url " |
| 128 | + curl -sL "$download_url" -o "$tmpdir/$tarball" |
| 129 | + |
| 130 | + echo "Extracting" |
| 131 | + tar -xf "$tmpdir/$tarball" -C "$tmpdir" |
| 132 | + |
| 133 | + ## Install binary to ~/.local/bin |
| 134 | + mkdir -p ~/.local/bin |
| 135 | + local fresh_bin |
| 136 | + fresh_bin="$(find "$tmpdir" -name 'fresh' -type f -executable | head -n 1)" |
| 137 | + |
| 138 | + if [ -z "$fresh_bin" ]; then |
| 139 | + ## Try without executable bit (tar might not preserve it) |
| 140 | + fresh_bin="$(find "$tmpdir" -name 'fresh' -type f | head -n 1)" |
| 141 | + fi |
| 142 | + |
| 143 | + if [ -z "$fresh_bin" ]; then |
| 144 | + echo "Error: Could not find 'fresh' binary in extracted archive." |
| 145 | + rm -rf "$tmpdir" |
| 146 | + exit 1 |
| 147 | + fi |
| 148 | + |
| 149 | + cp "$fresh_bin" ~/.local/bin/fresh |
| 150 | + chmod +x ~/.local/bin/fresh |
| 151 | + rm -rf "$tmpdir" |
| 152 | + |
| 153 | + echo "Installed fresh to ~/.local/bin/fresh" |
| 154 | + if ! echo "$PATH" | grep -q "$HOME/.local/bin"; then |
| 155 | + echo "Warning: ~/.local/bin is not in your PATH. Add it to your shell profile." |
| 156 | + fi |
| 157 | +} |
| 158 | + |
| 159 | +echo "Installing Fresh terminal IDE" |
| 160 | +echo " OS: $OS ($ARCH)" |
| 161 | + |
| 162 | +case "$OS" in |
| 163 | + Darwin) |
| 164 | + echo " Method: Homebrew" |
| 165 | + install_fresh_brew |
| 166 | + ;; |
| 167 | + |
| 168 | + Linux) |
| 169 | + DISTRO="$(detect_linux_distro)" |
| 170 | + echo " Distro: $DISTRO" |
| 171 | + |
| 172 | + case "$DISTRO" in |
| 173 | + ## Brew-based immutable distros |
| 174 | + bazzite|bluefin|aurora) |
| 175 | + echo " Method: Homebrew" |
| 176 | + install_fresh_brew |
| 177 | + ;; |
| 178 | + |
| 179 | + ## Arch Linux and derivatives |
| 180 | + arch|endeavouros|manjaro) |
| 181 | + echo " Method: AUR" |
| 182 | + install_fresh_arch |
| 183 | + ;; |
| 184 | + |
| 185 | + ## Debian/Ubuntu family |
| 186 | + debian|ubuntu|pop|linuxmint|elementary|zorin|kali) |
| 187 | + echo " Method: .deb package" |
| 188 | + install_fresh_deb |
| 189 | + ;; |
| 190 | + |
| 191 | + ## RPM-based distros |
| 192 | + fedora|rhel|centos|rocky|alma|ol|opensuse*|sles) |
| 193 | + echo " Method: .rpm package" |
| 194 | + install_fresh_rpm |
| 195 | + ;; |
| 196 | + |
| 197 | + ## Gentoo |
| 198 | + gentoo) |
| 199 | + echo " Method: GURU overlay" |
| 200 | + install_fresh_gentoo |
| 201 | + ;; |
| 202 | + |
| 203 | + ## Anything else: fall back to pre-built binary |
| 204 | + *) |
| 205 | + echo " Method: Pre-built binary (fallback)" |
| 206 | + install_fresh_binary |
| 207 | + ;; |
| 208 | + esac |
| 209 | + ;; |
| 210 | + |
| 211 | + *) |
| 212 | + echo "Unsupported OS: $OS" |
| 213 | + exit 1 |
| 214 | + ;; |
| 215 | +esac |
| 216 | + |
| 217 | +if [[ $? -ne 0 ]]; then |
| 218 | + echo "Fresh installation failed." |
| 219 | + exit 1 |
| 220 | +fi |
| 221 | + |
| 222 | +echo "" |
| 223 | +echo "Fresh terminal IDE installed successfully." |
0 commit comments