-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
114 lines (99 loc) · 3.42 KB
/
install.sh
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env bash
{
# -----------------------------------
# author: @kiliantyler
# title: Dotfiles Installation Script
# description: Installs Xcode Command Line Tools if they are not already installed,
# then installs Chezmoi and initializes it with dotfiles repo.
# -----------------------------------
# -----------------------------------
# Instructions
#
# This script is intended to be run via curl through a specific URL.
# Do not run this script directly from github.
#
# To install, run the following command:
# curl -fsSL https://install.dotfiles.wiki/<yourGithubUsername> | sh
#
# This will assume that you have your dotfiles hosted on Github with the repo name "dotfiles"
# In the future this will support other git providers and repo names.
#
# -----------------------------------
#!/bin/sh
# POSIX shell script compatible version
fail() {
echo "$1" >&2
exit 1
}
# Checks if Command Line Tools are installed (MacOS)
should_install_command_line_tools() {
[ ! -e "/Library/Developer/CommandLineTools/usr/bin/git" ]
}
# Removes newline from a string (POSIX compatible)
chomp() {
echo "$1" | tr -d '\n'
}
sudo -v
# get OS type
OS=$(uname -s)
macos_install() {
# -----------------------------------
# Xcode Command Line Tools Installation (MacOS-specific)
# -----------------------------------
if should_install_command_line_tools; then
echo "Installing Xcode Command Line Tools"
clt_placeholder="/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress"
sudo touch "$clt_placeholder"
clt_label_command="/usr/sbin/softwareupdate -l |
grep -B 1 -E 'Command Line Tools' |
awk -F'*' '/^ *\\*/ {print \$2}' |
sed -e 's/^ *Label: //' -e 's/^ *//' |
sort -V |
tail -n1"
clt_label="$(chomp "$(sh -c "$clt_label_command")")"
if [ -n "$clt_label" ]; then
sudo /usr/sbin/softwareupdate -i "$clt_label"
sudo /usr/bin/xcode-select --switch /Library/Developer/CommandLineTools
fi
sudo rm -f "$clt_placeholder"
fi
}
linux_install() {
# -----------------------------------
# Linux Dependencies Installation (Linux-specific)
# -----------------------------------
if command -v apt-get >/dev/null 2>&1; then
echo "Installing dependencies with apt-get"
sudo apt-get update
sudo apt-get install -y zsh git curl
elif command -v dnf >/dev/null 2>&1; then
echo "Installing dependencies with dnf"
sudo dnf install -y git curl zsh
elif command -v yum >/dev/null 2>&1; then
echo "Installing dependencies with yum"
sudo yum install -y git curl zsh
else
fail "Unsupported package manager"
fi
}
if [ "$OS" = "Darwin" ]; then
echo "MacOS detected"
macos_install
elif [ "$OS" = "Linux" ]; then
echo "Linux detected"
linux_install
else
fail "Unsupported OS: $OS"
fi
# -----------------------------------
# Chezmoi Installation and Initialization
# -----------------------------------
if command -v chezmoi >/dev/null 2>&1; then
echo "Chezmoi is already installed"
else
echo "Installing Chezmoi..."
sh -c "$(curl -fsLS get.chezmoi.io)" -- -b "$HOME/.local/bin"
fi
# Initialize chezmoi with the provided repo
"$HOME/.local/bin/chezmoi" init --apply "{{USERNAME}}"
}