mirror of
https://github.com/DictXiong/dotfiles.git
synced 2025-04-24 21:56:54 +08:00
preinstall_check
This commit is contained in:
parent
df8bd9c6a2
commit
4742b8d3d3
42
install.sh
42
install.sh
|
@ -3,6 +3,7 @@
|
|||
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||
source "$THIS_DIR/tools/common.sh"
|
||||
|
||||
|
||||
if [[ ! "$DOTFILES" == "${HOME}"* ]]; then
|
||||
fmt_fatal "\"$DOTFILES\" is not under \"$HOME\". aborting ..."
|
||||
fi
|
||||
|
@ -26,6 +27,30 @@ HOME_SYMLINKS_SRC[0]=".ssh/authorized_keys2"
|
|||
HOME_SYMLINKS_DST[0]=".ssh/authorized_keys2"
|
||||
|
||||
|
||||
preinstall_check()
|
||||
{
|
||||
mandatory_commands=( "git" "zsh" "curl" "ping" )
|
||||
optional_commands=( "python3" "vim" "tmux" )
|
||||
for i in "${mandatory_commands[@]}"; do
|
||||
if [[ ! -x "$(command -v $i)" ]]; then
|
||||
fmt_info "all this utils are required: ${mandatory_commands[@]}"
|
||||
fmt_info "install them manually or check scripts in tools/"
|
||||
fmt_fatal "\"$i\" not found. aborting ..."
|
||||
fi
|
||||
done
|
||||
for i in "${optional_commands[@]}"; do
|
||||
if [[ ! -x "$(command -v $i)" ]]; then
|
||||
fmt_warning "\"$i\" not found"
|
||||
ask_for_Yn "continue anyway?"
|
||||
if [[ "$?" == "0" ]]; then
|
||||
fmt_info "all this utils are suggested: ${optional_commands[@]}"
|
||||
fmt_info "install them manually or check scripts in tools/"
|
||||
fmt_fatal "aborting ..."
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
install_file_content()
|
||||
{
|
||||
for ((i=0; i<${#HOME_FILES_PATH[@]}; i++)); do
|
||||
|
@ -101,13 +126,21 @@ uninstall_symlink()
|
|||
}
|
||||
|
||||
install_crontab(){
|
||||
fmt_note "installing \"$CRON_JOB\" to crontab ..."
|
||||
( crontab -l | grep -vxF "${CRON_JOB}" | grep -v "no crontab for"; echo "$CRON_JOB" ) | crontab -
|
||||
if [[ -x $(command -v crontab) ]]; then
|
||||
fmt_note "installing \"$CRON_JOB\" to crontab ..."
|
||||
( crontab -l | grep -vxF "${CRON_JOB}" | grep -v "no crontab for"; echo "$CRON_JOB" ) | crontab -
|
||||
else
|
||||
fmt_warning "crontab does not exist. skipping ..."
|
||||
fi
|
||||
}
|
||||
|
||||
uninstall_crontab(){
|
||||
fmt_note "removing \"$CRON_JOB\" from crontab ..."
|
||||
( crontab -l | grep -vxF "$CRON_JOB" ) | crontab -
|
||||
if [[ -x $(command -v crontab) ]]; then
|
||||
fmt_note "removing \"$CRON_JOB\" from crontab ..."
|
||||
( crontab -l | grep -vxF "$CRON_JOB" ) | crontab -
|
||||
else
|
||||
fmt_note "crontab does not exist. skipping ..."
|
||||
fi
|
||||
}
|
||||
|
||||
install_tmux_tpm(){
|
||||
|
@ -152,6 +185,7 @@ uninstall_update(){
|
|||
}
|
||||
|
||||
install(){
|
||||
preinstall_check
|
||||
install_update
|
||||
install_crontab
|
||||
install_file_content
|
||||
|
|
|
@ -38,7 +38,7 @@ supports_truecolor() {
|
|||
|
||||
fmt_fatal() {
|
||||
printf '%sfatal: %s%s\n' "${FMT_BOLD}${FMT_RED}" "$*" "${FMT_RESET}" >&2
|
||||
exit
|
||||
exit 1
|
||||
}
|
||||
|
||||
fmt_error() {
|
||||
|
@ -113,6 +113,18 @@ ask_for_yN()
|
|||
return 0
|
||||
}
|
||||
|
||||
ask_for_Yn()
|
||||
{
|
||||
while [[ -z "$DFS_QUIET" ]]; do
|
||||
read -p "${FMT_YELLOW}$1${FMT_RESET} [Yn]: " yn
|
||||
case $yn in
|
||||
[Nn]* ) return 0;;
|
||||
* ) return 1;;
|
||||
esac
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
post_log()
|
||||
{
|
||||
python3 "${DOTFILES}/tools/log.py" "[$1] $2: $3"
|
||||
|
|
|
@ -13,7 +13,7 @@ set_mirror()
|
|||
pacman_S()
|
||||
{
|
||||
pacman -Syu
|
||||
pacman -S tmux git zsh curl vim wget base-devel mingw-w64-x86_64-toolchain make cmake gcc zip unzip
|
||||
pacman -S tmux git zsh curl vim wget base-devel mingw-w64-x86_64-toolchain make cmake gcc zip unzip python3 python3-pip
|
||||
}
|
||||
|
||||
router()
|
||||
|
|
Loading…
Reference in New Issue
Block a user