mydotfiles/install.sh
2024-12-24 19:36:07 +03:00

95 lines
3.1 KiB
Bash
Executable file
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# Renk ve yazı stilleri
NC="\033[0m"
BOLD="\033[1m"
RED="\033[1;31m"
BLUE="\033[1;34m"
GREEN="\033[1;32m"
YELLOW="\033[1;33m"
# Kullanıcı adı ve betiğin bulunduğu dizini değişkenlerde sakla
USER_NAME=$(whoami)
SCRIPT_DIR=$(dirname "$0")
# Kontrol edilecek klasör ve dosyalar
DIRS=("emacs.d" "nano")
FILES=("bash_aliases" "nanorc")
# Eksik olan dosya veya klasörleri tutmak için bir liste
missings=()
# Klasör ve dosya kontrolleri
for item in "${DIRS[@]}" "${FILES[@]}"; do
if [ ! -e "$SCRIPT_DIR/$item" ]; then
missings+=("$item")
fi
done
# Eksik öğeleri kullanıcıdan talep et
for missing in "${missings[@]}"; do
echo -e "${YELLOW}${BOLD}${missing}${NC} bulunamadı."
read -rp "Lütfen eksik dosyanın tam yolunu belirt: " missing_path
if [ -e "$missing_path" ]; then
cp -r "$missing_path" "$SCRIPT_DIR/"
else
echo -e "${RED}${BOLD}${missing_path}${NC} geçersiz bir yol. Betiği yeniden çalıştırmayı dene."
exit 1
fi
done
# Dosya ve klasörleri kullanıcı dizinine kopyala veya mevcut ayarları kontrol et
for dir in "${DIRS[@]}"; do
target_dir="$HOME/.${dir%/}"
if [ -d "$target_dir" ]; then
echo -e "${BLUE}${BOLD}${target_dir}${NC} ${YELLOW}${BOLD}zaten mevcut${NC}."
read -rp "$(echo -e "Mevcut ayarları koru ${YELLOW}${BOLD}(g)${NC} / Üzerine yaz ${RED}${BOLD}(y)${NC}: ")" choice
case "$choice" in
g|G)
echo -e "${GREEN}${BOLD}${target_dir}${NC} atlandı.\n"
;;
y|Y)
cp -r "$SCRIPT_DIR/$dir" "$target_dir"
echo -e "${GREEN}${BOLD}${target_dir}${NC} üzerine yazıldı."
;;
*)
echo -e "${RED}${BOLD}Geçersiz seçim.${NC} İşlem iptal edildi."
exit 1
;;
esac
elif [ -d "$SCRIPT_DIR/$dir" ]; then
cp -r "$SCRIPT_DIR/$dir" "$target_dir"
fi
done
for file in "${FILES[@]}"; do
target_file="$HOME/.${file}"
if [ -f "$target_file" ]; then
echo -e "${BLUE}${BOLD}${target_file}${NC} ${YELLOW}${BOLD}zaten mevcut${NC}."
read -rp "$(echo -e "Mevcut ayarları koru ${YELLOW}${BOLD}(g)${NC} / Üzerine yaz ${RED}${BOLD}(y)${NC}: ")" choice
case "$choice" in
g|G)
echo -e "${GREEN}${BOLD}${target_file}${NC} atlandı.\n"
;;
y|Y)
cp "$SCRIPT_DIR/$file" "$target_file"
echo -e "${GREEN}${BOLD}${target_file}${NC} üzerine yazıldı."
;;
*)
echo -e "${RED}${BOLD}Geçersiz seçim.${NC} İşlem iptal edildi."
exit 1
;;
esac
elif [ -f "$SCRIPT_DIR/$file" ]; then
cp "$SCRIPT_DIR/$file" "$target_file"
fi
done
# .bashrc dosyasına bash_aliases dosyasını kaynak olarak ekle
BASHRC="$HOME/.bashrc"
ALIAS_SOURCE="source ~/.bash_aliases"
if ! grep -q "$ALIAS_SOURCE" "$BASHRC"; then
echo "$ALIAS_SOURCE" >> "$BASHRC"
fi
echo -e "${GREEN}${BOLD}İşlem tamamlandı.${NC} Değişikliklerin etkili olması için terminali ${YELLOW}yeniden başlatın.${NC}"