-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
178 lines (159 loc) · 5.18 KB
/
setup.sh
File metadata and controls
178 lines (159 loc) · 5.18 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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env bash
set -Eeuo pipefail
declare -r DOTFILES_REPO_URL="https://github.com/ishioni/dotfiles"
declare ostype="$(uname)"
function initialize_os_env() {
if [[ "${ostype}" == "Darwin" ]]; then
initialize_macos
elif [[ "${ostype}" == "Linux" ]]; then
if [[ "$(uname -r)" == *"+truenas"* ]]; then
ostype="TrueNAS"
initialize_truenas
else
initialize_linux
fi
else
echo "Invalid OS type: ${ostype}" >&2
exit 1
fi
}
function initialize_macos() {
function install_xcode() {
local git_cmd_path=$(which git)
if [[ ! -e "${git_cmd_path}" ]]; then
# Install command line developer tool
xcode-select --install
read -p "Press any key when the installation has completed." -n 1 -r
else
echo "Command line developer tools are installed."
fi
}
function install_rosetta() {
sudo softwareupdate --agree-to-license --install-rosetta
}
echo "Initializing MacOS..."
install_xcode
install_rosetta
}
function initialize_linux() {
echo "Initializing Linux..."
}
function initialize_truenas() {
if [[ ! -s /home/linuxbrew ]] ; then
echo "Initializing Truenas..."
sudo install-dev-tools
# Determine zpool to use: prefer env var ZFS_POOL, then TRUENAS_ZPOOL, else prompt
local zpool_name=""
if [[ -n "${ZFS_POOL-}" ]]; then
zpool_name="${ZFS_POOL}"
elif [[ -n "${TRUENAS_ZPOOL-}" ]]; then
zpool_name="${TRUENAS_ZPOOL}"
else
read -r -p "Enter the ZFS pool to create the linuxbrew dataset on (or leave empty to skip ZFS dataset creation): " zpool_name
fi
# Test if the provided zpool exists
if ! sudo zfs list "${zpool_name}" >/dev/null 2>&1; then
echo "ZFS pool ${zpool_name} does not exist, exiting..."
exit 1
fi
# If zpool provided, create dataset with mountpoint at /home/linuxbrew
if [[ -n "${zpool_name}" ]]; then
dataset="${zpool_name}/linuxbrew"
echo "Creating ZFS dataset ${dataset}"
# Create dataset if it doesn't exist
if ! sudo zfs list "${dataset}" >/dev/null 2>&1; then
sudo zfs create "${dataset}"
else
echo "ZFS dataset ${dataset} already exists."
fi
# Ensure ownership on the dataset
sudo chown -R "${USER}:${USER}" "/mnt/${dataset}"
sudo chmod 775 "/mnt/${dataset}"
fi
# Ensure user's home has a symlink pointing to the ZFS-managed /home/linuxbrew
if [[ ! -s /home/linuxbrew ]] ; then
sudo ln -sfn "/mnt/${dataset}" /home/linuxbrew
fi
# Create tmpdir
mkdir -p "/mnt/${dataset}/tmp"
else
echo "Truenas ready for homebrew"
fi
}
function get_homebrew_install_dir() {
if [[ "${ostype}" == "Darwin" ]]; then
echo "/opt/homebrew"
elif [[ "${ostype}" == "Linux" ]] || [[ "${ostype}" == "TrueNAS" ]]; then
echo "/home/linuxbrew/.linuxbrew"
fi
}
function install_homebrew() {
# Install Homebrew if necessary
export HOMEBREW_CASK_OPTS=--no-quarantine
if [[ -e "$(get_homebrew_install_dir)/bin/brew" ]]; then
echo "Homebrew is already installed."
else
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
}
function install_chezmoi() {
# Install chezmoi if necessary
if [[ -e "$(get_homebrew_install_dir)/bin/chezmoi" ]]; then
echo "Chezmoi is already installed."
else
brew install chezmoi
fi
}
function install_1password() {
# Install 1Password if necessary
if [[ "${ostype}" == "Darwin" ]]; then
if [[ -e "$(get_homebrew_install_dir)/bin/op" ]]; then
echo "1Password is already installed."
else
brew install --cask 1password
brew install --cask 1password-cli
fi
elif [[ "${ostype}" == "Linux" ]]; then
if [[ -e "/usr/local/bin/op" ]]; then
echo "1Password is already installed."
else
wget "https://cache.agilebits.com/dist/1P/op2/pkg/v2.32.0/op_linux_amd64_v2.32.0.zip" -O op.zip && \
unzip -d op op.zip && \
sudo mv op/op /usr/local/bin/ && \
rm -r op.zip op && \
sudo groupadd -f onepassword-cli && \
sudo chgrp onepassword-cli /usr/local/bin/op && \
sudo chmod g+s /usr/local/bin/op
fi
elif [[ "${ostype}" == "TrueNAS" ]]; then
if [[ -e "$(get_homebrew_install_dir)/bin/op" ]]; then
echo "1Password is already installed."
else
wget "https://cache.agilebits.com/dist/1P/op2/pkg/v2.32.0/op_linux_amd64_v2.32.0.zip" -O op.zip && \
unzip -d op op.zip && \
sudo mv op/op "$(get_homebrew_install_dir)/bin/op" && \
sudo chmod g+s "$(get_homebrew_install_dir)/bin/op"
fi
fi
if [[ "${ostype}" == "TrueNAS" ]]; then
op account add --address my.1password.com
eval "$(op signin)"
else
read -p "Please open 1Password, log into all accounts and set under Settings>CLI activate Integrate with 1Password CLI. Press any key to continue." -n 1 -r
fi
}
function get_homebrew_shellenv() {
"$(get_homebrew_install_dir)/bin/brew" shellenv
}
initialize_os_env
install_homebrew
eval "$(get_homebrew_shellenv)"
install_chezmoi
install_1password
# Apply dotfiles
echo "Applying Chezmoi configuration."
chezmoi init "${DOTFILES_REPO_URL}"
cd ~/.local/share/chezmoi
git remote set-url origin git@github.com:ishioni/dotfiles.git
chezmoi apply
source "${HOME}"/.zshrc