-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-template.sh
More file actions
executable file
·122 lines (103 loc) · 3.9 KB
/
setup-template.sh
File metadata and controls
executable file
·122 lines (103 loc) · 3.9 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
#!/bin/bash
# Setup script for presentation template
# This script customizes the template for a new presentation
set -e
echo "🎯 Presentation Template Setup"
echo "==============================="
echo
# Get the current repository name from git remote
REPO_URL=$(git config --get remote.origin.url || echo "")
if [ -n "$REPO_URL" ]; then
# Extract repo name from URL (works for both HTTPS and SSH)
REPO_NAME=$(echo "$REPO_URL" | sed -e 's/.*[:/]\([^/]*\/[^/]*\)\.git$/\1/' -e 's/.*[:/]\([^/]*\/[^/]*\)$/\1/')
OWNER=$(echo "$REPO_NAME" | cut -d'/' -f1)
REPO=$(echo "$REPO_NAME" | cut -d'/' -f2)
else
echo "⚠️ Could not detect git repository. Using defaults."
OWNER="YOUR-USERNAME"
REPO="YOUR-REPO-NAME"
fi
echo "Detected configuration:"
echo " Owner: $OWNER"
echo " Repository: $REPO"
echo
# Prompt for confirmation or custom values
read -p "Is this correct? (y/n) [y]: " CONFIRM
CONFIRM=${CONFIRM:-y}
if [ "$CONFIRM" != "y" ]; then
read -p "Enter GitHub username/organization: " OWNER
read -p "Enter repository name: " REPO
fi
read -p "Enter presentation title [$REPO]: " TITLE
TITLE=${TITLE:-"$REPO"}
# Replace placeholders in files
echo
echo "📝 Updating files..."
# Function to replace text in files (cross-platform)
replace_in_file() {
local file=$1
local pattern=$2
local replacement=$3
sed "s|$pattern|$replacement|g" "$file" > "$file.tmp" && mv "$file.tmp" "$file"
}
# Update README.md
replace_in_file README.md "YOUR-USERNAME" "$OWNER"
replace_in_file README.md "YOUR-REPO-NAME" "$REPO"
replace_in_file README.md "Presentation Title" "$TITLE"
# Update index.html
replace_in_file index.html "Presentation Title" "$TITLE"
replace_in_file index.html "slides/presentation.md" "slides/$REPO.md"
# Update package.json
replace_in_file package.json "\"name\": \"presentation-template\"" "\"name\": \"$REPO\""
# Rename the markdown file
if [ -f "slides/presentation.md" ]; then
mv "slides/presentation.md" "slides/$REPO.md"
echo "✅ Renamed slides/presentation.md to slides/$REPO.md"
elif [ -f "slides/ddev-linux-10-minutes.md" ]; then
mv "slides/ddev-linux-10-minutes.md" "slides/$REPO.md"
echo "✅ Renamed slides/ddev-linux-10-minutes.md to slides/$REPO.md"
fi
# Update title inside the markdown file
if [ -f "slides/$REPO.md" ]; then
replace_in_file "slides/$REPO.md" "Your Presentation Title" "$TITLE"
fi
# Configure repository settings via gh CLI if available
SETTINGS_INSTRUCTIONS=" Set these manually in Settings > General:
• Merge button: enable squash merging only (disable merge commits and rebase)
• Automatically delete head branches: enable"
if ! command -v gh &>/dev/null; then
echo "ℹ️ gh CLI not found — $SETTINGS_INSTRUCTIONS"
elif ! gh auth status &>/dev/null 2>&1; then
echo "ℹ️ gh CLI not authenticated — $SETTINGS_INSTRUCTIONS"
else
echo "⚙️ Configuring repository settings..."
if gh api "repos/$OWNER/$REPO" \
--method PATCH \
-f delete_branch_on_merge=true \
-f allow_squash_merge=true \
-f allow_merge_commit=false \
-f allow_rebase_merge=false \
--silent 2>&1; then
echo "✅ Repository settings configured (squash-only, auto-delete branches)"
else
echo "⚠️ Could not configure repository settings (insufficient permissions?) —"
echo "$SETTINGS_INSTRUCTIONS"
fi
fi
# Self-destruct: remove this setup script
echo
echo "🎉 Setup complete!"
echo
echo "Next steps:"
echo " 1. Edit slides/$REPO.md with your presentation content"
echo " 2. Customize css/custom.css if needed"
echo " 3. Add images to the images/ directory"
echo " 4. Commit and push your changes"
echo " 5. Enable GitHub Pages in repository settings (Settings > Pages > Deploy from main branch)"
echo
read -p "Remove this setup script? (y/n) [y]: " REMOVE
REMOVE=${REMOVE:-y}
if [ "$REMOVE" = "y" ]; then
rm -- "$0"
echo "✅ Setup script removed"
fi