-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathupdate.sh
More file actions
86 lines (72 loc) Β· 2.78 KB
/
Copy pathupdate.sh
File metadata and controls
86 lines (72 loc) Β· 2.78 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
#!/bin/bash
# Color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
clear
echo -e "${CYAN}"
echo "βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo "β π UPDATING 42 EXAM SHELL β"
echo "βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo -e "${NC}"
echo ""
# Check if git is available
if ! command -v git &> /dev/null; then
echo -e "${RED}β Error: Git is not installed${NC}"
exit 1
fi
# Check if we're in a git repository
if ! git rev-parse --git-dir > /dev/null 2>&1; then
echo -e "${RED}β Error: Not in a git repository${NC}"
exit 1
fi
# Show current branch
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo -e "${BLUE}π Current branch: ${YELLOW}$CURRENT_BRANCH${NC}"
echo ""
# Fetch latest changes
echo -e "${BLUE}π₯ Fetching latest changes from repository...${NC}"
if ! git fetch origin; then
echo -e "${RED}β Failed to fetch${NC}"
exit 1
fi
echo -e "${GREEN}β
Fetch successful${NC}"
echo ""
# Check if there are updates available
BEHIND=$(git rev-list --count HEAD..origin/$CURRENT_BRANCH 2>/dev/null)
if [ "$BEHIND" -eq 0 ]; then
echo -e "${GREEN}β
You are up to date!${NC}"
echo ""
else
echo -e "${YELLOW}π¦ $BEHIND update(s) available${NC}"
echo ""
# Show what will be updated
echo -e "${BLUE}π Changes to be pulled:${NC}"
git log HEAD..origin/$CURRENT_BRANCH --oneline | sed 's/^/ /'
echo ""
# Pull latest changes
echo -e "${BLUE}β¬οΈ Pulling latest changes...${NC}"
if ! git pull origin $CURRENT_BRANCH; then
echo -e "${RED}β Failed to pull${NC}"
exit 1
fi
echo -e "${GREEN}β
Pull successful${NC}"
echo ""
fi
# Update file permissions for tester scripts
echo -e "${BLUE}π Updating file permissions...${NC}"
find .resources -name "tester.sh" -exec chmod +x {} \; 2>/dev/null
echo -e "${GREEN}β
Permissions updated${NC}"
echo ""
# Show final status
echo "βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo -e "${GREEN}${BOLD}β¨ Update Complete!${NC}"
echo "βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo ""
echo -e "${CYAN}Ready to continue? Press enter to return to menu.${NC}"
read -r
cd .resources/main
bash menu.sh