|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +clear |
| 4 | + |
| 5 | +COLOR_RESET="\e[0m" |
| 6 | +COLOR_GREEN="\e[32m" |
| 7 | +COLOR_YELLOW="\e[33m" |
| 8 | +COLOR_CYAN="\e[36m" |
| 9 | +COLOR_RED="\e[31m" |
| 10 | +COLOR_BLUE="\e[34m" |
| 11 | + |
| 12 | +VERSION="4.1.2" |
| 13 | +TARGET_DIR="/usr/bin" |
| 14 | +SCRIPTS_DIR="$TARGET_DIR/scripts" |
| 15 | +DESKTOP_FILE="/usr/share/applications/carch.desktop" |
| 16 | +MAN_PAGES_DIR="/usr/share/man/man1/carch.1" |
| 17 | +ICON_DIR="/usr/share/icons/hicolor" |
| 18 | + |
| 19 | +BASH_COMPLETION_DIR="/usr/share/bash-completion/completions" |
| 20 | +ZSH_COMPLETION_DIR="/usr/share/zsh/functions/Completion/Unix" |
| 21 | +FISH_COMPLETION_DIR="/usr/share/fish/completions" |
| 22 | + |
| 23 | +check_dependency() { |
| 24 | + local dependency="$1" |
| 25 | + if ! command -v "$dependency" &>/dev/null; then |
| 26 | + echo -e "${COLOR_YELLOW}:: Installing missing dependency: $dependency${COLOR_RESET}" |
| 27 | + sudo dnf install -y "$dependency" |
| 28 | + fi |
| 29 | +} |
| 30 | + |
| 31 | +for pkg in git cargo gcc unzip curl wget figlet man-db man bash sed xdg-user-dirs unzip google-noto-color-emoji-fonts google-noto-emoji-fonts jetbrains-mono-fonts-all tar tree-sitter gum bash-completion-devel zsh fish libtree-sitter rust-tree-sitter-devel glibc zip; do |
| 32 | + check_dependency "$pkg" |
| 33 | +done |
| 34 | + |
| 35 | +clear |
| 36 | + |
| 37 | +echo -e "${COLOR_CYAN}" |
| 38 | +figlet -f slant "Carch" |
| 39 | +echo "Version $VERSION" |
| 40 | +echo -e "${COLOR_RESET}" |
| 41 | + |
| 42 | +CHOICE=$(gum choose "Rolling Release" "Stable Release" "Cancel") |
| 43 | +if [[ $CHOICE == "Cancel" ]]; then |
| 44 | + echo -e "${COLOR_RED}Installation canceled by the user.${COLOR_RESET}" |
| 45 | + exit 0 |
| 46 | +fi |
| 47 | + |
| 48 | +echo -e "${COLOR_YELLOW}Removing existing installation...${COLOR_RESET}" |
| 49 | +sudo rm -rf "$TARGET_DIR/carch" "$TARGET_DIR/carch-tui" "$SCRIPTS_DIR" |
| 50 | +sudo rm -f "$DESKTOP_FILE" "$MAN_PAGES_DIR" |
| 51 | +sudo rm -f "$BASH_COMPLETION_DIR/carch" "$ZSH_COMPLETION_DIR/_carch" "$FISH_COMPLETION_DIR/carch.fish" |
| 52 | +echo -e "${COLOR_YELLOW}Removing icons...${COLOR_RESET}" |
| 53 | +for size in 16 24 32 48 64 128 256; do |
| 54 | + sudo rm -f "$ICON_DIR/${size}x${size}/apps/carch.png" |
| 55 | +done |
| 56 | + |
| 57 | +if [[ $CHOICE == "Rolling Release" ]]; then |
| 58 | + echo -e "${COLOR_YELLOW}:: Cloning and building Rolling Release...${COLOR_RESET}" |
| 59 | + rm -rf /tmp/carch-build |
| 60 | + git clone --depth=1 https://github.com/harilvfs/carch.git /tmp/carch-build |
| 61 | + cd /tmp/carch-build |
| 62 | + cargo build --release |
| 63 | + |
| 64 | + echo -e "${COLOR_YELLOW}:: Installing binaries...${COLOR_RESET}" |
| 65 | + sudo mv build/carch "$TARGET_DIR/" |
| 66 | + sudo mv target/release/carch-tui "$TARGET_DIR/" |
| 67 | + |
| 68 | +elif [[ $CHOICE == "Stable Release" ]]; then |
| 69 | + echo -e "${COLOR_YELLOW}Downloading and installing Stable Release...${COLOR_RESET}" |
| 70 | + sudo curl -L "https://github.com/harilvfs/carch/releases/latest/download/carch" -o "$TARGET_DIR/carch" |
| 71 | + sudo curl -L "https://github.com/harilvfs/carch/releases/latest/download/carch-tui" -o "$TARGET_DIR/carch-tui" |
| 72 | + sudo chmod +x "$TARGET_DIR/carch" "$TARGET_DIR/carch-tui" |
| 73 | +fi |
| 74 | + |
| 75 | +echo -e "${COLOR_YELLOW}:: Downloading and installing scripts...${COLOR_RESET}" |
| 76 | +sudo mkdir -p "$SCRIPTS_DIR" |
| 77 | +SCRIPT_URL="https://github.com/harilvfs/carch/releases/latest/download/scripts.zip" |
| 78 | +[[ $CHOICE == "Rolling Release" ]] && SCRIPT_URL="https://github.com/harilvfs/carch/raw/main/source/zip/scripts.zip" |
| 79 | +curl -L "$SCRIPT_URL" -o /tmp/scripts.zip |
| 80 | +sudo unzip -q /tmp/scripts.zip -d "$SCRIPTS_DIR" |
| 81 | +sudo chmod +x "$SCRIPTS_DIR"/*.sh |
| 82 | +rm /tmp/scripts.zip |
| 83 | + |
| 84 | +echo -e "${COLOR_YELLOW}:: Installing man pages...${COLOR_RESET}" |
| 85 | +curl -L "https://raw.githubusercontent.com/harilvfs/carch/main/man/carch.1" -o /tmp/carch.1 |
| 86 | +sudo mv /tmp/carch.1 "$MAN_PAGES_DIR" |
| 87 | +sudo mandb &>/dev/null |
| 88 | + |
| 89 | +detect_shell() { |
| 90 | + echo "$(basename "$SHELL")" |
| 91 | +} |
| 92 | + |
| 93 | +ensure_directories() { |
| 94 | + local shell="$1" |
| 95 | + local dir="" |
| 96 | + |
| 97 | + case "$shell" in |
| 98 | + bash) |
| 99 | + dir="$BASH_COMPLETION_DIR" |
| 100 | + ;; |
| 101 | + zsh) |
| 102 | + dir="$ZSH_COMPLETION_DIR" |
| 103 | + ;; |
| 104 | + fish) |
| 105 | + dir="$FISH_COMPLETION_DIR" |
| 106 | + ;; |
| 107 | + *) |
| 108 | + echo -e "${COLOR_RED}Unsupported shell: $shell. Skipping completion setup.${COLOR_RESET}" |
| 109 | + return |
| 110 | + ;; |
| 111 | + esac |
| 112 | + |
| 113 | + if [[ ! -d "$dir" ]]; then |
| 114 | + echo -e "${COLOR_CYAN}:: Creating completion directory for $shell...${COLOR_RESET}" |
| 115 | + sudo mkdir -p "$dir" || { echo -e "${COLOR_RED}Failed to create $shell completion directory.${COLOR_RESET}"; exit 1; } |
| 116 | + else |
| 117 | + echo -e "${COLOR_GREEN}Completion directory for $shell already exists.${COLOR_RESET}" |
| 118 | + fi |
| 119 | +} |
| 120 | + |
| 121 | +install_completions() { |
| 122 | + local shell="$1" |
| 123 | + echo -e "${COLOR_YELLOW}:: Installing completion files for $shell...${COLOR_RESET}" |
| 124 | + |
| 125 | + case "$shell" in |
| 126 | + bash) |
| 127 | + sudo curl -L "https://raw.githubusercontent.com/harilvfs/carch/refs/heads/main/completions/bash/carch" \ |
| 128 | + -o "$BASH_COMPLETION_DIR/carch" &>/dev/null |
| 129 | + echo -e "${COLOR_GREEN}:: Bash completion installed in:${COLOR_CYAN} $BASH_COMPLETION_DIR${COLOR_RESET}" |
| 130 | + ;; |
| 131 | + zsh) |
| 132 | + sudo curl -L "https://raw.githubusercontent.com/harilvfs/carch/refs/heads/main/completions/zsh/_carch" \ |
| 133 | + -o "$ZSH_COMPLETION_DIR/_carch" &>/dev/null |
| 134 | + echo -e "${COLOR_GREEN}:: Zsh completion installed in:${COLOR_CYAN} $ZSH_COMPLETION_DIR${COLOR_RESET}" |
| 135 | + ;; |
| 136 | + fish) |
| 137 | + sudo curl -L "https://raw.githubusercontent.com/harilvfs/carch/refs/heads/main/completions/fish/carch.fish" \ |
| 138 | + -o "$FISH_COMPLETION_DIR/carch.fish" &>/dev/null |
| 139 | + echo -e "${COLOR_GREEN}:: Fish completion installed in:${COLOR_CYAN} $FISH_COMPLETION_DIR${COLOR_RESET}" |
| 140 | + ;; |
| 141 | + *) |
| 142 | + echo -e "${COLOR_RED}Unknown shell: $shell. Skipping completion installation.${COLOR_RESET}" |
| 143 | + ;; |
| 144 | + esac |
| 145 | +} |
| 146 | + |
| 147 | +current_shell=$(detect_shell) |
| 148 | +ensure_directories "$current_shell" |
| 149 | +install_completions "$current_shell" |
| 150 | + |
| 151 | +echo -e "${COLOR_YELLOW}:: Installing icons...${COLOR_RESET}" |
| 152 | +for size in 16 24 32 48 64 128 256; do |
| 153 | + icon_path="$ICON_DIR/${size}x${size}/apps" |
| 154 | + if [[ -n "$icon_path" ]]; then |
| 155 | + sudo mkdir -p "$icon_path" || { echo "Failed to create $icon_path"; exit 1; } |
| 156 | + sudo curl -L "https://raw.githubusercontent.com/harilvfs/carch/main/source/logo/product_logo_${size}.png" -o "$icon_path/carch.png" &>/dev/null |
| 157 | + fi |
| 158 | +done |
| 159 | + |
| 160 | +echo -e "${COLOR_YELLOW}:: Creating desktop entry...${COLOR_RESET}" |
| 161 | +sudo tee "$DESKTOP_FILE" > /dev/null <<EOL |
| 162 | +[Desktop Entry] |
| 163 | +Name=Carch |
| 164 | +Comment=An automated script for quick & easy Fedora system setup. |
| 165 | +Exec=$TARGET_DIR/carch |
| 166 | +Icon=carch |
| 167 | +Type=Application |
| 168 | +Terminal=true |
| 169 | +Categories=Utility; |
| 170 | +EOL |
| 171 | + |
| 172 | +display_message() { |
| 173 | + gum style --border "normal" --width 50 --padding 1 --foreground "white" --background "blue" --align "center" "Carch installed successfully! |
| 174 | + Use 'carch' or 'carch --tui' to run the script. |
| 175 | +For help, type 'carch --help'." |
| 176 | +} |
| 177 | + |
| 178 | +display_message |
| 179 | + |
0 commit comments