aboutsummaryrefslogtreecommitdiffstats
path: root/config/hypr/scripts/build-awww.sh
blob: c59c34c0f4d5f0a7fe9405db2496da62cec4190a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/usr/bin/env bash
set -euo pipefail

RED="\033[0;31m"
GREEN="\033[0;32m"
YELLOW="\033[1;33m"
BLUE="\033[0;34m"
NC="\033[0m"

ICON_OK="✅"
ICON_WARN="⚠️"
ICON_ERR="❌"
ICON_INFO="ℹ️"

fail() {
  printf "${RED}${ICON_ERR} %s${NC}\n" "$1" >&2
  exit 1
}

info() {
  printf "${BLUE}${ICON_INFO} %s${NC}\n" "$1"
}

warn() {
  printf "${YELLOW}${ICON_WARN} %s${NC}\n" "$1"
}

ok() {
  printf "${GREEN}${ICON_OK} %s${NC}\n" "$1"
}

trap 'fail "Script failed at line $LINENO."' ERR

if [[ ! -t 0 ]]; then
  fail "This script requires an interactive terminal. Run it directly in a terminal (e.g. ./build-awww.sh)."
fi

info "Starting awww installer..."

if command -v awww >/dev/null 2>&1; then
  ok "awww is already installed. Nothing to do."
  exit 0
fi

if ! command -v git >/dev/null 2>&1; then
  fail "git is required but not installed."
fi

detect_distro() {
  if [[ -r /etc/os-release ]]; then
    # shellcheck disable=SC1091
    . /etc/os-release
    echo "${ID:-}"
    return
  fi
  echo ""
}

prompt_confirm_distro() {
  local detected="$1"
  local choice=""
  if [[ -n "$detected" ]]; then
    printf "${BLUE}${ICON_INFO} Detected distro: %s${NC}\n" "$detected" >/dev/tty
    printf "Confirm? (Y/y to confirm, N/n to choose, Q/q to quit): " >/dev/tty
    read -r choice </dev/tty
    case "$choice" in
      [Yy]) echo "$detected"; return ;;
      [Qq]) exit 0 ;;
      [Nn]) ;;
      *) warn "Invalid choice, continuing to manual selection." ;;
    esac
  fi
  echo "Supported distros:"
  echo "  1) debian"
  echo "  2) ubuntu"
  echo "  3) arch"
  echo "  4) opensuse"
  echo "  5) fedora"
  echo "  6) gentoo"
  printf "Select your distro (1-6) or Q/q to quit: " >/dev/tty
  read -r choice </dev/tty
  read -r choice
  case "$choice" in
    1) echo "debian" ;;
    2) echo "ubuntu" ;;
    3) echo "arch" ;;
    4) echo "opensuse" ;;
    5) echo "fedora" ;;
    6) echo "gentoo" ;;
    [Qq]) exit 0 ;;
    *) fail "Invalid selection." ;;
  esac
}

distro="$(prompt_confirm_distro "$(detect_distro)")"

install_deps_debian_ubuntu() {
  local missing=()
  for pkg in pkg-config liblz4-dev; do
    dpkg -s "$pkg" >/dev/null 2>&1 || missing+=("$pkg")
  done
  if (( ${#missing[@]} )); then
    info "Installing deps: ${missing[*]}"
    sudo apt update
    sudo apt install -y "${missing[@]}"
  else
    ok "All required deps already installed."
  fi
}

install_deps_fedora() {
  local missing=()
  for pkg in wayland-protocols lz4-devel wayland-devel; do
    rpm -q "$pkg" >/dev/null 2>&1 || missing+=("$pkg")
  done
  if (( ${#missing[@]} )); then
    info "Installing deps: ${missing[*]}"
    sudo dnf install -y "${missing[@]}"
  else
    ok "All required deps already installed."
  fi
}

install_deps_opensuse() {
  local missing=()
  for pkg in pkg-config liblz4-devel; do
    rpm -q "$pkg" >/dev/null 2>&1 || missing+=("$pkg")
  done
  if (( ${#missing[@]} )); then
    info "Installing deps: ${missing[*]}"
    sudo zypper install -y "${missing[@]}"
  else
    ok "All required deps already installed."
  fi
}

install_deps_arch() {
  local missing=()
  for pkg in pkgconf lz4 wayland-protocols; do
    pacman -Qi "$pkg" >/dev/null 2>&1 || missing+=("$pkg")
  done
  if (( ${#missing[@]} )); then
    info "Installing deps: ${missing[*]}"
    sudo pacman -S --needed --noconfirm "${missing[@]}"
  else
    ok "All required deps already installed."
  fi
}

ensure_cargo() {
  if command -v cargo >/dev/null 2>&1; then
    ok "cargo is available."
    return
  fi
  case "$distro" in
    debian|ubuntu|fedora|opensuse)
      info "Installing Rust toolchain via rustup..."
      curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
      # shellcheck disable=SC1091
      source "$HOME/.cargo/env"
      ;;
    arch)
      info "Installing Rust toolchain..."
      sudo pacman -S --needed --noconfirm rust
      ;;
    gentoo)
      ;;
    *)
      fail "Unknown distro for cargo install."
      ;;
  esac
  command -v cargo >/dev/null 2>&1 || fail "cargo is still not available."
}

case "$distro" in
  debian) install_deps_debian_ubuntu ;;
  ubuntu) install_deps_debian_ubuntu ;;
  fedora) install_deps_fedora ;;
  opensuse) install_deps_opensuse ;;
  arch) install_deps_arch ;;
  gentoo)
    info "Installing awww via Portage..."
    sudo emerge gui-apps/awww
    ok "awww installed successfully."
    exit 0
    ;;
  *) fail "Unsupported distro: $distro" ;;
esac

ensure_cargo

info "Cloning or updating awww..."
cd "$HOME"
if [[ -d awww/.git ]]; then
  git -C awww pull --rebase
else
  git clone https://codeberg.org/LGFae/awww.git
fi

cd "$HOME/awww"
info "Building awww..."
cargo build --release

info "Installing binaries..."
sudo install -vDm755 target/release/awww -t /usr/bin/
sudo install -vDm755 target/release/awww-daemon -t /usr/bin/
sudo install -vDm644 completions/_awww -t /usr/share/zsh/site-functions/

ok "awww installed successfully."
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage