-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·48 lines (44 loc) · 1.64 KB
/
setup.sh
File metadata and controls
executable file
·48 lines (44 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
# Online script for dotfiles installation.
me="-->online-setup<--"
remote_repo=Twilight4/dotfiles
set -e
function try { "$@" || sleep 0; }
function x() {
if "$@";then cmdstatus=0;else cmdstatus=1;fi # 0=normal; 1=failed; 2=failed but ignored
while [ $cmdstatus == 1 ] ;do
echo -e "\e[31m$me: Command \"\e[32m$@\e[31m\" has failed."
echo -e "You may need to resolve the problem manually BEFORE repeating this command.\e[0m"
echo " r = Repeat this command (DEFAULT)"
echo " e = Exit now"
read -p " [R/e]: " p
case $p in
[eE]) echo -e "\e[34mExitting.\e[0m";break;;
*) echo -e "\e[34mOK, repeating...\e[0m"
if "$@";then cmdstatus=0;else cmdstatus=1;fi
;;
esac
done
case $cmdstatus in
0) echo -e "\e[34m$me: Command \"\e[32m$@\e[34m\" finished.\e[0m";;
1) echo -e "\e[31m$me: Command \"\e[32m$@\e[31m\" has failed. Exiting...\e[0m";exit 1;;
esac
}
command -v pacman || { echo "\"pacman\" not found. This script only work for Arch(-based) Linux distros. Aborting..."; exit 1 ; }
if [ -z "$1" ]; then
path=~/dotfiles
else
path="$1"
fi
echo "$me: Downloading repo to $path ..."
x mkdir -p $path
x cd $path
if [ -z "$(ls -A)" ]; then
x git init -b main
x git remote add origin https://github.com/$remote_repo
fi
git remote get-url origin|grep -q $remote_repo || { echo "Dir \"$path\" is not empty, nor a git repo of $remote_repo. Aborting..."; exit 1 ; }
x git pull origin main && git submodule update --init --recursive
echo "$me: Downloaded."
echo "$me: Running \"install.sh\"."
x .config/.install/install.sh || { echo "$me: Error occured when running \"install.sh\"."; exit 1 ; }