-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit.sh
More file actions
77 lines (63 loc) · 1.63 KB
/
git.sh
File metadata and controls
77 lines (63 loc) · 1.63 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
#!/usr/bin/env bash
set -euo pipefail
# ---------- helpers ----------
log() { echo -e "\n==> $*"; }
if [[ "${EUID}" -ne 0 ]]; then
echo "Please run as root: sudo $0"
exit 1
fi
TARGET_USER="${SUDO_USER:-}"
if [[ -z "${TARGET_USER}" || "${TARGET_USER}" == "root" ]]; then
TARGET_USER="root"
fi
TARGET_HOME="$(eval echo "~${TARGET_USER}")"
# ---------- install git ----------
log "Installing Git..."
apt-get update -y
apt-get install -y git
# ---------- configure git ----------
log "Git installed: $(git --version)"
# Create global gitignore
log "Creating global .gitignore..."
cat > "${TARGET_HOME}/.gitignore_global" <<'EOF'
# OS
.DS_Store
Thumbs.db
# IDE
.idea/
.vscode/
*.swp
*.swo
*~
# Logs
*.log
# Environment
.env
.env.local
# Dependencies
node_modules/
vendor/
__pycache__/
*.pyc
EOF
chown "${TARGET_USER}:${TARGET_USER}" "${TARGET_HOME}/.gitignore_global"
# Configure git to use global gitignore
sudo -u "${TARGET_USER}" git config --global core.excludesfile "${TARGET_HOME}/.gitignore_global"
# Set some useful defaults
sudo -u "${TARGET_USER}" git config --global init.defaultBranch main
sudo -u "${TARGET_USER}" git config --global pull.rebase false
sudo -u "${TARGET_USER}" git config --global core.autocrlf input
log "Done."
echo ""
echo "=========================================="
echo " Git Installation Complete!"
echo "=========================================="
echo ""
echo "Version: $(git --version)"
echo ""
echo "Configure your identity:"
echo " git config --global user.name 'Your Name'"
echo " git config --global user.email 'you@example.com'"
echo ""
echo "Global gitignore: ${TARGET_HOME}/.gitignore_global"
echo ""