-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-runner
executable file
·65 lines (48 loc) · 1.8 KB
/
update-runner
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
#!/bin/bash
update_local_file() {
local url="$1"
local local_file="$2"
content=$(curl -s $url)
new_lines=""
while IFS= read -r line; do
key=$(echo $line | cut -d'=' -f1)
if ! grep -q "$key" $local_file; then
new_lines="$new_lines$line\n"
fi
done <<< "$content"
echo -e "$new_lines" >> $local_file
}
# Get meta data from the latest release
echo "Looking for the latest release..."
json=$(curl -s https://api.github.com/repos/cophilot/msh/releases/latest)
# get the tag name of the latest release
version=$(echo $json | grep -Po '"tag_name": "\K.*?(?=")')
echo "Found version: $version"
# Add myshell script
echo "Adding msh..."
url=https://github.com/cophilot/msh/releases/download/$version/msh
curl -sL $url > bin/msh
chmod +x bin/msh
# Add scripts
echo "Adding scripts..."
curl -s https://raw.githubusercontent.com/cophilot/msh/main/uninstall > bin/msh-uninstall
chmod +x bin/msh-uninstall
curl -s https://raw.githubusercontent.com/cophilot/msh/main/update > bin/msh-update
chmod +x bin/msh-update
curl -s https://raw.githubusercontent.com/cophilot/msh/main/mshx > bin/mshx
chmod +x bin/mshx
if [ ! -f .conf ]; then
curl -s https://raw.githubusercontent.com/cophilot/msh/main/.conf.template > .conf
else
update_local_file "https://raw.githubusercontent.com/cophilot/msh/main/.conf.template" ".conf"
fi
if [ ! -f .mshrc ]; then
curl -s https://raw.githubusercontent.com/cophilot/msh/main/.mshrc.template > .mshrc
chmod +x .mshrc
else
# Remove all duplicates lines
file_to_remove_duplicates=".mshrc"
awk '!seen[$0]++' "$file_to_remove_duplicates" > temp_file && mv temp_file "$file_to_remove_duplicates"
fi
curl -s https://raw.githubusercontent.com/cophilot/msh/main/LICENSE > LICENSE
echo "myshell has been updated to version $version"