-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.sh
executable file
·189 lines (158 loc) · 5.34 KB
/
init.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
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
179
180
181
182
183
184
185
186
187
188
189
#!/bin/bash
set -e # Exit on any error
REPO="B-urb/dotfiles" # Replace with actual repo
BRANCH="master"
TARGET_DIR="$HOME/.dotfiles"
# Function to check if a command exists
check_command() {
if ! command -v "$1" &> /dev/null; then
echo "Error: '$1' is not installed. Please install it and rerun the script."
exit 1
fi
}
# Ensure required tools are installed
check_command curl
# Function to get dotfiles
get_dotfiles() {
# Clone the repository directly to the target directory
git clone --single-branch --branch "$BRANCH" --recursive "[email protected]:$REPO.git" "$TARGET_DIR"
# Optionally, you can run git pull if you want to update it later
# cd "$TARGET_DIR" && git pull origin "$BRANCH"
}
# Function to install dependencies
install_deps() {
echo "Installing dependencies..."
# Detect OS and install
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
if command -v apt &> /dev/null; then
"$TARGET_DIR/ubuntu/install_software.sh"
elif command -v dnf &> /dev/null; then
sudo dnf install -y bitwarden-cli
elif command -v pacman &> /dev/null; then
sudo pacman -Sy --noconfirm bitwarden-cli
elif command -v zypper &> /dev/null; then
sudo zypper install -y bitwarden-cli
else
echo "Unsupported Linux distribution. Please install dependencies manually."
exit 1
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
brew bundle --file="$TARGET_DIR/macos/Brewfile"
elif [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then
"$TARGET_DIR/windows/install_deps.sh"
else
echo "Unsupported operating system."
exit 1
fi
# Ensure required scripts exist before execution
if [[ -f "$TARGET_DIR/install_cargo.sh" ]]; then
"$TARGET_DIR/install_cargo.sh"
fi
if [[ -f "$TARGET_DIR/install" ]]; then
"$TARGET_DIR/install"
fi
if [[ -f "$TARGET_DIR/install_extensions.sh" ]]; then
"$TARGET_DIR/install_extensions.sh"
fi
}
# Function to install Bitwarden CLI
install_bw_cli() {
if command -v bw &> /dev/null; then
echo "Bitwarden CLI is already installed."
return
fi
echo "Bitwarden CLI not found. Attempting to install..."
# Detect OS and install
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
sudo snap install bw
elif [[ "$OSTYPE" == "darwin"* ]]; then
brew install bitwarden-cli
elif [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then
winget install --id Bitwarden.CLI -e
else
echo "Unsupported operating system. Please install Bitwarden CLI manually."
exit 1
fi
}
install_snap() {
echo "Checking if Snap is installed..."
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
if ! command -v snap &> /dev/null; then
echo "Snap not found. Installing Snap..."
# Install snapd if not already installed
sudo apt update
sudo apt install -y snapd
# Install the snapd snap to ensure we get the latest version
sudo snap install snapd
# Install Snap Store (optional, if you want to use the Snap GUI)
sudo snap install snap-store
echo "Snap installed successfully!"
else
echo "Snap is already installed."
fi
else
echo "Skipping Snap installation on non-Linux systems."
fi
}
install_git() {
echo "Checking if git is installed..."
if ! command -v git &> /dev/null; then
echo "Git not found. Attempting to install..."
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
if command -v apt &> /dev/null; then
sudo apt update && sudo apt install -y git
elif command -v dnf &> /dev/null; then
sudo dnf install -y git
elif command -v pacman &> /dev/null; then
sudo pacman -Sy --noconfirm git
elif command -v zypper &> /dev/null; then
sudo zypper install -y git
else
echo "Unsupported Linux distribution. Please install Git manually."
exit 1
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
brew install git
elif [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then
winget install --id Git.Git -e
else
echo "Unsupported operating system. Please install Git manually."
exit 1
fi
else
echo "Git is already installed."
fi
}
# Ensure BW_SESSION is set
setup_bw_session() {
if [ -z "$BW_SESSION" ]; then
echo "BW_SESSION is not set. Logging in..."
bw config server https://warden.burbn.de
BW_SESSION=$(bw login --raw)
export BW_SESSION
fi
}
# Fetch and setup SSH key from Bitwarden
setup_ssh_key() {
echo "Fetching SSH key from Bitwarden..."
SSH_KEY=$(bw get item ssh-key --session "$BW_SESSION" | jq -r '.notes')
if [ -z "$SSH_KEY" ]; then
echo "Error: SSH key not found in Bitwarden."
exit 1
fi
SSH_KEY_FILE="$HOME/.ssh/id_rsa"
echo "$SSH_KEY" > "$SSH_KEY_FILE"
chmod 600 "$SSH_KEY_FILE"
eval "$(ssh-agent -s)"
ssh-add -D
ssh-add "$SSH_KEY_FILE"
}
# Execute functions in correct order
install_git
install_snap
install_bw_cli
export PATH=$PATH:/snap/bin
setup_bw_session
setup_ssh_key
get_dotfiles
install_deps