preinstall_check

This commit is contained in:
Dict Xiong 2022-11-05 19:12:55 +08:00
parent df8bd9c6a2
commit 4742b8d3d3
3 changed files with 52 additions and 6 deletions

View File

@ -3,6 +3,7 @@
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd ) THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
source "$THIS_DIR/tools/common.sh" source "$THIS_DIR/tools/common.sh"
if [[ ! "$DOTFILES" == "${HOME}"* ]]; then if [[ ! "$DOTFILES" == "${HOME}"* ]]; then
fmt_fatal "\"$DOTFILES\" is not under \"$HOME\". aborting ..." fmt_fatal "\"$DOTFILES\" is not under \"$HOME\". aborting ..."
fi fi
@ -26,6 +27,30 @@ HOME_SYMLINKS_SRC[0]=".ssh/authorized_keys2"
HOME_SYMLINKS_DST[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() install_file_content()
{ {
for ((i=0; i<${#HOME_FILES_PATH[@]}; i++)); do for ((i=0; i<${#HOME_FILES_PATH[@]}; i++)); do
@ -101,13 +126,21 @@ uninstall_symlink()
} }
install_crontab(){ install_crontab(){
if [[ -x $(command -v crontab) ]]; then
fmt_note "installing \"$CRON_JOB\" to crontab ..." fmt_note "installing \"$CRON_JOB\" to crontab ..."
( crontab -l | grep -vxF "${CRON_JOB}" | grep -v "no crontab for"; echo "$CRON_JOB" ) | 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(){ uninstall_crontab(){
if [[ -x $(command -v crontab) ]]; then
fmt_note "removing \"$CRON_JOB\" from crontab ..." fmt_note "removing \"$CRON_JOB\" from crontab ..."
( crontab -l | grep -vxF "$CRON_JOB" ) | crontab - ( crontab -l | grep -vxF "$CRON_JOB" ) | crontab -
else
fmt_note "crontab does not exist. skipping ..."
fi
} }
install_tmux_tpm(){ install_tmux_tpm(){
@ -152,6 +185,7 @@ uninstall_update(){
} }
install(){ install(){
preinstall_check
install_update install_update
install_crontab install_crontab
install_file_content install_file_content

View File

@ -38,7 +38,7 @@ supports_truecolor() {
fmt_fatal() { fmt_fatal() {
printf '%sfatal: %s%s\n' "${FMT_BOLD}${FMT_RED}" "$*" "${FMT_RESET}" >&2 printf '%sfatal: %s%s\n' "${FMT_BOLD}${FMT_RED}" "$*" "${FMT_RESET}" >&2
exit exit 1
} }
fmt_error() { fmt_error() {
@ -113,6 +113,18 @@ ask_for_yN()
return 0 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() post_log()
{ {
python3 "${DOTFILES}/tools/log.py" "[$1] $2: $3" python3 "${DOTFILES}/tools/log.py" "[$1] $2: $3"

View File

@ -13,7 +13,7 @@ set_mirror()
pacman_S() pacman_S()
{ {
pacman -Syu 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() router()