/ programs / x86_64 / libreoffice
libreoffice
  1  #!/bin/sh
  2  
  3  # AM INSTALL SCRIPT VERSION 3. 
  4  set -u
  5  APP=libreoffice
  6  SITE="https://www.libreoffice.org"
  7  
  8  # CREATE DIRECTORIES AND ADD REMOVER
  9  [ -n "$APP" ] && mkdir -p "/opt/$APP/icons" "/opt/$APP/tmp" && cd "/opt/$APP/tmp" || exit 1
 10  printf "#!/bin/sh\nset -e\nrm -f /usr/local/bin/$APP\nrm -R -f /opt/$APP" > "/opt/$APP/remove"
 11  printf '\n%s' "rm -f /usr/local/share/applications/$APP*-AM.desktop" >> "/opt/$APP/remove"
 12  chmod a+x "/opt/$APP/remove"
 13  
 14  _release_still() {
 15  	chooseone=" tail -1 "
 16  	release=$(wget -q https://www.libreoffice.org/download/download-libreoffice -O - | tr '<' '\n' | grep dl_version | sed 's:.*>::' | tail -1)
 17  	version=$(wget -q https://appimages.libreitalia.org/ -O - | tr '"' '\n' | grep -oi "libreoffice-.*appimage$" | grep -v ">\|LibreOffice-fresh\|LibreOffice-still" | sort -t- -k1,1V -k2,2V -k3,3V -k4,4V | grep "$edition" | grep "$release" | tail -1 )
 18  }
 19  
 20  _release_fresh() {
 21  	chooseone=" head -1 "
 22  	release=$(wget -q https://www.libreoffice.org/download/download-libreoffice -O - | tr '<' '\n' | grep dl_version | sed 's:.*>::' | head -1)
 23  	version=$(wget -q https://appimages.libreitalia.org/ -O - | tr '"' '\n' | grep -oi "libreoffice-.*appimage$" | grep -v ">\|LibreOffice-fresh\|LibreOffice-still" | sort -t- -k1,1V -k2,2V -k3,3V -k4,4V | grep "$edition" | grep "$release" | tail -1 )
 24  }
 25  
 26  # CHOOSE A VERSION
 27  
 28  read -r -p " Please choose a LibreOffice edition:
 29  
 30   - STILL is slightly older but tested longer.
 31   - FRESH includes all the latest features.
 32   - BASIC only supports English (US and GB).
 33   - STANDARD includes English (US/GB), Arabic, Chinese (Simplified and 
 34     Traditional), French, German, Italian, Japanese, Korean, Portuguese 
 35     (BR/PT), Russian, and Spanish.
 36   - FULL includes all supported languages.
 37  
 38   1) Still-basic			2) Still-basic with manuals
 39   3) Still-standard		4) Still-standard with manuals
 40   5) Still-full			6) Still-full with manuals
 41   7) Fresh-basic			8) Fresh-basic with manuals
 42   9) Fresh-standard		10) Fresh-standard with manuals
 43   11) Fresh-full			12) Fresh-full with manuals
 44  
 45   Type a number from the above list and press ENTER: " response
 46  case "$response" in
 47  	1)	rm -f /opt/"$APP"/version
 48  		edition="basic-x86_64"
 49  		_release_still 2> /dev/null 
 50  		wget "https://appimages.libreitalia.org/$version" -O "$APP"
 51  		wget "https://appimages.libreitalia.org/$version".zsync -O "$APP".zsync 2> /dev/null
 52  		echo "$version" >> "/opt/$APP/version";;
 53  	2)	rm -f /opt/"$APP"/version
 54  		edition="basic.help-x86_64"
 55  		_release_still 2> /dev/null 
 56  		wget "https://appimages.libreitalia.org/$version" -O "$APP"
 57  		wget "https://appimages.libreitalia.org/$version".zsync -O "$APP".zsync 2> /dev/null
 58  		echo "$version" >> "/opt/$APP/version";;
 59  	3)	rm -f /opt/"$APP"/version
 60  		edition="standard-x86_64"
 61  		_release_still 2> /dev/null 
 62  		wget "https://appimages.libreitalia.org/$version" -O "$APP"
 63  		wget "https://appimages.libreitalia.org/$version".zsync -O "$APP".zsync 2> /dev/null
 64  		echo "$version" >> "/opt/$APP/version";;
 65  	4)	rm -f /opt/"$APP"/version
 66  		edition="standard.help-x86_64"
 67  		_release_still 2> /dev/null 
 68  		wget "https://appimages.libreitalia.org/$version" -O "$APP"
 69  		wget "https://appimages.libreitalia.org/$version".zsync -O "$APP".zsync 2> /dev/null
 70  		echo "$version" >> "/opt/$APP/version";;
 71  	5)	rm -f /opt/"$APP"/version
 72  		edition="full-x86_64"
 73  		_release_still 2> /dev/null 
 74  		wget "https://appimages.libreitalia.org/$version" -O "$APP"
 75  		wget "https://appimages.libreitalia.org/$version".zsync -O "$APP".zsync 2> /dev/null
 76  		echo "$version" >> "/opt/$APP/version";;
 77  	6)	rm -f /opt/"$APP"/version
 78  		edition="full.help-x86_64"
 79  		_release_still 2> /dev/null 
 80  		wget "https://appimages.libreitalia.org/$version" -O "$APP"
 81  		wget "https://appimages.libreitalia.org/$version".zsync -O "$APP".zsync 2> /dev/null
 82  		echo "$version" >> "/opt/$APP/version";;
 83  	7)	rm -f /opt/"$APP"/version
 84  		edition="basic-x86_64"
 85  		_release_fresh 2> /dev/null 
 86  		wget "https://appimages.libreitalia.org/$version" -O "$APP"
 87  		wget "https://appimages.libreitalia.org/$version".zsync -O "$APP".zsync 2> /dev/null
 88  		echo "$version" >> "/opt/$APP/version";;
 89  	8)	rm -f /opt/"$APP"/version
 90  		edition="basic.help-x86_64"
 91  		_release_fresh 2> /dev/null 
 92  		wget "https://appimages.libreitalia.org/$version" -O "$APP"
 93  		wget "https://appimages.libreitalia.org/$version".zsync -O "$APP".zsync 2> /dev/null
 94  		echo "$version" >> "/opt/$APP/version";;
 95  	9)	rm -f /opt/"$APP"/version
 96  		edition="standard-x86_64"
 97  		_release_fresh 2> /dev/null 
 98  		wget "https://appimages.libreitalia.org/$version" -O "$APP"
 99  		wget "https://appimages.libreitalia.org/$version".zsync -O "$APP".zsync 2> /dev/null
