From 1901c3a9ce8d554e195b51154a2a24b02d198eeb Mon Sep 17 00:00:00 2001 From: Dict Xiong Date: Sat, 21 May 2022 14:47:39 +0800 Subject: [PATCH] .gitconfig; tools/alpine.sh; mkdir -p when install; restruct ubuntu.sh --- .gitconfig2 | 3 +++ install.sh | 4 ++++ tools/alpine.sh | 38 ++++++++++++++++++++++++++++++++++++++ tools/ubuntu.sh | 25 ++++++++++++------------- 4 files changed, 57 insertions(+), 13 deletions(-) create mode 100644 .gitconfig2 create mode 100755 tools/alpine.sh diff --git a/.gitconfig2 b/.gitconfig2 new file mode 100644 index 0000000..ba6799e --- /dev/null +++ b/.gitconfig2 @@ -0,0 +1,3 @@ +[user] + email = me@beardic.cn + name = Dict Xiong diff --git a/install.sh b/install.sh index 76c5c41..4da10c0 100755 --- a/install.sh +++ b/install.sh @@ -115,6 +115,7 @@ insert_if_not_exist() filename=$1 line=$2 fmt_note "installing \"$line\" into \"$filename\" ..." + mkdir -p $(dirname "$filename") if [ ! -f "$filename" ]; then touch $filename fi @@ -140,6 +141,7 @@ create_symlink() fmt_error "\"$src\" does not exist! aborting this job ..." return 1 fi + mkdir -p $(driname "$dest") if [ -f "$dest" ]; then if [ "$(readlink $dest)" -ef "$src" ]; then return 0 @@ -212,6 +214,7 @@ install(){ insert_if_not_exist "${HOME}/.zshrc" "source ${dotfile_home_path}/.zshrc2" insert_if_not_exist "${HOME}/.tmux.conf" "source-file ${dotfile_home_path}/.tmux.conf2" insert_if_not_exist "${HOME}/.vimrc" "source ${dotfile_home_path}/.vimrc2" + insert_if_not_exist "${HOME}/.gitconfig" "[include] path = \"${dotfile_home_path}/.gitconfig2\"" create_symlink "${dotfile_path}/.ssh/authorized_keys2" "${HOME}/.ssh/authorized_keys2" # those that won't be uninstalled in the future install_tmux_tpm @@ -226,6 +229,7 @@ uninstall(){ delete_if_exist "${HOME}/.zshrc" "source ${dotfile_home_path}/.zshrc2" delete_if_exist "${HOME}/.tmux.conf" "source-file ${dotfile_home_path}/.tmux.conf2" delete_if_exist "${HOME}/.vimrc" "source ${dotfile_home_path}/.vimrc2" + delete_if_exist "${HOME}/.gitconfig" "[include] path = \"${dotfile_home_path}/.gitconfig2\"" delete_link_if_match "${dotfile_path}/.ssh/authorized_keys2" "${HOME}/.ssh/authorized_keys2" fmt_note "done uninstalling!" fi diff --git a/tools/alpine.sh b/tools/alpine.sh new file mode 100755 index 0000000..5f9ca24 --- /dev/null +++ b/tools/alpine.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +if [[ $USER != "root" ]]; then + echo "must run as root!" + exit 1 +fi + +set_mirror() +{ + #MIRROR=${1:="mirrors.tuna.tsinghua.edu.cn"} + #MIRROR=${MIRROR//\//\\\/} + #sed -i 's/(archive|security).ubuntu.com/${MIRROR}/g' /etc/apt/sources.list + echo "to-do ..." +} + +apk_add() +{ + apk update + + # mass installation + apk add zsh git tmux vim curl wget bash python3 htop gcc g++ cmake make fzf perl linux-headers bind-tools iputils man-db + #for i in {fzf,ripgrep}; do apk add $i -y; done + + # who am i + git config --global user.email "me@beardic.cn" + git config --global user.name "Dict Xiong" +} + +router() +{ + case $1 in + apk-add ) apk_add ;; + #set-mirror ) set_mirror $2 ;; + * ) echo unknown command "$1". available: apk-add;; + esac +} + +router $@ diff --git a/tools/ubuntu.sh b/tools/ubuntu.sh index 0f8e0f6..ecf290c 100755 --- a/tools/ubuntu.sh +++ b/tools/ubuntu.sh @@ -5,26 +5,24 @@ if [[ $USER != "root" ]]; then exit 1 fi -init() +set_mirror() +{ + MIRROR=${1:="mirrors.tuna.tsinghua.edu.cn"} + MIRROR=${MIRROR//\//\\\/} + sed -i 's/(archive|security).ubuntu.com/${MIRROR}/g' /etc/apt/sources.list +} + +apt_install() { # basic packages apt update for i in {man-db,vim,ca-certificates}; do apt install $i -y; done - # apt source - ${MIRROR:="mirrors.tuna.tsinghua.edu.cn"} - MIRROR=${MIRROR//\//\\\/} - sed -i 's/(archive|security).ubuntu.com/${MIRROR}/g' /etc/apt/sources.list - # mass installation apt update - apt install git tmux zsh curl wget dialog net-tools dnsutils netcat traceroute sudo python3 python3-pip cron inetutils-ping openssh-client openssh-server htop gcc g++ cmake + apt install git tmux zsh curl wget dialog net-tools dnsutils netcat traceroute sudo python3 python3-pip cron inetutils-ping openssh-client openssh-server htop gcc g++ cmake make for i in {fzf,ripgrep}; do apt install $i -y; done - # custom dotfiles (usually not needed) - mkdir -p ~/.ssh - # cd ~ && git clone https://gitee.com/dictxiong/dotfiles && ./dotfiles/install.sh - # who am i git config --global user.email "me@beardic.cn" git config --global user.name "Dict Xiong" @@ -33,8 +31,9 @@ init() router() { case $1 in - init ) init ;; - * ) echo unknown command "$1". available: init ;; + apt-install ) apt_install ;; + set-mirror ) set_mirror $2 ;; + * ) echo unknown command "$1". available: apt-install, set-mirror;; esac }