diff --git a/.gitconfig b/.gitconfig index b687e43..e1dc271 100644 --- a/.gitconfig +++ b/.gitconfig @@ -29,8 +29,6 @@ smudge = git-lfs smudge -- %f process = git-lfs filter-process required = true -[url "git@github.com:"] - insteadOf = https://github.com/ [diff] tool = difftastic external = difft diff --git a/ansible/playbook.yaml b/ansible/playbook.yaml index 8c31f1c..c7a3069 100644 --- a/ansible/playbook.yaml +++ b/ansible/playbook.yaml @@ -5,6 +5,7 @@ roles: - init_snap - xdg_base_directory + - dot_rc - system_tools - dev_tools - fonts diff --git a/ansible/roles/dot_rc/tasks/_backup_and_symlink.yaml b/ansible/roles/dot_rc/tasks/_backup_and_symlink.yaml new file mode 100644 index 0000000..b47b220 --- /dev/null +++ b/ansible/roles/dot_rc/tasks/_backup_and_symlink.yaml @@ -0,0 +1,20 @@ +- name: backup_and_symlink + become: false + block: + - name: check item exists + stat: + path: "{{ lookup('env', 'HOME') }}/{{ item }}" + register: item_exists + changed_when: false + + - name: backup if item exists + ansible.builtin.shell: >- + mv "{{ lookup('env', 'HOME') }}/{{ item }}" "{{ lookup('env', 'HOME') }}/{{ item }}.bak" + when: item_exists.stat.exists and not item_exists.stat.islnk + + - name: create symlink + file: + src: "{{ (playbook_dir + '/../' + item) | realpath }}" + dest: "{{ lookup('env', 'HOME') }}/{{ item }}" + state: link + when: not item_exists.stat.exists diff --git a/ansible/roles/dot_rc/tasks/main.yaml b/ansible/roles/dot_rc/tasks/main.yaml new file mode 100644 index 0000000..c39f161 --- /dev/null +++ b/ansible/roles/dot_rc/tasks/main.yaml @@ -0,0 +1,10 @@ +- name: backup and symlink rc files and others + include_tasks: _backup_and_symlink.yaml + with_items: + - .bashrc + - .bash_aliases + - .profile + - .dircolors + - .config/rcs + - .gitignore + - .gitconfig diff --git a/install.sh b/install.sh deleted file mode 100755 index 9c4a32a..0000000 --- a/install.sh +++ /dev/null @@ -1,81 +0,0 @@ -#!/bin/bash -e - -# /home/ -home_dir=`realpath ~` - -cur_dir=`pwd` - -function create_symlink_f() { - file=$1 - dst_path=$2 - dst="${home_dir}/${dst_path}" - src="${cur_dir}/${file}" - if [ ! -L $dst ]; then - echo "symlink $dst does not exists." - if [ -f $dst ]; then - echo "file $dst exists." - read -p "Remove and backup file $dst and create a symlink to $src? [Yn]: " yn - else - read -p "Create a symlink to $src? [Yn]: " yn - fi - case $yn in - "" | [Yy*] ) - if [ -f $dst ]; then - cp $dst "${dst}.old" - rm -rf "$dst" - fi - ln -sf "${src}" "${dst}" - printf "Created symlink to ${dst}\n" - ;; - * ) - echo "Skip." - ;; - esac - else - printf "symlink ${src} => ${dst} already exists, skipping.\n" - fi -} - -function create_symlink_d() { - dir=$1 - dst_dir=$2 - dst="${home_dir}/${dst_dir}" - src="${cur_dir}/${dir}" - if [ ! -L $dst ]; then - echo "symlink $dst does not exists." - if [ -d $dst ]; then - echo "directory $dst exists." - read -p "Remove and backup directory $dst and create a symlink to $src? [Yn]: " yn - else - read -p "Create a symlink to $src? [Yn]: " yn - fi - case $yn in - "" | [Yy*] ) - if [ -d $dst ]; then - cp -r $dst "${dst}.old" - rm -rf "$dst" - fi - ln -s "${src}" "${dst}" - printf "Created symlink to ${dst}\n" - ;; - * ) - echo "Skip." - ;; - esac - else - printf "symlink ${src} => ${dst} already exists, skipping.\n" - fi -} - -# system, bash -create_symlink_f ".bashrc" ".bashrc" -create_symlink_f ".bash_aliases" ".bash_aliases" -create_symlink_f ".profile" ".profile" -create_symlink_f ".dircolors" ".dircolors" - -# .rc files -create_symlink_d ".config/rcs" ".config/rcs" - -# git -create_symlink_f ".gitignore" ".gitignore" -create_symlink_f ".gitconfig" ".gitconfig" diff --git a/uninstall.sh b/uninstall.sh deleted file mode 100755 index 0094cd4..0000000 --- a/uninstall.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash -e - -function unlink_symlink() { - path=$1 - if [ -L $path ]; then - local question="Are you sure to unlink $path ? [Yn]: " - read -p "$question" yn - case $yn in - [Yy*] ) - unlink $path - printf "Unlinked $path\n\n" - ;; - [Nn*] ) - printf "Skip\n\n" - ;; - * ) - printf "Please enter yes or no\n\n" - ;; - esac - fi -} - -home_path=`realpath ~` - -unlink_symlink "${home_path}/.bashrc" -unlink_symlink "${home_path}/.bash_aliases" -unlink_symlink "${home_path}/.profile" -unlink_symlink "${home_path}/.dircolors" - -unlink_symlink "${home_path}/.config/fish" - -unlink_symlink "${home_path}/.gitignore" -unlink_symlink "${home_path}/.gitconfig" - -unlink_symlink "${home_path}/.emacs" -unlink_symlink "${home_path}/.emacs.d" - -unlink_symlink "${home_path}/.tmux.conf" -unlink_symlink "${home_path}/.config/tmux"