mirror of
https://github.com/Matir/skel.git
synced 2026-05-25 21:19:09 -07:00
Cleanups
This commit is contained in:
70
clone.sh
70
clone.sh
@@ -2,22 +2,68 @@
|
||||
|
||||
set -ue
|
||||
|
||||
# Script to clone and install
|
||||
# --- Helper function to install git ---
|
||||
install_git() {
|
||||
echo "Git not found. Attempting to install..." >&2
|
||||
case "$(uname)" in
|
||||
Darwin)
|
||||
if command -v brew >/dev/null 2>&1; then
|
||||
echo "Using Homebrew to install git..." >&2
|
||||
brew install git
|
||||
else
|
||||
echo "Error: Homebrew not found on your macOS system." >&2
|
||||
echo "Please install Homebrew first by visiting https://brew.sh/ then run this script again." >&2
|
||||
return 1
|
||||
fi
|
||||
;;
|
||||
Linux)
|
||||
if command -v apt-get >/dev/null 2>&1; then
|
||||
echo "Using apt-get to install git..." >&2
|
||||
if [ "${EUID:-$(id -u)}" -ne 0 ]; then
|
||||
sudo apt-get update && sudo apt-get install -y git
|
||||
else
|
||||
apt-get update && apt-get install -y git
|
||||
fi
|
||||
else
|
||||
echo "Error: This script requires 'apt-get' on Linux to install git." >&2
|
||||
echo "Please install git using your system's package manager and run this script again." >&2
|
||||
return 1
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Error: Unsupported operating system '$(uname)'." >&2
|
||||
echo "Please install git manually and run this script again." >&2
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Wrapped in a function to prevent incomplete execution if download is
|
||||
# interrupted
|
||||
function installer_main {
|
||||
if ! command -v git >/dev/null 2>&1 ; then
|
||||
( if [ "$EUID" != 0 ] ; then
|
||||
sudo apt install -y git
|
||||
else
|
||||
apt install -y git
|
||||
fi ) || ( echo 'Failed to install git!' >/dev/stderr; false)
|
||||
# --- Main script logic ---
|
||||
installer_main() {
|
||||
# 1. Check for git, and try to install it if it's missing.
|
||||
if ! command -v git >/dev/null 2>&1; then
|
||||
install_git
|
||||
# Final check after attempting installation
|
||||
if ! command -v git >/dev/null 2>&1; then
|
||||
echo "ERROR: git installation failed or was not found." >&2
|
||||
echo "Please install git manually and re-run this script." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
git clone --depth 1 https://github.com/Matir/skel.git ${HOME}/.skel
|
||||
# 2. Clone the repository if it doesn't exist
|
||||
local dest="${HOME}/.skel"
|
||||
if [ -d "${dest}" ]; then
|
||||
echo "Repository already exists in ${dest}. Skipping clone." >&2
|
||||
else
|
||||
echo "Cloning repository..." >&2
|
||||
git clone --depth 1 https://github.com/Matir/skel.git "${dest}"
|
||||
fi
|
||||
|
||||
${HOME}/.skel/install.sh
|
||||
# 3. Run the main installer
|
||||
echo "Running main installer..." >&2
|
||||
"${dest}/install.sh"
|
||||
}
|
||||
|
||||
installer_main
|
||||
|
||||
|
||||
Reference in New Issue
Block a user