-
Notifications
You must be signed in to change notification settings - Fork 0
/
haikurev.sh
executable file
·144 lines (118 loc) · 3.99 KB
/
haikurev.sh
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
if [ -z "$SCRIPT_DIR" ]
then
#Find script original dir even if called with a symlink
export SCRIPT_DIR="$( cd "$( dirname "$(readlink -f "${BASH_SOURCE[0]}" )" )" && pwd )"
#
fi
# Retrieve the active hrev value using uname -a
# how do I find the r1~beta4_ string from the current install ?
clear
nblines=20
stable='r1beta5'
basever='r1~beta5_'
active_build=$basever$(uname -a | grep -o 'hrev[0-9]*' )
uname_output=$(uname -a)
if [[ $uname_output == *x86_64* ]]; then
url="https://eu.hpkg.haiku-os.org/haiku/master/x86_64"
elif [[ $uname_output == *x86_gcc2* ]]; then
url="https://eu.hpkg.haiku-os.org/haiku/master/x86_gcc2"
else
echo "Unsupported architecture, please fix the script to support this"
exit 1
fi
echo "----------------------------"
echo "Active build: $active_build"
echo "----------------------------"
echo "Fetching versions from:"
echo $url
# Fetch the content from the URL and extract the 10 most recent version numbers
content=$(curl --connect-timeout 20 -s $url)
if [ -z "$content" ]; then
echo "Ooops - server responded with empty string. Maybe a timeout"
exit 1
fi
versions=$(echo "$content" | grep -a -o '"r1~beta[0-9]_hrev[0-9]*"' | sed 's/"//g' | sort -r | head -n $nblines)
versions="stable"$'\n'"current"$'\n'"$versions"
IFS=$'\n' read -r -d '' -a versions_array <<< "$versions"
selected_index=0
while true; do
clear
echo "----------------------------"
echo "Pick Haiku Revision to install"
echo "----------------------------"
echo "If anything goes wrong go back to stable"
echo "Current will enable UNSTABLE nightly builds"
echo "Pick a hrev to test and keep a specific build"
echo "----------------------------"
echo
# Display the version numbers with index
for i in "${!versions_array[@]}"; do
if [ "${versions_array[i]}" == "$active_build" ]; then
if [ $i -eq $selected_index ]; then
echo "> ${versions_array[i]} (Installed)"
else
echo " ${versions_array[i]} (Installed)"
fi
elif [ $i -eq $selected_index ]; then
echo "> ${versions_array[i]}"
else
echo " ${versions_array[i]}"
fi
done
read -rsn1 input
case "$input" in
"A") # Up arrow key
selected_index=$((selected_index - 1))
;;
"B") # Down arrow key
selected_index=$((selected_index + 1))
;;
"") # Enter key
selected_version="${versions_array[selected_index]}"
break
;;
esac
# Check bounds limits
if [ $selected_index -lt 0 ]; then
selected_index=0
elif [ $selected_index -ge ${#versions_array[@]} ]; then
selected_index=$(( ${#versions_array[@]} - 1 ))
fi
done
# Extract the part after "hrev" and print it
hrev=$(echo "$selected_version" | sed 's/.*hrev//')
if [ "$hrev" != "current" ] && [ "$hrev" != "stable" ]; then
tag=hrev$hrev
source $SCRIPT_DIR/haikuchanges.sh
fi
# Prompt user to launch next command
read -p "Do you want to proceed installing Haiku revision $hrev (y/n): " choice
echo
if [[ $choice == "y" || $choice == "Y" ]]; then
echo "----------------------------"
echo "Installing revision: $hrev"
echo "----------------------------"
if [ "$hrev" = "stable" ]; then
upurl="https://eu.hpkg.haiku-os.org/haiku/$stable/$(getarch)/current"
elif [ "$hrev" = "current" ]; then
upurl="https://eu.hpkg.haiku-os.org/haiku/master/$(getarch)/current"
else
upurl="https://eu.hpkg.haiku-os.org/haiku/master/$(getarch)/$basever"hrev"$hrev"
fi
pkgman add $upurl
pkgman full-sync
echo
echo "----------------------------"
read -p "Do you want to reboot now ? (y/n)" choice
echo "----------------------------"
echo
if [[ $choice == "y" || $choice == "Y" ]]; then
echo "Rebooting now..."
shutdown -r -s
else
echo "Ok. But one day you will have to reboot. We all do."
fi
else
echo "Exiting..."
fi