/ programs / x86_64 / ripgrep
ripgrep
 1  #!/bin/sh
 2  
 3  # AM INSTALL SCRIPT VERSION 3.5
 4  set -u
 5  APP=ripgrep
 6  SITE="BurntSushi/ripgrep"
 7  
 8  # CREATE DIRECTORIES AND ADD REMOVER
 9  [ -n "$APP" ] && mkdir -p "/opt/$APP/tmp" "/opt/$APP/icons" && cd "/opt/$APP/tmp" || exit 1
10  printf "#!/bin/sh\nset -e\nrm -f /usr/local/bin/rg\nrm -R -f /opt/$APP" > ../remove
11  chmod a+x ../remove || exit 1
12  
13  # DOWNLOAD AND PREPARE THE APP, $version is also used for updates
14  version=$(curl -Ls https://api.github.com/repos/"$SITE"/releases | sed 's/[()",{} ]/\n/g' | grep -oi 'https.*x86_64.*unknown.*linux.*musl.*gz$' | head -1)
15  wget "$version" || exit 1
16  [ -e ./*7z ] && 7z x ./*7z && rm -f ./*7z
17  [ -e ./*tar.* ] && tar fx ./*tar.* && rm -f ./*tar.*
18  [ -e ./*zip ] && unzip -qq ./*zip 1>/dev/null && rm -f ./*zip
19  cd ..
20  if [ -d ./tmp/* 2>/dev/null ]; then mv ./tmp/*/* ./; else mv ./tmp/* ./"$APP" 2>/dev/null || mv ./tmp/* ./; fi
21  rm -R -f ./tmp || exit 1
22  echo "$version" > ./version
23  chmod a+x ./rg || exit 1
24  
25  # LINK TO PATH
26  ln -s "/opt/$APP/rg" "/usr/local/bin/rg"
27  
28  # SCRIPT TO UPDATE THE PROGRAM
29  cat >> ./AM-updater << 'EOF'
30  #!/bin/sh
31  set -u
32  APP=ripgrep
33  SITE="BurntSushi/ripgrep"
34  version0=$(cat "/opt/$APP/version")
35  version=$(curl -Ls https://api.github.com/repos/"$SITE"/releases | sed 's/[()",{} ]/\n/g' | grep -oi 'https.*x86_64.*unknown.*linux.*musl.*gz$' | head -1)
36  [ -n "$version" ] || { echo "Error getting link"; exit 1; }
37  if [ "$version" != "$version0" ]; then
38  	mkdir "/opt/$APP/tmp" && cd "/opt/$APP/tmp" || exit 1
39  	notify-send "A new version of $APP is available, please wait"
40  	wget "$version" || exit 1
41  	[ -e ./*7z ] && 7z x ./*7z && rm -f ./*7z
42  	[ -e ./*tar.* ] && tar fx ./*tar.* && rm -f ./*tar.*
43  	[ -e ./*zip ] && unzip -qq ./*zip 1>/dev/null && rm -f ./*zip
44  	cd ..
45  	if [ -d ./tmp/* 2>/dev/null ]; then mv --backup=t ./tmp/*/* ./; else mv --backup=t ./tmp/* ./"$APP" 2>/dev/null || mv --backup=t ./tmp/* ./; fi
46  	chmod a+x ./rg || exit 1
47  	echo "$version" > ./version
48  	rm -R -f ./tmp ./*~
49  	notify-send "$APP is updated!"
50  else
51  	echo "Update not needed!"
52  fi
53  EOF
54  chmod a+x ./AM-updater || exit 1