-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·87 lines (72 loc) · 2.63 KB
/
Copy pathbootstrap.sh
File metadata and controls
executable file
·87 lines (72 loc) · 2.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
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env bash
set -e
# === CONFIGURATION ===
REPO_NAME="linux" # <-- Change to your repo name
REPO_URL="https://github.com/tefloon/$REPO_NAME.git"
# === 1. Install git if needed ===
if ! command -v git >/dev/null 2>&1; then
echo "Installing git..."
pacman -Sy --noconfirm git
fi
# === 2. Determine username ===
if [[ -n "$SUDO_USER" && "$SUDO_USER" != "root" ]]; then
USERNAME="$SUDO_USER"
else
USERNAME=$(ls /home | head -n 1)
fi
USER_HOME="/home/$USERNAME"
# === 3. Clone repo to user's home directory ===
cd "$USER_HOME"
if [[ ! -d "$REPO_NAME" ]]; then
git clone "$REPO_URL"
else
echo "Repository $REPO_NAME already exists in $USER_HOME"
fi
# === 4. Set correct ownership and permissions ===
chown -R $USERNAME:$USERNAME "$REPO_NAME"
# Make all scripts executable if they exist
if compgen -G "$REPO_NAME/scripts/*" > /dev/null; then
chmod +x "$REPO_NAME/scripts/"*
fi
if [[ -f "$REPO_NAME/setup.sh" ]]; then
chmod +x "$REPO_NAME/setup.sh"
fi
# Make dotfiles and configs readable/writable, not executable
if [[ -d "$REPO_NAME/dotfiles" ]]; then
find "$REPO_NAME/dotfiles" -type f -exec chmod 644 {} \;
fi
add_fstab_entry() {
local line="$1"
if ! grep -qxF "$line" /etc/fstab; then
echo "$line" | sudo tee -a /etc/fstab > /dev/null
fi
}
echo "Adding drives to /etc/fstab"
add_fstab_entry "UUID=3ECEEACFCEEA7F11 /mnt/backups ntfs-3g uid=1000,gid=1000,umask=003 0 0"
add_fstab_entry "UUID=243C543D3C540BE4 /mnt/chmury ntfs-3g uid=1000,gid=1000,umask=003 0 0"
add_fstab_entry "UUID=A8426D93426D6752 /mnt/projects ntfs-3g uid=1000,gid=1000,umask=003 0 0"
add_fstab_entry "UUID=06E8FAA9E8FA9661 /mnt/dane ntfs-3g uid=1000,gid=1000,umask=003 0 0"
add_fstab_entry "UUID=5402FCC602FCADDC /mnt/zainstalowane ntfs-3g uid=1000,gid=1000,umask=003 0 0"
# === 5. Creating symlinks in the home folder ===
USER_HOME="/home/$USERNAME"
ln -sf /mnt/chmury $USER_HOME/
ln -sf /mnt/dane $USER_HOME/
ln -sf /mnt/projects $USER_HOME/
ln -sf /mnt/zainstalowane $USER_HOME/
ln -sf /mnt/backups $USER_HOME/
# === 6. Run the main setup as the user ===
cd "$REPO_NAME"
sudo -u $USERNAME ./setup.sh
# === 7. Setup git remote to use SSH (personal preference) ===
echo "Setting up git remote to use SSH..."
cd "$USER_HOME/$REPO_NAME"
current_url=$(sudo -u $USERNAME git remote get-url origin 2>/dev/null || echo "")
if [[ "$current_url" != git@github.com:* ]]; then
if sudo -u $USERNAME git remote set-url origin "git@github.com:tefloon/linux.git"; then
echo "✓ Git remote updated to use SSH"
else
echo "⚠ Failed to update git remote (will use HTTPS)"
fi
else
echo "✓ Git remote already using SSH"
fi