100  		echo "$version" >> "/opt/$APP/version";;
101  	10)	rm -f /opt/"$APP"/version
102  		edition="standard.help-x86_64"
103  		_release_fresh 2> /dev/null 
104  		wget "https://appimages.libreitalia.org/$version" -O "$APP"
105  		wget "https://appimages.libreitalia.org/$version".zsync -O "$APP".zsync 2> /dev/null
106  		echo "$version" >> "/opt/$APP/version";;
107  	11)	rm -f /opt/"$APP"/version
108  		edition="full-x86_64"
109  		_release_fresh 2> /dev/null 
110  		wget "https://appimages.libreitalia.org/$version" -O "$APP"
111  		wget "https://appimages.libreitalia.org/$version".zsync -O "$APP".zsync 2> /dev/null
112  		echo "$version" >> "/opt/$APP/version";;
113  	12)	rm -f /opt/"$APP"/version
114  		edition="full.help-x86_64"
115  		_release_fresh 2> /dev/null 
116  		wget "https://appimages.libreitalia.org/$version" -O "$APP"
117  		wget "https://appimages.libreitalia.org/$version".zsync -O "$APP".zsync 2> /dev/null
118  		echo "$version" >> "/opt/$APP/version";;
119  	''|*)	mkdir -p "/opt/$APP/tmp";;
120  esac
121  cd ..
122  mv "/opt/$APP/tmp/$APP" "/opt/$APP/$APP" 2> /dev/null || exit 1
123  mv "/opt/$APP/tmp/$APP.zsync" "/opt/$APP/$APP.zsync" 2> /dev/null || exit 1
124  if test -f "/opt/$APP/$APP"; then rmdir ./tmp  || exit 1; fi 
125  chmod a+x "/opt/$APP/$APP" 2> /dev/null || exit 1
126  
127  # LINK
128  ln -s "/opt/$APP/$APP" "/usr/local/bin/$APP"
129  
130  # SCRIPT TO UPDATE THE PROGRAM
131  cat >> "/opt/$APP/AM-updater" << 'EOF'
132  #!/bin/sh
133  set -u
134  APP=libreoffice
135  SITE="https://www.libreoffice.org"
136  version0=$(cat "/opt/$APP/version")
137  edition="EDITION"
138  release=$(wget -q https://www.libreoffice.org/download/release-notes/ -O - | tr '>' '\n' | grep -i "^LibreOffice [0-9]*" | grep " Release" | tr ' ' '\n' | grep "^[0-9]" | RELEASE)
139  version=$(wget -q https://appimages.libreitalia.org/ -O - | tr '"' '\n' | grep -oi "libreoffice-.*appimage$" | grep -v ">\|LibreOffice-fresh\|LibreOffice-still" | sort -t- -k1,1V -k2,2V -k3,3V -k4,4V | grep "$edition" | grep "$release" | tail -1 )
140  [ -n "$version" ] || { echo "Error getting link"; exit 1; }
141  if [ "$version" != "$version0" ] || [ -e /opt/"$APP"/*.zsync ]; then
142  	mkdir "/opt/$APP/tmp" && cd "/opt/$APP/tmp" || exit 1
143  	[ -e /opt/"$APP"/*.zsync ] || notify-send "A new version of $APP is available, please wait"
144  	[ -e /opt/"$APP"/*.zsync ] && wget "https://appimages.libreitalia.org/$version.zsync" 2>/dev/null || { wget "https://appimages.libreitalia.org/$version" || exit 1; }
145  	# Use tar fx ./*tar* here for example in this line in case a compressed file is downloaded.
146  	cd ..
147  	mv ./tmp/*.zsync ./"$APP".zsync 2>/dev/null || mv --backup=t ./tmp/*mage ./"$APP"
148  	[ -e /opt/"$APP"/*.zsync ] && { zsync "/opt/$APP/$APP.zsync" || notify-send -u critical "zsync failed to update $APP"; }
149  	chmod a+x "/opt/$APP/$APP" || exit 1
150  	echo "$version" > ./version
151  	rm -R -f ./*zs-old ./*.part ./tmp ./*~
152  	notify-send "$APP is updated!"
153  else
154  	echo "Update not needed!"
155  fi
156  EOF
157  sed -i 's#EDITION#'"$edition"'#g; s#RELEASE#'"$chooseone"'#g; s###g' "/opt/$APP/AM-updater"
158  chmod a+x "/opt/$APP/AM-updater"
159  
160  # ICONS
161  cd "/opt/$APP" || exit 1
162  mv $(./libreoffice --appimage-extract usr/share/icons/hicolor/scalable/apps/*.svg) ./icons 2> /dev/null
163  RELEASE=$(ls ./icons | head -1 | rev | cut -c 10- | rev)
164  mv ./icons/"$RELEASE"-base* ./icons/"$APP"-base 2> /dev/null
165  mv ./icons/"$RELEASE"-basic* ./icons/"$APP"-basic 2> /dev/null
166  mv ./icons/"$RELEASE"-calc* ./icons/"$APP"-calc 2> /dev/null
167  mv ./icons/"$RELEASE"-chart* ./icons/"$APP"-chart 2> /dev/null
168  mv ./icons/"$RELEASE"-draw* ./icons/"$APP"-draw 2> /dev/null
169  mv ./icons/"$RELEASE"-extension* ./icons/"$APP"-extension 2> /dev/null
170  mv ./icons/"$RELEASE"-impress* ./icons/"$APP"-impress 2> /dev/null
171  mv ./icons/"$RELEASE"-main* ./icons/"$APP"-main 2> /dev/null
172  mv ./icons/"$RELEASE"-math* ./icons/"$APP"-math 2> /dev/null
173  mv ./icons/"$RELEASE"-startcenter* ./icons/"$APP"-startcenter 2> /dev/null
174  mv ./icons/"$RELEASE"-writer* ./icons/"$APP"-writer 2> /dev/null
175  
176  # LAUNCHERS
177  mv $(./libreoffice --appimage-extract opt/libreoffice*/share/xdg) . 2> /dev/null
178  cd ./xdg || exit 1
179  for f in *.desktop ; do mv "$f" "$APP-${f%.desktop}-AM.desktop"; done
180  sed -i "s# $(echo $RELEASE | cut -c 12-) # #g; s#Icon=$APP#Icon=/opt/$APP/icons/$APP#g; s#$RELEASE#$APP#g" *
181  sed -i '/Name=LibreOffice/c\Name=LibreOffice' ./*startcenter-AM.desktop
182  cd ..
183  mv ./xdg/* /usr/local/share/applications/ 2> /dev/null
184  rm -R -f ./squashfs-root ./xdg