|
| 1 | +#!/bin/bash |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | +# |
| 4 | +# |
| 5 | +# This file is part of ruri, with ABSOLUTELY NO WARRANTY. |
| 6 | +# |
| 7 | +# MIT License |
| 8 | +# Copyright (c) 2025 Moe-hacker |
| 9 | +# |
| 10 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 11 | +# of this software and associated documentation files (the "Software"), to deal |
| 12 | +# in the Software without restriction, including without limitation the rights |
| 13 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 14 | +# copies of the Software, and to permit persons to whom the Software is |
| 15 | +# furnished to do so, subject to the following conditions: |
| 16 | +# |
| 17 | +# The above copyright notice and this permission notice shall be included in all |
| 18 | +# copies or substantial portions of the Software. |
| 19 | +# |
| 20 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 21 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 22 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 23 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 24 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 25 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 26 | +# SOFTWARE. |
| 27 | +error() { |
| 28 | + printf "\033[?1049l" |
| 29 | + printf "\033[?25h" |
| 30 | + printf "\033[31mError: %s\033[0m\n" "$1" |
| 31 | + exit 1 |
| 32 | +} |
| 33 | +UNAME_ARCH=$(uname -m) |
| 34 | +case ${UNAME_ARCH} in |
| 35 | +armv7* | armv8l) CPU_ARCH="armhf" ;; |
| 36 | +armv[1-6]*) CPU_ARCH="armv7" ;; |
| 37 | +aarch64 | armv8* | arm64 | arm*) CPU_ARCH="aarch64" ;; |
| 38 | +x86_64 | amd64) CPU_ARCH="x86_64" ;; |
| 39 | +i*86 | x86) CPU_ARCH="i386" ;; |
| 40 | +risc*) CPU_ARCH="riscv64" ;; |
| 41 | +s390*) ARCH_TYPE="s390x" ;; |
| 42 | +ppc*) ARCH_TYPE="ppc64le" ;; |
| 43 | +loong*) ARCH_TYPE="loongarch64" ;; |
| 44 | +*) CPU_ARCH="" ;; |
| 45 | +esac |
| 46 | +if [ -z "${CPU_ARCH}" ]; then |
| 47 | + error "Cannot detect CPU architecture" |
| 48 | +fi |
| 49 | +URL="https://github.com/Moe-hacker/ruri/releases/latest/download/${CPU_ARCH}.tar" |
| 50 | +DIR="$(pwd)" |
| 51 | +fallback() { |
| 52 | + cd "$DIR" || exit 1 |
| 53 | + printf "\033[?1049l" |
| 54 | + printf "\033[?25h" |
| 55 | + echo "Fallback mode..." |
| 56 | + if !command -v wget >/dev/null 2>&1; then |
| 57 | + curl -L "$URL" -o ruri.tar |
| 58 | + if [ $? -ne 0 ]; then |
| 59 | + error "Download failed!" |
| 60 | + fi |
| 61 | + else |
| 62 | + wget -q --show-progress --progress=dot "$URL" -O ruri.tar |
| 63 | + fi |
| 64 | + if [ ! -f ruri.tar ]; then |
| 65 | + error "Download failed!" |
| 66 | + fi |
| 67 | + tar -xf ruri.tar |
| 68 | + rm -f ruri.tar |
| 69 | + rm -f LICENSE |
| 70 | + chmod +x ruri |
| 71 | + echo "Download complete!" |
| 72 | + echo "ruri ${CPU_ARCH} has been downloaded successfully to $(pwd)/ruri" |
| 73 | + exit 0 |
| 74 | +} |
| 75 | +if [ "x$1" = "x-s" ]; then |
| 76 | + fallback |
| 77 | +fi |
| 78 | +if [ -z "$TMPDIR" ]; then |
| 79 | + TMPDIR="/tmp" |
| 80 | +fi |
| 81 | +cd $TMPDIR || fallback |
| 82 | +rm -rf ruri_temp || true |
| 83 | +mkdir ruri_temp || fallback |
| 84 | +cd ruri_temp || fallback |
| 85 | +tty_out() { |
| 86 | + for i in $(seq 1 ${#2}); do |
| 87 | + printf "$(printf "$2" | cut -c $i)" |
| 88 | + sleep $1 |
| 89 | + done |
| 90 | + echo |
| 91 | +} |
| 92 | +ruri_logo1=" _-###-_ " |
| 93 | +ruri_logo2=" _## *** ##_ " |
| 94 | +ruri_logo3=" _## * * * ##_ " |
| 95 | +ruri_logo4=" ### * * * ### " |
| 96 | +ruri_logo5=" ## * * * ## " |
| 97 | +ruri_logo6=" #**** _ * * * _ ****# " |
| 98 | +ruri_logo7=" # * *_ **__ * * * __**_ * * # " |
| 99 | +ruri_logo8=" # * _**_ *_ * * * _* _**_ * # " |
| 100 | +ruri_logo9=" # **_* * *** * *_** # " |
| 101 | +ruri_logo10=" # ****+++**** # " |
| 102 | +ruri_logo11=" # **\`* * *** * *\`** # " |
| 103 | +ruri_logo12=" # * \`**\` *\` * * * \`* \`**\` * # " |
| 104 | +ruri_logo13=" # * *\` **\`\` * * * \`\`**\` * * # " |
| 105 | +ruri_logo14=" #**** \` * * * \` ****# " |
| 106 | +ruri_logo15=" ## * * * ## " |
| 107 | +ruri_logo16=" ### * * * ### " |
| 108 | +ruri_logo17=" \`## * * * ##\` " |
| 109 | +ruri_logo18=" \`## *** ##\` " |
| 110 | +ruri_logo19=" \`\`\`-###-\`\`\` " |
| 111 | +export S=$(stty size | awk '{print $2}') |
| 112 | +export S=$((S / 2 - 19)) |
| 113 | +init_logo() { |
| 114 | + printf "\033[?1049h" |
| 115 | + printf "\033[?25l" |
| 116 | + printf "\033[38;2;100;100;100m" |
| 117 | + clear |
| 118 | + for i in $(seq 1 19); do |
| 119 | + for j in $(seq 1 $S); do printf " "; done |
| 120 | + eval echo \"\${ruri_logo$i}\" |
| 121 | + done |
| 122 | + printf "\033[0H" |
| 123 | +} |
| 124 | +update_logo() { |
| 125 | + L=$((19 * $1 / 100)) |
| 126 | + if [ x"$L_BK" = x"" ]; then |
| 127 | + L_BK=0 |
| 128 | + fi |
| 129 | + printf "\033[38;2;254;228;208m" |
| 130 | + while [ $L -gt $L_BK ]; do |
| 131 | + for j in $(seq 1 $S); do printf " "; done |
| 132 | + L_BK=$((L_BK + 1)) |
| 133 | + eval echo \"\${ruri_logo$L_BK}\" |
| 134 | + done |
| 135 | + export L_BK=$L |
| 136 | +} |
| 137 | +init_logo |
| 138 | +tmpfile=$(mktemp) |
| 139 | +if [ ! -f "$tmpfile" ]; then |
| 140 | + fallback |
| 141 | +fi |
| 142 | +wget -q --show-progress --progress=dot "$URL" -O ruri.tar 2>&1 | stdbuf -oL grep "%" | stdbuf -oL sed 's/.* \([0-9.]*%\).*/\1/' | stdbuf -oL cut -d "%" -f 1 | while read -r percent; do |
| 143 | + update_logo $percent |
| 144 | + echo $percent >"$tmpfile" |
| 145 | +done |
| 146 | +percent=$(cat "$tmpfile") |
| 147 | +rm -f "$tmpfile" |
| 148 | +if [ "$percent" = "100" ]; then |
| 149 | + tar -xf ruri.tar |
| 150 | + rm -f ruri.tar |
| 151 | + printf "\033[38;2;254;228;208m" |
| 152 | + echo "Download complete!" |
| 153 | +else |
| 154 | + printf "\033[31m" |
| 155 | + fallback |
| 156 | +fi |
| 157 | +chmod +x ruri |
| 158 | +rm -f LICENSE |
| 159 | +printf "\033[38;2;254;228;208mruri ${CPU_ARCH} has been downloaded successfully to $(pwd)/ruri\n\n" |
| 160 | +read -p "Do you want to install ruri to $PREFIX/bin? [y/n]: " INSTALL |
| 161 | +if [ x"${INSTALL}" = "xy" ]; then |
| 162 | + sudo mv ruri $PREFIX/bin/ || mv ruri $PREFIX/bin/ |
| 163 | + if [ $? != 0 ]; then |
| 164 | + error "Failed to install ruri" |
| 165 | + fi |
| 166 | + echo "ruri has been installed to $PREFIX/bin" |
| 167 | +fi |
| 168 | +clear |
| 169 | +printf "\033[38;2;254;228;208m" |
| 170 | +printf "\n\n\n\n" |
| 171 | +tty_out 0.03 "Let's take a short tour of ruri!\n" |
| 172 | +printf "\n" |
| 173 | +sleep 1 |
| 174 | +tty_out 0.03 "First, you have a rootfs in ./rootfs" |
| 175 | +printf "\n" |
| 176 | +tty_out 0.03 "You can just run:\n" |
| 177 | +printf "\n" |
| 178 | +tty_out 0.03 "ruri ./rootfs\n" |
| 179 | +printf "\n" |
| 180 | +tty_out 0.03 "If your device does not support rootless containers, you can run with sudo:\n" |
| 181 | +printf "\n" |
| 182 | +tty_out 0.03 "sudo ruri ./rootfs\n" |
| 183 | +printf "\n" |
| 184 | +tty_out 0.03 "And, after all, umount the container with:\n" |
| 185 | +printf "\n" |
| 186 | +tty_out 0.03 "ruri -U ./rootfs\n" |
| 187 | +printf "\n" |
| 188 | +tty_out 0.03 "Don't know how to get a rootfs? Try our rurima tool!\n" |
| 189 | +tty_out 0.03 "https://github.com/rurioss/rurima\n" |
| 190 | +printf "\n" |
| 191 | +sleep 10 |
| 192 | +printf "\033[?1049l" |
| 193 | +printf "\033[?25h" |
| 194 | +printf "\033[0m" |
0 commit comments