From d202ddeeb0a3afa0a114686832b6c10abe059156 Mon Sep 17 00:00:00 2001 From: Muha Aliss Date: Tue, 24 Dec 2024 19:36:07 +0300 Subject: [PATCH] install script changed --- install.sh | 181 +++++++++++++++++++++++-------------------------- install_old.sh | 104 ++++++++++++++++++++++++++++ 2 files changed, 190 insertions(+), 95 deletions(-) create mode 100755 install_old.sh diff --git a/install.sh b/install.sh index 058611d..910844e 100755 --- a/install.sh +++ b/install.sh @@ -1,104 +1,95 @@ #!/bin/bash -# Renk tanımları -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[0;33m' -CYAN='\033[0;36m' -BOLD='\033[1m' -NC='\033[0m' # No Color +# 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" -# Varsayılan ayar dosyaları dizini -config_directory=$(pwd) +# Kullanıcı adı ve betiğin bulunduğu dizini değişkenlerde sakla +USER_NAME=$(whoami) +SCRIPT_DIR=$(dirname "$0") -# Ayar dosyaları betik ile aynı dizinde değilse kullanıcıdan ayar dizinini iste -if [ ! -d "$config_directory/emacs.d" ] || [ ! -d "$config_directory/nano" ] || [ ! -f "$config_directory/nanorc" ] || [ ! -f "$config_directory/bash_aliases" ]; then - echo -e "${YELLOW}Ayar dosyalarının bulunduğu dizin (örn. ~/Documents/mydotfiles/): ${CYAN}${BOLD}$config_directory${NC}" - read -p "" config_directory -fi +# Kontrol edilecek klasör ve dosyalar +DIRS=("emacs.d" "nano") +FILES=("bash_aliases" "nanorc") -# Ayar dosyaları ve hedef konumları tanımla -declare -A config_files=( - ["$config_directory/emacs.d"]="$HOME/.emacs.d" - ["$config_directory/nano"]="$HOME/.nano" - ["$config_directory/nanorc"]="$HOME/.nanorc" - ["$config_directory/bash_aliases"]="$HOME/.bash_aliases" -) +# Eksik olan dosya veya klasörleri tutmak için bir liste +missings=() -# Genel ayar yükleme fonksiyonu -setup_configuration() { - local source_path=$1 - local target_path=$2 - local source_config_name=$(basename "$source_path") - - if [ -e "$target_path" ]; then - echo -e "${YELLOW}${BOLD}$target_path${NC} zaten var." - echo -e "Mevcut ayarları koruyarak ekle ${CYAN}(e)${NC}, üzerine yaz ${RED}(y)${NC}, olduğu gibi bırak ${GREEN}(b)${NC}:" - read -p "" user_choice - case $user_choice in - [Ee]* ) - if [ -d "$source_path" ]; then - cp -r "$source_path"/* "$target_path" - echo -e "${BOLD}$source_config_name${NC} içeriği ${GREEN}${BOLD}${target_path}${NC} içine eklendi." - else - cat "$source_path" >> "$target_path" - echo -e "${BOLD}$source_config_name${NC} içeriği ${GREEN}${BOLD}${target_path}${NC} dosyasına eklendi." - fi - - # .bash_aliases'i .bashrc'ye ekle - if [[ "$target_path" == "$HOME/.bash_aliases" ]]; then - bashrc_path="$HOME/.bashrc" - if ! grep -q "source $target_path" "$bashrc_path"; then - echo "source $target_path" >> "$bashrc_path" - echo -e "${BOLD}$(basename "$target_path")${NC} dosyası ${GREEN}${BOLD}$(basename "$bashrc_path")${NC} dosyasına eklendi." - else - echo -e "${YELLOW}${BOLD}$(basename "$target_path")${NC} zaten ${BOLD}$(basename "$bashrc_path")${NC} dosyasında kaynak olarak gösteriliyor." - fi - fi - ;; - [Yy]* ) - backup_path="${target_path}_backup_$(date +%Y%m%d_%H%M%S)" - mv "$target_path" "$backup_path" - echo -e "${YELLOW}${BOLD}$target_path${NC} yedeklendi: ${BOLD}$backup_path${NC}" - cp -r "$source_path" "$target_path" - echo -e "${BOLD}$source_config_name${NC} içeriği ${GREEN}${BOLD}${target_path}${NC} dosyasına yazıldı." - - # .bash_aliases'i .bashrc'ye ekle - if [[ "$target_path" == "$HOME/.bash_aliases" ]]; then - bashrc_path="$HOME/.bashrc" - if ! grep -q "source $target_path" "$bashrc_path"; then - echo "source $target_path" >> "$bashrc_path" - echo -e "${BOLD}$(basename "$target_path")${NC} dosyası ${GREEN}${BOLD}$(basename "$bashrc_path")${NC} dosyasına eklendi." - else - echo -e "${YELLOW}${BOLD}$(basename "$target_path")${NC} zaten ${BOLD}$(basename "$bashrc_path")${NC} dosyasında kaynak olarak gösteriliyor." - fi - fi - ;; - [Bb]* ) - echo -e "${YELLOW}${BOLD}$target_path${NC} olduğu gibi bırakıldı." - ;; - * ) echo -e "${RED}Geçersiz seçim. İşlem atlandı.${NC}" ;; - esac - else - cp -r "$source_path" "$target_path" - echo -e "${BOLD}$source_config_name${NC} içeriği ${GREEN}${BOLD}${target_path}${NC} olarak yüklendi." - - # .bash_aliases'i .bashrc'ye ekle - if [[ "$target_path" == "$HOME/.bash_aliases" ]]; then - bashrc_path="$HOME/.bashrc" - if ! grep -q "source $target_path" "$bashrc_path"; then - echo "source $target_path" >> "$bashrc_path" - echo -e "${BOLD}$(basename "$target_path")${NC} dosyası ${GREEN}${BOLD}$(basename "$bashrc_path")${NC} dosyasına eklendi." - else - echo -e "${YELLOW}${BOLD}$(basename "$target_path")${NC} zaten ${BOLD}$(basename "$bashrc_path")${NC} dosyasında kaynak olarak gösteriliyor." - fi - fi +# Klasör ve dosya kontrolleri +for item in "${DIRS[@]}" "${FILES[@]}"; do + if [ ! -e "$SCRIPT_DIR/$item" ]; then + missings+=("$item") fi -} - -# Tüm ayarları yükle -for source_path in "${!config_files[@]}"; do - setup_configuration "$source_path" "${config_files[$source_path]}" done -echo -e "${GREEN}Tüm ayarlar tamamlandı!${NC}" +# 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}" diff --git a/install_old.sh b/install_old.sh new file mode 100755 index 0000000..058611d --- /dev/null +++ b/install_old.sh @@ -0,0 +1,104 @@ +#!/bin/bash + +# Renk tanımları +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +CYAN='\033[0;36m' +BOLD='\033[1m' +NC='\033[0m' # No Color + +# Varsayılan ayar dosyaları dizini +config_directory=$(pwd) + +# Ayar dosyaları betik ile aynı dizinde değilse kullanıcıdan ayar dizinini iste +if [ ! -d "$config_directory/emacs.d" ] || [ ! -d "$config_directory/nano" ] || [ ! -f "$config_directory/nanorc" ] || [ ! -f "$config_directory/bash_aliases" ]; then + echo -e "${YELLOW}Ayar dosyalarının bulunduğu dizin (örn. ~/Documents/mydotfiles/): ${CYAN}${BOLD}$config_directory${NC}" + read -p "" config_directory +fi + +# Ayar dosyaları ve hedef konumları tanımla +declare -A config_files=( + ["$config_directory/emacs.d"]="$HOME/.emacs.d" + ["$config_directory/nano"]="$HOME/.nano" + ["$config_directory/nanorc"]="$HOME/.nanorc" + ["$config_directory/bash_aliases"]="$HOME/.bash_aliases" +) + +# Genel ayar yükleme fonksiyonu +setup_configuration() { + local source_path=$1 + local target_path=$2 + local source_config_name=$(basename "$source_path") + + if [ -e "$target_path" ]; then + echo -e "${YELLOW}${BOLD}$target_path${NC} zaten var." + echo -e "Mevcut ayarları koruyarak ekle ${CYAN}(e)${NC}, üzerine yaz ${RED}(y)${NC}, olduğu gibi bırak ${GREEN}(b)${NC}:" + read -p "" user_choice + case $user_choice in + [Ee]* ) + if [ -d "$source_path" ]; then + cp -r "$source_path"/* "$target_path" + echo -e "${BOLD}$source_config_name${NC} içeriği ${GREEN}${BOLD}${target_path}${NC} içine eklendi." + else + cat "$source_path" >> "$target_path" + echo -e "${BOLD}$source_config_name${NC} içeriği ${GREEN}${BOLD}${target_path}${NC} dosyasına eklendi." + fi + + # .bash_aliases'i .bashrc'ye ekle + if [[ "$target_path" == "$HOME/.bash_aliases" ]]; then + bashrc_path="$HOME/.bashrc" + if ! grep -q "source $target_path" "$bashrc_path"; then + echo "source $target_path" >> "$bashrc_path" + echo -e "${BOLD}$(basename "$target_path")${NC} dosyası ${GREEN}${BOLD}$(basename "$bashrc_path")${NC} dosyasına eklendi." + else + echo -e "${YELLOW}${BOLD}$(basename "$target_path")${NC} zaten ${BOLD}$(basename "$bashrc_path")${NC} dosyasında kaynak olarak gösteriliyor." + fi + fi + ;; + [Yy]* ) + backup_path="${target_path}_backup_$(date +%Y%m%d_%H%M%S)" + mv "$target_path" "$backup_path" + echo -e "${YELLOW}${BOLD}$target_path${NC} yedeklendi: ${BOLD}$backup_path${NC}" + cp -r "$source_path" "$target_path" + echo -e "${BOLD}$source_config_name${NC} içeriği ${GREEN}${BOLD}${target_path}${NC} dosyasına yazıldı." + + # .bash_aliases'i .bashrc'ye ekle + if [[ "$target_path" == "$HOME/.bash_aliases" ]]; then + bashrc_path="$HOME/.bashrc" + if ! grep -q "source $target_path" "$bashrc_path"; then + echo "source $target_path" >> "$bashrc_path" + echo -e "${BOLD}$(basename "$target_path")${NC} dosyası ${GREEN}${BOLD}$(basename "$bashrc_path")${NC} dosyasına eklendi." + else + echo -e "${YELLOW}${BOLD}$(basename "$target_path")${NC} zaten ${BOLD}$(basename "$bashrc_path")${NC} dosyasında kaynak olarak gösteriliyor." + fi + fi + ;; + [Bb]* ) + echo -e "${YELLOW}${BOLD}$target_path${NC} olduğu gibi bırakıldı." + ;; + * ) echo -e "${RED}Geçersiz seçim. İşlem atlandı.${NC}" ;; + esac + else + cp -r "$source_path" "$target_path" + echo -e "${BOLD}$source_config_name${NC} içeriği ${GREEN}${BOLD}${target_path}${NC} olarak yüklendi." + + # .bash_aliases'i .bashrc'ye ekle + if [[ "$target_path" == "$HOME/.bash_aliases" ]]; then + bashrc_path="$HOME/.bashrc" + if ! grep -q "source $target_path" "$bashrc_path"; then + echo "source $target_path" >> "$bashrc_path" + echo -e "${BOLD}$(basename "$target_path")${NC} dosyası ${GREEN}${BOLD}$(basename "$bashrc_path")${NC} dosyasına eklendi." + else + echo -e "${YELLOW}${BOLD}$(basename "$target_path")${NC} zaten ${BOLD}$(basename "$bashrc_path")${NC} dosyasında kaynak olarak gösteriliyor." + fi + fi + fi +} + +# Tüm ayarları yükle +for source_path in "${!config_files[@]}"; do + setup_configuration "$source_path" "${config_files[$source_path]}" +done + +echo -e "${GREEN}Tüm ayarlar tamamlandı!${NC}"