From 404e60caa500606d324a4021fb42321d118a5223 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Sun, 11 Oct 2015 11:57:25 -0400 Subject: Rename setup script. --- bin/kj-setup.sh | 94 ++++++++++++++++++++++++++++++++++++++++++ bin/kj-sync-keys.sh | 56 +++++++++++++++++++++++++ bin/kj_sync_authorized_keys.sh | 56 ------------------------- bin/setup.sh | 94 ------------------------------------------ 4 files changed, 150 insertions(+), 150 deletions(-) create mode 100755 bin/kj-setup.sh create mode 100755 bin/kj-sync-keys.sh delete mode 100755 bin/kj_sync_authorized_keys.sh delete mode 100755 bin/setup.sh diff --git a/bin/kj-setup.sh b/bin/kj-setup.sh new file mode 100755 index 0000000..5058bb5 --- /dev/null +++ b/bin/kj-setup.sh @@ -0,0 +1,94 @@ +#!/bin/bash + +red='\e[0;31m' +orange='\e[0;33m' +green='\e[0;32m' +none='\e[0m' + +cd +# Check that things are in their right places. +if [[ ! -f dotfiles/bin/kj-setup.sh ]]; then + printf "${red}[FAIL]${none} expected to find myself\n" + exit 1 +fi + +required_commands=(git basename) +for command in ${required_commands[@]}; do + if ! which "${command}" >/dev/null; then + printf "${red}[FAIL]${none} ${command} not installed\n" + exit 1 + fi +done + +cd ~/dotfiles +git submodule update --init --recursive +git submodule foreach pull + +cd +# Creates a symlink with target $1 at location $2. +# Does nothing and prints an error message if $2 exists and is not a symlink. +create_symlink() { + if [[ -e "$2" && ! -h "$2" ]]; then + printf "${orange}[SKIPPED]${none} '$2' exists and is not a symlink.\n" + return + else + if ln -sf "$1" "$2"; then + printf "${green}[OK]${none} '$2' → '$1'\n" + else + printf "${red}[WARNING]${none} could not create '$2'\n" + fi + fi + if ! diff "$2" "$(dirname $2)/$1"; then + printf "${red}[WARNING]${none} diffs in $2\n" + fi +} + +create_symlink dotfiles/gitconfig .gitconfig +create_symlink dotfiles/taskrc .taskrc +create_symlink dotfiles/tmux.conf .tmux.conf +create_symlink dotfiles/spacemacs .spacemacs +create_symlink /dev/null .vimrc.local + +mkdir -p bin +for binary in dotfiles/bin/*; do + binary=$(basename "${binary}") + create_symlink "../dotfiles/bin/${binary}" "bin/${binary}" +done + +if [[ "${SHELL}" = *zsh* ]]; then + create_symlink dotfiles/zshrc .zshrc +else + printf "${orange}[SKIPPED]${none} shell is not zsh :-(.\n" +fi + +mkdir -p .ssh +create_symlink ../dotfiles/ssh/config .ssh/config + +if which i3 >/dev/null; then + mkdir -p .i3 + create_symlink ../dotfiles/i3/config .i3/config + create_symlink dotfiles/i3status.conf .i3status.conf + create_symlink dotfiles/i3blocks.conf .i3blocks.conf +else + printf "${orange}[SKIPPED]${none} i3 not installed.\n" +fi + +create_symlink dotfiles/vimrc .vimrc +if [[ -e .vim/bundle/Vundle.vim ]]; then + printf "${orange}[SKIPPED]${none} Vundle.vim already installed\n" +else + success=1 + mkdir -p .vim/bundle + git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim \ + || success=0 +fi +vim +PluginInstall +qall || success=0 +if [[ "$success" == "1" ]]; then + printf "${green}[OK]${none} installed vim plugins\n" +else + printf "${red}[WARNING]${none} failed to install vim plugins\n" +fi + +if which emacs >/dev/null && [[ ! -d .emacs.d ]]; then + git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d +fi diff --git a/bin/kj-sync-keys.sh b/bin/kj-sync-keys.sh new file mode 100755 index 0000000..b8be72d --- /dev/null +++ b/bin/kj-sync-keys.sh @@ -0,0 +1,56 @@ +#!/bin/bash +# +# This script syncs authorized keys (found in the $authorized_keys_file below) +# to a list of remote hosts. It does not touch existing keys unless overwrite +# is set to true, but creates a special section containing the keys. + +declare -r begin_marker="### BEGIN MANAGED_BY_KJ_SYNC_AUTHORIZED_KEYS.SH ###" +declare -r end_marker="### END MANAGED_BY_KJ_SYNC_AUTHORIZED_KEYS.SH ###" +# If overwrite=true, the entire authorized_keys file is overwritten. +declare -r overwrite=false +declare -r tmpdir=$(mktemp -d /tmp/kj_sync_authorized_keys.XXXXX) + +targets=( + root@orbekk.osl.trygveandre.net + tesuji.6.orbekk.com + login.6.orbekk.com + minecraft.6.orbekk.com + login.pvv.ntnu.no + aji.orbekk.com + moyo.orbekk.com + pi@photobox.6.orbekk.com +) +authorized_keys_file=$HOME/dotfiles/authorized_keys +if [[ ! -f "${authorized_keys_file}" ]]; then + echo "could not find authorized_keys_file: ${authorized_keys_file}" + exit 1 +fi + +add_keys_to_file() { + local filename="$1" + awk \ + "/$begin_marker/"' { exit 0 } { print }' \ + ${filename} > ${filename}.header + awk \ + "/$end_marker/"' { should_output=1 } should_output { print }' \ + ${filename} > ${filename}.footer + + cat "${filename}.header" > ${filename} + echo "${begin_marker}" >> ${filename} + echo "# WARNING: ANY CHANGES WILL BE OVERWRITTEN" >> ${filename} + cat "$authorized_keys_file" >> ${filename} + echo "${end_marker}" >> ${filename} + cat "${filename}.footer" >> ${filename} +} + +for target in ${targets[@]}; do + echo "syncing $target" + tmp="${tmpdir}/${target}" + touch ${tmp} + if [[ $overwrite != true ]]; then + ssh ${target} 'cat .ssh/authorized_keys || echo -n' > ${tmp} + fi + add_keys_to_file "${tmp}" + ssh ${target} 'mkdir -p .ssh' + cat "${tmp}" | ssh ${target} 'cat > .ssh/authorized_keys.tmp && mv .ssh/authorized_keys{.tmp,}' +done diff --git a/bin/kj_sync_authorized_keys.sh b/bin/kj_sync_authorized_keys.sh deleted file mode 100755 index b8be72d..0000000 --- a/bin/kj_sync_authorized_keys.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/bash -# -# This script syncs authorized keys (found in the $authorized_keys_file below) -# to a list of remote hosts. It does not touch existing keys unless overwrite -# is set to true, but creates a special section containing the keys. - -declare -r begin_marker="### BEGIN MANAGED_BY_KJ_SYNC_AUTHORIZED_KEYS.SH ###" -declare -r end_marker="### END MANAGED_BY_KJ_SYNC_AUTHORIZED_KEYS.SH ###" -# If overwrite=true, the entire authorized_keys file is overwritten. -declare -r overwrite=false -declare -r tmpdir=$(mktemp -d /tmp/kj_sync_authorized_keys.XXXXX) - -targets=( - root@orbekk.osl.trygveandre.net - tesuji.6.orbekk.com - login.6.orbekk.com - minecraft.6.orbekk.com - login.pvv.ntnu.no - aji.orbekk.com - moyo.orbekk.com - pi@photobox.6.orbekk.com -) -authorized_keys_file=$HOME/dotfiles/authorized_keys -if [[ ! -f "${authorized_keys_file}" ]]; then - echo "could not find authorized_keys_file: ${authorized_keys_file}" - exit 1 -fi - -add_keys_to_file() { - local filename="$1" - awk \ - "/$begin_marker/"' { exit 0 } { print }' \ - ${filename} > ${filename}.header - awk \ - "/$end_marker/"' { should_output=1 } should_output { print }' \ - ${filename} > ${filename}.footer - - cat "${filename}.header" > ${filename} - echo "${begin_marker}" >> ${filename} - echo "# WARNING: ANY CHANGES WILL BE OVERWRITTEN" >> ${filename} - cat "$authorized_keys_file" >> ${filename} - echo "${end_marker}" >> ${filename} - cat "${filename}.footer" >> ${filename} -} - -for target in ${targets[@]}; do - echo "syncing $target" - tmp="${tmpdir}/${target}" - touch ${tmp} - if [[ $overwrite != true ]]; then - ssh ${target} 'cat .ssh/authorized_keys || echo -n' > ${tmp} - fi - add_keys_to_file "${tmp}" - ssh ${target} 'mkdir -p .ssh' - cat "${tmp}" | ssh ${target} 'cat > .ssh/authorized_keys.tmp && mv .ssh/authorized_keys{.tmp,}' -done diff --git a/bin/setup.sh b/bin/setup.sh deleted file mode 100755 index e3b7c4f..0000000 --- a/bin/setup.sh +++ /dev/null @@ -1,94 +0,0 @@ -#!/bin/bash - -red='\e[0;31m' -orange='\e[0;33m' -green='\e[0;32m' -none='\e[0m' - -cd -# Check that things are in their right places. -if [[ ! -f dotfiles/bin/setup.sh ]]; then - printf "${red}[FAIL]${none} expected to find myself\n" - exit 1 -fi - -required_commands=(git basename) -for command in ${required_commands[@]}; do - if ! which "${command}" >/dev/null; then - printf "${red}[FAIL]${none} ${command} not installed\n" - exit 1 - fi -done - -cd ~/dotfiles -git submodule update --init --recursive -git submodule foreach pull - -cd -# Creates a symlink with target $1 at location $2. -# Does nothing and prints an error message if $2 exists and is not a symlink. -create_symlink() { - if [[ -e "$2" && ! -h "$2" ]]; then - printf "${orange}[SKIPPED]${none} '$2' exists and is not a symlink.\n" - return - else - if ln -sf "$1" "$2"; then - printf "${green}[OK]${none} '$2' → '$1'\n" - else - printf "${red}[WARNING]${none} could not create '$2'\n" - fi - fi - if ! diff "$2" "$(dirname $2)/$1"; then - printf "${red}[WARNING]${none} diffs in $2\n" - fi -} - -create_symlink dotfiles/gitconfig .gitconfig -create_symlink dotfiles/taskrc .taskrc -create_symlink dotfiles/tmux.conf .tmux.conf -create_symlink dotfiles/spacemacs .spacemacs -create_symlink /dev/null .vimrc.local - -mkdir -p bin -for binary in dotfiles/bin/*; do - binary=$(basename "${binary}") - create_symlink "../dotfiles/bin/${binary}" "bin/${binary}" -done - -if [[ "${SHELL}" = *zsh* ]]; then - create_symlink dotfiles/zshrc .zshrc -else - printf "${orange}[SKIPPED]${none} shell is not zsh :-(.\n" -fi - -mkdir -p .ssh -create_symlink ../dotfiles/ssh/config .ssh/config - -if which i3 >/dev/null; then - mkdir -p .i3 - create_symlink ../dotfiles/i3/config .i3/config - create_symlink dotfiles/i3status.conf .i3status.conf - create_symlink dotfiles/i3blocks.conf .i3blocks.conf -else - printf "${orange}[SKIPPED]${none} i3 not installed.\n" -fi - -create_symlink dotfiles/vimrc .vimrc -if [[ -e .vim/bundle/Vundle.vim ]]; then - printf "${orange}[SKIPPED]${none} Vundle.vim already installed\n" -else - success=1 - mkdir -p .vim/bundle - git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim \ - || success=0 -fi -vim +PluginInstall +qall || success=0 -if [[ "$success" == "1" ]]; then - printf "${green}[OK]${none} installed vim plugins\n" -else - printf "${red}[WARNING]${none} failed to install vim plugins\n" -fi - -if which emacs >/dev/null && [[ ! -d .emacs.d ]]; then - git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d -fi -- cgit v1.2.3