-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·142 lines (122 loc) · 4.7 KB
/
install.sh
File metadata and controls
executable file
·142 lines (122 loc) · 4.7 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
#!/bin/bash
# Dotfiles installation script with bitwarden session management
# Copied from: https://github.com/twpayne/chezmoi
set -e # -e: exit on error
# setup common to all install scripts
source "${DOTFILES}/lib/common/all.sh"
# Show help function
show_help() {
cat << EOF
Dotfiles Installation Script
USAGE:
$0 [OPTIONS]
DESCRIPTION:
Installs and configures a complete development environment using chezmoi
dotfiles management. This script will:
• Install chezmoi if not present
• Set up prerequisites (Homebrew, Node.js, development tools)
• Install platform-specific packages (Arch, Flatpak, Homebrew)
• Configure development applications (VS Code, Zed, Claude Code)
• Set up Bitwarden integration for secrets management
• Apply dotfiles configuration templates
OPTIONS:
--debug Enable debug mode with verbose output and bash tracing
--user USERNAME Set username for Bitwarden Apple ID lookup (default: ashebanow)
--help Show this help message and exit
EXAMPLES:
$0 # Normal installation (uses 'ashebanow' user)
$0 --user john # Installation using 'john_apple_id' Bitwarden entry
$0 --debug # Installation with debug output
$0 --help # Show this help
For more information, see: https://github.com/ashebanow/dotfiles
EOF
}
# Parse command line arguments
DEBUG_MODE=false
USER_NAME=""
while [[ $# -gt 0 ]]; do
case $1 in
--debug)
DEBUG_MODE=true
shift
;;
--user)
if [[ -n "$2" && "$2" != --* ]]; then
USER_NAME="$2"
shift 2
else
log_error "Error: --user requires a username argument"
log_error "Try '$0 --help' for more information."
exit 1
fi
;;
--help|-h)
show_help
exit 0
;;
*)
log_error "Unknown option: $1"
log_error "Usage: $0 [--debug] [--user USERNAME] [--help]"
log_error "Try '$0 --help' for more information."
exit 1
;;
esac
done
# Set debug options if requested
if [[ "$DEBUG_MODE" == "true" ]]; then
log_debug "🐛 Debug mode enabled"
export GUM_LOG_LEVEL=debug
set -x # Enable bash debug tracing
fi
# Set Apple ID username for Bitwarden lookup (with default)
export APPLE_ID_USER="${USER_NAME:-ashebanow}"
# POSIX way to get script's dir: https://stackoverflow.com/a/29834779/12156188
script_dir="$(cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P)"
# Install chezmoi if not available
if [ ! "$(command -v chezmoi)" ]; then
bin_dir="$HOME/.local/bin"
chezmoi="$bin_dir/chezmoi"
if [ "$(command -v curl)" ]; then
sh -c "$(curl -fsSL https://git.io/chezmoi)" -- -b "$bin_dir"
elif [ "$(command -v wget)" ]; then
sh -c "$(wget -qO- https://git.io/chezmoi)" -- -b "$bin_dir"
else
log_error "To install chezmoi, you must have curl or wget installed."
exit 1
fi
else
chezmoi=chezmoi
fi
# Initialize chezmoi without applying (to set up source directory)
log_info "Initializing chezmoi..."
"$chezmoi" init --source="$script_dir"
# Run install scripts to set up dependencies
export DOTFILES="$script_dir"
# Set flag to prevent recursive calls from run_onchange scripts
export DOTFILES_INSTALL_RUNNING=1
log_info "Running installation scripts..."
"$script_dir/lib/install/main.sh"
# Establish bitwarden session for template expansion
log_info "Setting up Bitwarden session for template expansion..."
if [ -x "$script_dir/home/private_dot_local/bin/executable_bw-session-manager" ]; then
# Use the new session manager from source
export BW_SESSION=$("$script_dir/home/private_dot_local/bin/executable_bw-session-manager" ensure)
elif [ -x "$script_dir/home/private_dot_local/bin/executable_bw-open" ]; then
# Fallback to bw-open from source
export BW_SESSION=$("$script_dir/home/private_dot_local/bin/executable_bw-open")
else
log_error "Error: Bitwarden session tools not found. Cannot proceed with template expansion."
log_error "Expected files:"
log_error " $script_dir/home/private_dot_local/bin/executable_bw-session-manager"
log_error " $script_dir/home/private_dot_local/bin/executable_bw-open"
exit 1
fi
# Now apply all templates with bitwarden session available
log_info "Applying dotfiles configuration..."
"$chezmoi" apply
log_info "Applied dotfiles configuration..."
log_info "✅ Dotfiles installation complete!"
log_info ""
log_info "The bitwarden session service is now running and will manage"
log_info "persistent sessions automatically. Use 'bw-open' in new shells"
log_info "to get the session when you need bitwarden access."