Skip to content

Commit 7d2de71

Browse files
committed
Use config-manager.sh to bootstrap config
1 parent e4be0a1 commit 7d2de71

File tree

10 files changed

+174
-178
lines changed

10 files changed

+174
-178
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ You are free to use my dotfiles as you wish. However, I strongly encourage you n
77
## Usage
88

99
```bash
10-
git clone https://github.com/cpplain/dotfiles.git &&
11-
cd dotfiles/scripts &&
12-
./install.sh -p
10+
bash -c "$(curl -fsSL https://raw.githubusercontent.com/cpplain/dotfiles/main/config-manager.sh)"
1311
```
1412

1513
## Goals

config-manager.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
test -f ~/.env && source ~/.env
6+
7+
set_env() {
8+
while true; do
9+
echo "Confgure environement for:"
10+
echo "[1] personal (default)"
11+
echo "[2] work"
12+
read -p "Enter selection: " ENV
13+
case $ENV in
14+
2)
15+
ENV=work
16+
;;
17+
*)
18+
ENV=personal
19+
;;
20+
esac
21+
22+
read -p "Target repo directory: " REPO_DIR
23+
REPO_DIR="${REPO_DIR/#\~/$HOME}"
24+
25+
echo "Configuring environment for $ENV"
26+
echo "Cloning dotfiles repo into $REPO_DIR"
27+
read -p "Continue? [Y/n]: " YN
28+
case $YN in
29+
n)
30+
continue
31+
;;
32+
*)
33+
break
34+
;;
35+
esac
36+
done
37+
38+
echo "CONFIG_ENV=$ENV" >~/.env
39+
echo "DOTFILES_REPO_DIR=$REPO_DIR" >>~/.env
40+
}
41+
42+
install_brew() {
43+
echo "Installing brew"
44+
case $(uname -sm) in
45+
"Darwin arm64")
46+
brew=/opt/homebrew/bin/brew
47+
;;
48+
*)
49+
brew=/usr/local/bin/brew
50+
;;
51+
esac
52+
test -x $brew && echo "Brew already installed: $brew" && return
53+
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh | bash
54+
}
55+
56+
clone_repo() {
57+
echo "Cloning dotfiles repo"
58+
test -d $DOTFILES_REPO_DIR/.git && echo "Repo already exists: $DOTFILES_REPO_DIR" && return
59+
git clone --recurse-submodules https://github.com/cpplain/dotfiles.git $DOTFILES_REPO_DIR
60+
}
61+
62+
bootstrap() {
63+
set_env
64+
source ~/.env
65+
install_brew
66+
clone_repo
67+
source $DOTFILES_REPO_DIR/scripts/links.sh
68+
create_links
69+
source $DOTFILES_REPO_DIR/scripts/brew.sh
70+
brew_bundle
71+
}
72+
73+
bootstrap

scripts/brew.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
if ! which brew >/dev/null; then
6+
case $(uname -sm) in
7+
"Darwin arm64")
8+
eval "$(/opt/homebrew/bin/brew shellenv)"
9+
;;
10+
*)
11+
eval "$(/usr/local/bin/brew shellenv)"
12+
;;
13+
esac
14+
fi
15+
16+
source ~/.env || echo "Unable to source .env"
17+
18+
case $CONFIG_ENV in
19+
personal)
20+
brewfile=~/.config/Brewfile
21+
;;
22+
work)
23+
brewfile=~/.config/Brewfile_work
24+
;;
25+
esac
26+
27+
brew_bundle() {
28+
echo "Running brew bundle"
29+
echo "Using brewfile: $brewfile"
30+
brew update
31+
brew bundle --file $brewfile --verbose --force --no-lock
32+
}

scripts/install-brew.sh

Lines changed: 0 additions & 17 deletions
This file was deleted.

scripts/install-packages.sh

Lines changed: 0 additions & 23 deletions
This file was deleted.

scripts/install.sh

Lines changed: 0 additions & 35 deletions
This file was deleted.

scripts/link.sh

Lines changed: 0 additions & 29 deletions
This file was deleted.

scripts/links.sh

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
test -f ~/.env && source ~/.env
6+
7+
find_dotfiles() {
8+
case $1 in
9+
--public)
10+
echo $(find $DOTFILES_REPO_DIR/home -depth 1)
11+
;;
12+
--private)
13+
echo $(find $DOTFILES_REPO_DIR/private/home -type f)
14+
;;
15+
esac
16+
}
17+
18+
source_to_target() {
19+
case $1 in
20+
--public)
21+
echo $(echo $2 | sed "s|$DOTFILES_REPO_DIR/home|$HOME|")
22+
;;
23+
--private)
24+
echo $(echo $2 | sed "s|$DOTFILES_REPO_DIR/private/home|$HOME|")
25+
;;
26+
esac
27+
}
28+
29+
create_link() {
30+
test -L $2 && rm -f $2 && echo "- $2"
31+
ln -s $1 $2 && echo "+ $2 -> $1"
32+
}
33+
34+
create_links() {
35+
echo "Creating public dotfile links"
36+
files=$(find_dotfiles --public)
37+
for f in $files; do
38+
target=$(source_to_target --public $f)
39+
create_link $f $target
40+
done
41+
42+
echo "Creating private dotfile links"
43+
files=$(find_dotfiles --private)
44+
for f in $files; do
45+
target=$(source_to_target --private $f)
46+
create_link $f $target
47+
done
48+
}
49+
50+
remove_link() {
51+
test -L $1 && rm -f $1 && echo "- $1"
52+
}
53+
54+
remove_links() {
55+
echo "Removing private dotfile links"
56+
files=$(find_dotfiles --private)
57+
for f in $files; do
58+
target=$(source_to_target --private $f)
59+
remove_link $target
60+
done
61+
62+
echo "Removing public dotfile links"
63+
files=$(find_dotfiles --public)
64+
for f in $files; do
65+
target=$(source_to_target --public $f)
66+
remove_link $target
67+
done
68+
}

scripts/unlink.sh

Lines changed: 0 additions & 27 deletions
This file was deleted.

scripts/utils.sh

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)