mirror of
https://github.com/DictXiong/dotfiles.git
synced 2025-07-01 12:50:30 +08:00
use update.sh to update safely
This commit is contained in:
parent
bbeffe3313
commit
61b7d11977
25
.update.sh
Normal file
25
.update.sh
Normal file
@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
export DOTFILES=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||
# get the specified commit id
|
||||
dfs_commit=$(curl -fsSL https://api.beardic.cn/get-dfs-commit)
|
||||
if [[ ${#dfs_commit} != 40 ]]; then
|
||||
echo "Error: invalid commit id."
|
||||
exit
|
||||
fi
|
||||
# fetch origin
|
||||
cd $DOTFILES
|
||||
git fetch
|
||||
if [[ -n "$(git status -s)" ]]; then
|
||||
echo "Error: directory not clean."
|
||||
exit
|
||||
fi
|
||||
# update
|
||||
if [[ "$(git rev-parse HEAD)" == "$dfs_commit" ]]; then
|
||||
echo "Nothing to do."
|
||||
else
|
||||
echo "Checking out to commit $dfs_commit ..."
|
||||
git checkout $dfs_commit
|
||||
cp ./.update.sh ./update.sh
|
||||
chmod +x ./update.sh
|
||||
fi
|
2
.zshrc2
2
.zshrc2
@ -80,7 +80,7 @@ fi
|
||||
dfs()
|
||||
{
|
||||
case $1 in
|
||||
update ) (cd "$DOTFILES" && git pull) ;;
|
||||
update ) $DOTFILES/update.sh ;;
|
||||
force-update ) (cd "$DOTFILES" && git fetch --all && git reset --hard origin/main && git pull) ;;
|
||||
reset )
|
||||
antigen reset 1> /dev/null
|
||||
|
11
install.sh
11
install.sh
@ -96,7 +96,7 @@ if [[ ! $dotfile_path == ${home_slashes}* ]]; then
|
||||
fi
|
||||
dotfile_home_path=${dotfile_path/${home_slashes}/\~}
|
||||
dotfile_relative_path=${dotfile_path#${home_slashes}\/}
|
||||
crontab_job="0 * * * * cd ${dotfile_path} && env git pull"
|
||||
crontab_job="0 * * * * ${dotfile_path}/update.sh"
|
||||
|
||||
ask_for_yN()
|
||||
{
|
||||
@ -209,7 +209,16 @@ install_vim_vundle(){
|
||||
fi
|
||||
}
|
||||
|
||||
install_update(){
|
||||
fmt_note "installing update.sh ..."
|
||||
cp "${dotfile_path}/.update.sh" "${dotfile_path}/update.sh"
|
||||
chmod +x "${dotfile_path}/update.sh"
|
||||
fmt_note "running update.sh ..."
|
||||
${dotfile_path}/update.sh
|
||||
}
|
||||
|
||||
install(){
|
||||
install_update
|
||||
install_crontab
|
||||
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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user