Download baslat.sh from SevdanurGenc/Text-to-SQL: direct link, hf CLI and curl.
- Browser
- Download file 8.54 kB
-
https://huggingface.co/SevdanurGenc/Text-to-SQL/resolve/main/baslat.sh
- Command line
-
hf download hf://SevdanurGenc/Text-to-SQL/baslat.sh
-
curl -L -o baslat.sh https://huggingface.co/SevdanurGenc/Text-to-SQL/resolve/main/baslat.sh
8.54 kB
| # Tablo2SQL-TR başlatıcı — Linux ve macOS | |
| # bash baslat.sh : denetle, eksikleri kur, arayüzü aç | |
| # bash baslat.sh --kontrol : yalnızca denetle | |
| # bash baslat.sh --kisayol : masaüstü kısayolu oluştur | |
| # bash baslat.sh --sifirla : sanal ortamı (.venv) silip yeniden kur | |
| set -u | |
| # ---- proje klasörüne geç (sembolik bağlantıları çöz) | |
| SRC="${BASH_SOURCE[0]}" | |
| while [ -L "$SRC" ]; do | |
| DIR="$(cd -P "$(dirname "$SRC")" && pwd)"; SRC="$(readlink "$SRC")" | |
| [[ "$SRC" != /* ]] && SRC="$DIR/$SRC" | |
| done | |
| ROOT="$(cd -P "$(dirname "$SRC")" && pwd)" | |
| cd "$ROOT" || exit 1 | |
| OS="$(uname -s)" | |
| MIN_MINOR=10 | |
| PY_VER_WANTED="3.12" | |
| VENV="$ROOT/.venv" | |
| VPY="$VENV/bin/python" | |
| if [ -t 1 ]; then B=$'\e[1m'; G=$'\e[32m'; Y=$'\e[33m'; R=$'\e[31m'; C=$'\e[36m'; N=$'\e[0m'; else B=""; G=""; Y=""; R=""; C=""; N=""; fi | |
| ok() { echo " ${G}[TAMAM]${N} $*"; } | |
| warn() { echo " ${Y}[UYARI]${N} $*"; } | |
| err() { echo " ${R}[HATA]${N} $*"; } | |
| info() { echo " ${C}[BİLGİ]${N} $*"; } | |
| ask() { # ask "soru" -> 0 evet / 1 hayır (etkileşimsizse hayır) | |
| [ -t 0 ] || return 1 | |
| local a; read -r -p " $1 [E/h] " a | |
| case "${a:-e}" in [eEyY]*) return 0 ;; *) return 1 ;; esac | |
| } | |
| pause_on_error() { | |
| local code=$1 | |
| if [ "$code" -ne 0 ] && [ -t 0 ]; then | |
| echo; read -r -p " Bir sorun oluştu. Pencereyi kapatmak için Enter'a basın… " _ | |
| fi | |
| exit "$code" | |
| } | |
| echo | |
| echo "${B} ═══ Tablo2SQL-TR başlatıcı (${OS}) ═══${N}" | |
| # ---- argümanlar | |
| RESET=0; ARGS=() | |
| for a in "$@"; do | |
| case "$a" in | |
| --sifirla) RESET=1 ;; | |
| *) ARGS+=("$a") ;; | |
| esac | |
| done | |
| # ======================================================================= Python bul | |
| py_ok() { # $1 = yorumlayıcı; uygun sürümse 0 | |
| "$1" -c "import sys; sys.exit(0 if sys.version_info >= (3, $MIN_MINOR) else 1)" >/dev/null 2>&1 | |
| } | |
| find_python() { | |
| local cands=() | |
| cands+=(python3.13 python3.12 python3.11 python3.10) | |
| if [ "$OS" = "Darwin" ]; then | |
| cands+=(/opt/homebrew/bin/python3 /usr/local/bin/python3) | |
| for f in /Library/Frameworks/Python.framework/Versions/3.*/bin/python3; do [ -x "$f" ] && cands+=("$f"); done | |
| # /usr/bin/python3 Xcode araçları yoksa kurulum penceresi açar; yalnızca araçlar kuruluysa dene | |
| xcode-select -p >/dev/null 2>&1 && cands+=(/usr/bin/python3) | |
| else | |
| cands+=(python3) | |
| fi | |
| cands+=("$HOME/.local/bin/python3.12") | |
| for p in "${cands[@]}"; do | |
| if command -v "$p" >/dev/null 2>&1 || [ -x "$p" ]; then | |
| local full; full="$(command -v "$p" 2>/dev/null || echo "$p")" | |
| if py_ok "$full"; then echo "$full"; return 0; fi | |
| fi | |
| done | |
| # uv ile kurulmuş bağımsız Python | |
| if command -v uv >/dev/null 2>&1 || [ -x "$HOME/.local/bin/uv" ]; then | |
| local UVB; UVB="$(command -v uv 2>/dev/null || echo "$HOME/.local/bin/uv")" | |
| local up; up="$("$UVB" python find "$PY_VER_WANTED" 2>/dev/null)" | |
| [ -n "$up" ] && py_ok "$up" && { echo "$up"; return 0; } | |
| fi | |
| return 1 | |
| } | |
| install_with_uv() { | |
| info "uv (yönetici izni gerektirmeyen Python yöneticisi) ile Python $PY_VER_WANTED kuruluyor…" | |
| if ! command -v uv >/dev/null 2>&1 && [ ! -x "$HOME/.local/bin/uv" ]; then | |
| if command -v curl >/dev/null 2>&1; then curl -LsSf https://astral.sh/uv/install.sh | sh | |
| elif command -v wget >/dev/null 2>&1; then wget -qO- https://astral.sh/uv/install.sh | sh | |
| else err "curl veya wget bulunamadı."; return 1; fi | |
| fi | |
| local UVB; UVB="$(command -v uv 2>/dev/null || echo "$HOME/.local/bin/uv")" | |
| "$UVB" python install "$PY_VER_WANTED" | |
| } | |
| install_python() { | |
| warn "Python 3.$MIN_MINOR veya daha yenisi bulunamadı." | |
| if [ "$OS" = "Darwin" ]; then | |
| if command -v brew >/dev/null 2>&1; then | |
| if ask "Homebrew ile python@$PY_VER_WANTED kurulsun mu?"; then brew install "python@$PY_VER_WANTED" && return 0; fi | |
| fi | |
| if ask "Yönetici izni olmadan uv ile Python $PY_VER_WANTED kurulsun mu? (önerilir)"; then install_with_uv && return 0; fi | |
| if ask "Resmî python.org kurulum paketi indirilip açılsın mı?"; then | |
| local PKG="/tmp/python-3.12.10-macos11.pkg" | |
| curl -fL -o "$PKG" "https://www.python.org/ftp/python/3.12.10/python-3.12.10-macos11.pkg" && open "$PKG" | |
| info "Kurulum sihirbazını tamamladıktan sonra bu başlatıcıyı yeniden çalıştırın." | |
| pause_on_error 1 | |
| fi | |
| err "Python kurulmadı. Seçenekler:" | |
| echo " • https://www.python.org/downloads/macos/ adresinden Python $PY_VER_WANTED" | |
| echo " • Homebrew: /bin/bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\" && brew install python@$PY_VER_WANTED" | |
| return 1 | |
| fi | |
| # Linux: dağıtım paket yöneticisi | |
| local cmd="" | |
| if command -v apt-get >/dev/null 2>&1; then cmd="sudo apt-get update && sudo apt-get install -y python3 python3-venv python3-pip" | |
| elif command -v dnf >/dev/null 2>&1; then cmd="sudo dnf install -y python3 python3-pip" | |
| elif command -v pacman >/dev/null 2>&1; then cmd="sudo pacman -S --needed --noconfirm python python-pip" | |
| elif command -v zypper >/dev/null 2>&1; then cmd="sudo zypper install -y python312 python312-pip" | |
| elif command -v apk >/dev/null 2>&1; then cmd="sudo apk add python3 py3-pip" | |
| fi | |
| if [ -n "$cmd" ] && ask "Sistem paket yöneticisiyle kurulsun mu? ($cmd)"; then | |
| bash -c "$cmd" && find_python >/dev/null && return 0 | |
| warn "Dağıtımın Python sürümü yetersiz veya kurulum başarısız." | |
| fi | |
| if ask "Yönetici izni olmadan uv ile Python $PY_VER_WANTED kurulsun mu? (önerilir)"; then install_with_uv && return 0; fi | |
| err "Python kurulmadı. Elle kurulum: dağıtımınızın paket yöneticisi ile python3 (≥3.$MIN_MINOR), python3-venv ve" | |
| echo " python3-pip paketlerini kurun ya da: curl -LsSf https://astral.sh/uv/install.sh | sh && uv python install $PY_VER_WANTED" | |
| return 1 | |
| } | |
| # ======================================================================= ana akış | |
| echo | |
| echo "${B}0) Ön koşullar${N}" | |
| PY="$(find_python)" | |
| if [ -z "$PY" ]; then | |
| install_python || pause_on_error 1 | |
| hash -r | |
| PY="$(find_python)" | |
| [ -z "$PY" ] && { err "Kurulumdan sonra Python bulunamadı; terminali kapatıp yeniden açın."; pause_on_error 1; } | |
| fi | |
| ok "Python: $PY ($("$PY" -c 'import platform; print(platform.python_version())'))" | |
| # yalnızca kısayol isteniyorsa sanal ortam gerekmez | |
| if [ "${ARGS[0]:-}" = "--kisayol" ]; then | |
| "$PY" "$ROOT/scripts/kisayol.py"; pause_on_error $? | |
| fi | |
| # ---- sanal ortam | |
| if [ "$RESET" -eq 1 ] && [ -d "$VENV" ]; then info "Sanal ortam siliniyor…"; rm -rf "$VENV"; fi | |
| if [ -d "$VENV" ] && ! "$VPY" -c "import sys" >/dev/null 2>&1; then | |
| warn "Mevcut .venv bozuk (klasör taşınmış veya Python güncellenmiş olabilir); yeniden oluşturuluyor." | |
| rm -rf "$VENV" | |
| fi | |
| if [ ! -d "$VENV" ]; then | |
| info "Sanal ortam oluşturuluyor (.venv)…" | |
| if ! "$PY" -m venv "$VENV" 2>/tmp/t2s_venv_err.txt; then | |
| rm -rf "$VENV" | |
| warn "venv modülü eksik: $(tail -1 /tmp/t2s_venv_err.txt)" | |
| MINOR="$("$PY" -c 'import sys; print(f"{sys.version_info[0]}.{sys.version_info[1]}")')" | |
| if command -v apt-get >/dev/null 2>&1 && ask "python$MINOR-venv paketi kurulsun mu? (sudo)"; then | |
| sudo apt-get install -y "python$MINOR-venv" python3-venv | |
| "$PY" -m venv "$VENV" || { rm -rf "$VENV"; } | |
| fi | |
| if [ ! -d "$VENV" ] && { command -v uv >/dev/null 2>&1 || [ -x "$HOME/.local/bin/uv" ]; }; then | |
| UVB="$(command -v uv 2>/dev/null || echo "$HOME/.local/bin/uv")" | |
| "$UVB" venv --seed --python "$PY" "$VENV" | |
| fi | |
| [ -d "$VENV" ] || { err "Sanal ortam oluşturulamadı. Debian/Ubuntu: sudo apt install python3-venv"; pause_on_error 1; } | |
| fi | |
| ok "Sanal ortam hazır." | |
| else | |
| ok "Sanal ortam mevcut." | |
| fi | |
| # ---- paketler (requirements.txt değiştiyse yeniden kur) | |
| HASH_FILE="$VENV/.req_hash" | |
| NEW_HASH="$("$VPY" -c "import hashlib; print(hashlib.sha256(open('requirements.txt','rb').read()).hexdigest())")" | |
| if [ ! -f "$HASH_FILE" ] || [ "$(cat "$HASH_FILE")" != "$NEW_HASH" ]; then | |
| info "Python paketleri kuruluyor (ilk kurulum birkaç dakika sürebilir)…" | |
| "$VPY" -m pip install --disable-pip-version-check -q --upgrade pip >/dev/null 2>&1 | |
| if "$VPY" -m pip install --disable-pip-version-check -r requirements.txt; then | |
| echo "$NEW_HASH" > "$HASH_FILE"; ok "Paketler kuruldu." | |
| else | |
| err "Paket kurulumu başarısız. İnternet bağlantısını kontrol edin; sorun sürerse: bash baslat.sh --sifirla" | |
| pause_on_error 1 | |
| fi | |
| fi | |
| # ---- ortak başlatıcı | |
| "$VPY" "$ROOT/scripts/baslat.py" "${ARGS[@]+"${ARGS[@]}"}" | |
| pause_on_error $? | |