1+ #! /usr/bin/env bash
2+
3+ set -e
4+
5+ # Version can be overridden by setting FILEFUSION_VERSION
6+ VERSION=${FILEFUSION_VERSION:- " latest" }
7+ GITHUB_REPO=" drgsn/filefusion"
8+ INSTALL_DIR=" ${HOME} /.filefusion"
9+
10+ print_help () {
11+ cat << EOF
12+ FileFusion Installer
13+
14+ Usage: ./install.sh [options]
15+
16+ Options:
17+ -h, --help Show this help message
18+ -v, --version Install specific version instead of latest
19+ -d, --dir Specify installation directory (default: ~/.filefusion)
20+ -s, --skip-rc Skip updating shell RC files
21+
22+ Environment variables:
23+ FILEFUSION_VERSION Set specific version to install
24+ EOF
25+ }
26+
27+ # Parse command line arguments
28+ while [[ $# -gt 0 ]]; do
29+ case $1 in
30+ -h|--help)
31+ print_help
32+ exit 0
33+ ;;
34+ -v|--version)
35+ VERSION=" $2 "
36+ shift 2
37+ ;;
38+ -d|--dir)
39+ INSTALL_DIR=" $2 "
40+ shift 2
41+ ;;
42+ -s|--skip-rc)
43+ SKIP_RC=1
44+ shift
45+ ;;
46+ * )
47+ echo " Unknown option: $1 "
48+ print_help
49+ exit 1
50+ ;;
51+ esac
52+ done
53+
54+ # Function to detect OS and architecture
55+ detect_platform () {
56+ local os arch
57+
58+ # Detect OS
59+ case " $( uname -s) " in
60+ Darwin)
61+ os=" darwin"
62+ ;;
63+ Linux)
64+ os=" linux"
65+ ;;
66+ MINGW* |MSYS* |CYGWIN* )
67+ os=" windows"
68+ ;;
69+ * )
70+ echo " Unsupported operating system: $( uname -s) "
71+ exit 1
72+ ;;
73+ esac
74+
75+ # Detect architecture
76+ case " $( uname -m) " in
77+ x86_64|amd64)
78+ arch=" amd64"
79+ ;;
80+ arm64|aarch64)
81+ arch=" arm64"
82+ ;;
83+ * )
84+ echo " Unsupported architecture: $( uname -m) "
85+ exit 1
86+ ;;
87+ esac
88+
89+ echo " ${os} _${arch} "
90+ }
91+
92+ # Function to detect shell and get rc file path
93+ get_shell_rc () {
94+ local shell_rc=" "
95+
96+ if [ -n " $ZSH_VERSION " ]; then
97+ shell_rc=" $HOME /.zshrc"
98+ elif [ -n " $BASH_VERSION " ]; then
99+ if [[ " $OSTYPE " == " darwin" * ]]; then
100+ shell_rc=" $HOME /.bash_profile"
101+ else
102+ shell_rc=" $HOME /.bashrc"
103+ fi
104+ elif [ -n " $FISH_VERSION " ]; then
105+ shell_rc=" $HOME /.config/fish/config.fish"
106+ fi
107+
108+ if [ -z " $shell_rc " ]; then
109+ echo " Unable to detect shell configuration file"
110+ exit 1
111+ fi
112+
113+ echo " $shell_rc "
114+ }
115+
116+ # Function to download the latest release
117+ download_release () {
118+ local platform=" $1 "
119+ local ext=" tar.gz"
120+ if [[ " $platform " == windows* ]]; then
121+ ext=" zip"
122+ fi
123+
124+ local version_no
125+ if [ " $VERSION " = " latest" ]; then
126+ # Get the latest version number from the latest release
127+ version_no=$( curl -fsSL " https://api.github.com/repos/${GITHUB_REPO} /releases/latest" | grep ' "tag_name":' | sed -E ' s/.*"([^"]+)".*/\1/' | sed ' s/^v//' )
128+ if [ -z " $version_no " ]; then
129+ echo " Failed to get latest version number"
130+ exit 1
131+ fi
132+ else
133+ # Remove 'v' prefix if present
134+ version_no=$( echo " $VERSION " | sed ' s/^v//' )
135+ fi
136+
137+ local release_url=" https://github.com/${GITHUB_REPO} /releases/download/v${version_no} /filefusion_${version_no} _${platform} .${ext} "
138+
139+ echo " Downloading FileFusion from: $release_url "
140+
141+ # Create temporary directory
142+ local tmp_dir
143+ tmp_dir=" $( mktemp -d) "
144+
145+ # Download the release
146+ if ! curl -fsSL " $release_url " -o " ${tmp_dir} /filefusion.${ext} " ; then
147+ echo " Failed to download FileFusion"
148+ rm -rf " $tmp_dir "
149+ exit 1
150+ fi
151+
152+ # Extract the release
153+ mkdir -p " $INSTALL_DIR "
154+ if [[ " $platform " == windows* ]]; then
155+ unzip -o " ${tmp_dir} /filefusion.${ext} " -d " $INSTALL_DIR "
156+ else
157+ tar xzf " ${tmp_dir} /filefusion.${ext} " -C " $INSTALL_DIR "
158+ fi
159+
160+ # Cleanup
161+ rm -rf " $tmp_dir "
162+ }
163+
164+ # Function to update shell configuration
165+ update_shell_rc () {
166+ local shell_rc=" $1 "
167+ local path_export=" export PATH=\"\$ PATH:$INSTALL_DIR \" "
168+
169+ # Check if path is already in shell rc
170+ if ! grep -q " $INSTALL_DIR " " $shell_rc " ; then
171+ echo " " >> " $shell_rc "
172+ echo " # FileFusion" >> " $shell_rc "
173+ echo " $path_export " >> " $shell_rc "
174+ echo " Updated $shell_rc "
175+ else
176+ echo " $shell_rc already contains FileFusion path"
177+ fi
178+ }
179+
180+ # Function to update PowerShell profile on Windows
181+ update_powershell_profile () {
182+ local profile_dir=" $HOME /Documents/PowerShell"
183+ local profile_path=" $profile_dir /Microsoft.PowerShell_profile.ps1"
184+
185+ mkdir -p " $profile_dir "
186+
187+ if [ ! -f " $profile_path " ] || ! grep -q " $INSTALL_DIR " " $profile_path " ; then
188+ echo " " >> " $profile_path "
189+ echo " # FileFusion" >> " $profile_path "
190+ echo " \$ env:Path += \" ;$INSTALL_DIR \" " >> " $profile_path "
191+ echo " Updated PowerShell profile"
192+ else
193+ echo " PowerShell profile already contains FileFusion path"
194+ fi
195+ }
196+
197+ # Main installation process
198+ main () {
199+ local platform
200+ platform=" $( detect_platform) "
201+
202+ echo " Installing FileFusion for $platform ..."
203+
204+ # Download and extract the release
205+ download_release " $platform "
206+
207+ # Make binary executable (not needed for Windows)
208+ if [[ " $platform " != windows* ]]; then
209+ chmod +x " $INSTALL_DIR /filefusion"
210+ fi
211+
212+ # Update shell configuration
213+ if [ -z " $SKIP_RC " ]; then
214+ if [[ " $platform " == windows* ]]; then
215+ update_powershell_profile
216+ # Also update shell rc for Git Bash/MSYS2 if applicable
217+ if [ -n " $BASH_VERSION " ]; then
218+ update_shell_rc " $( get_shell_rc) "
219+ fi
220+ else
221+ update_shell_rc " $( get_shell_rc) "
222+ fi
223+ fi
224+
225+ echo " FileFusion installed successfully!"
226+ echo " To start using FileFusion, either:"
227+ echo " 1. Restart your terminal"
228+ echo " 2. Run: source $( get_shell_rc) "
229+ }
230+
231+ # Run the installer
232+ main
0 commit comments