s243a

update-firefox.sh (hach - fatdog64 - puppylinux)

Jan 15th, 2016
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.78 KB | None | 0 0
  1. #!/bin/dash
  2. # update firefox to latest official version
  3. # jamesbond 2015
  4. # MIT license
  5. # L18L internationalized to get also localized version
  6.  
  7. export TEXTDOMAIN=get_app
  8.  
  9. ### config
  10. APPTITLE="$(gettext 'Update Firefox')"
  11. WORKDIR=/tmp/update-firefox.$$
  12.  
  13. ### generic helpers
  14. get_config() {
  15.     if [ $(id -u) -ne 0 ]; then
  16.         msg "$(gettext 'You must be root.')"
  17.         exit 1
  18.     fi
  19.    
  20.     LIBDIR=lib64 # lib for 32-bit
  21.     ARCH=x86_64 # i686 for 32-bit
  22.     FFCHANNEL=latest # or latest-esr
  23.     #FF_DOWNLOAD_PATH_DIR="http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/$FFCHANNEL/linux-$ARCH/"
  24.     FF_DOWNLOAD_PATH_DIR='https://download.mozilla.org/?product=firefox-latest&os=linux64&lang=en-US'
  25.  
  26.     #FFLANG=en-US # or others
  27.     read FFLANG < ${FATDOG_STATE_DIR}/language ; FFLANG=${FFLANG%.*}
  28.     # FFLANG=${FFLANG//_/-} # dash cannot do this
  29.     FFLANG=`echo ${FFLANG} | tr '_' '-'`
  30.     [ "`wget --spider -S ${FF_DOWNLOAD_PATH_DIR}${FFLANG} 2>&1| grep '404 Not Found'`" ] && FFLANG=${FFLANG%-*}
  31.     [ "`wget --spider -S ${FF_DOWNLOAD_PATH_DIR}${FFLANG} 2>&1| grep '404 Not Found'`" ] && FFLANG=en-US
  32.  
  33.      #FF_DOWNLOAD_PATH="http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/$FFCHANNEL/linux-$ARCH/$FFLANG/"
  34.     FF_DOWNLOAD_PATH='https://download.mozilla.org/?product=firefox-latest&os=linux64&lang=en-US'
  35.     #echo FF_DOWNLOAD_PATH=$FF_DOWNLOAD_PATH ; exit # debug only
  36. }
  37.  
  38. # $1-text
  39. msg() {
  40.     [ -z "$DISPLAY" ] && echo "$1" ||
  41.     Xdialog --title "$APPTITLE" --infobox "$1" 0 0 10000
  42. }
  43.  
  44. # $1-text, returns true/false
  45. yesno() {
  46.     local p
  47.     if [ -z "$DISPLAY" ]; then
  48.         printf "%s\nType [yes] to continue: " "$1"
  49.         read p
  50.         case "$p" in
  51.             [Yy][Ee][Ss]) return 0
  52.         esac
  53.         return 1
  54.     else
  55.         Xdialog --title "$APPTITLE" --yesno "$1" 0 0
  56.     fi
  57. }
  58.  
  59. # $1-text
  60. splash() {
  61.     if [ -z "$DISPLAY" ]; then
  62.         echo "$1"
  63.     else
  64.         if [ "$1" ]; then
  65.             [ $SPID ] && kill $SPID
  66.             Xdialog --title "$APPTITLE" --no-buttons --infobox "$1" 0 0 10000000 &
  67.             SPID=$!
  68.         else
  69.             [ $SPID ] && kill $SPID
  70.             SPID=""
  71.         fi
  72.     fi
  73. }
  74. function ff_version(){
  75. while read line
  76. do
  77.   tmp=$(echo "$line" | sed -nr 's|.*firefox-(.*)\.tar\.bz2.*|\1|p')
  78.   #echo "$line"
  79.   if [ ${#tmp} -gt 0 ]; then
  80.     echo "$tmp"
  81.     break
  82.   fi
  83. done
  84. }
  85. ### firefox stuff
  86. get_latest_version() {
  87.     #wget -q --trust-server-names -O - "$FF_DOWNLOAD_PATH" |
  88.     #sed -nr 's|.*>firefox-(.*)\.tar\.bz2</a>.*|\1|p'
  89.     wget --trust-server-names --timeout=10 -o /dev/stdout -O /dev/null "$FF_DOWNLOAD_PATH" | ff_version
  90.     #wget -O - "$FF_DOWNLOAD_PATH" |
  91.  
  92. }
  93.  
  94. get_current_version() {
  95.     ls -ld /usr/lib64/firefox-* | tail -n 1 | sed 's/.*firefox-//'
  96. }
  97.  
  98. # $1-version $2-path
  99. download_firefox() {
  100.     #wget -qO $2 "${FF_DOWNLOAD_PATH}firefox-${1}.tar.bz2"
  101.     wget --trust-server-names -q -O $2 "$FF_DOWNLOAD_PATH"
  102. }
  103.  
  104. # $1-version
  105. package_firefox() {
  106.     splash "$(eval echo `gettext 'Making firefox $1 package, the package will be stored in $HOME'`)"
  107.     mkdir pkg.$$; cd pkg.$$
  108.    
  109.     # extract
  110.     mkdir -p usr/$LIBDIR/ usr/share/pixmaps usr/bin usr/share/applications
  111.     tar -xf ../firefox.tar.bz2 -C usr/$LIBDIR
  112.    
  113.     # setup symlinks, etc
  114.     mv usr/$LIBDIR/firefox usr/$LIBDIR/firefox-$1
  115.     ln -s firefox-$1 usr/$LIBDIR/firefox
  116.     ln -s /usr/$LIBDIR/firefox/firefox usr/bin/firefox
  117.     ln -s /usr/$LIBDIR/firefox-$VERSION/browser/icons/mozicon128.png \
  118.         usr/share/pixmaps/firefox.png &&
  119.    
  120.     # run firefox as spot
  121.     cat << "EOF" >> usr/bin/firefox-spot &&
  122. #!/bin/dash
  123. SPOT_HOME=$(awk -F: '$1=="spot" {print $6}' /etc/passwd)
  124. #{ chown spot $SPOT_HOME/Downloads;
  125. #chown spot /aufs/devsave/Downloads; } 2> /dev/null
  126. cd $SPOT_HOME/Downloads
  127. exec /usr/bin/run-as-spot /usr/bin/firefox "$@"
  128. EOF
  129.     chmod +x usr/bin/firefox-spot &&
  130.    
  131.     # desktop file
  132.     cat << "EOF" > usr/share/applications/firefox.desktop
  133. [Desktop Entry]
  134. Version=1.0
  135. Name=Firefox Browser
  136. GenericName=Web Browser
  137. Comment=Your web, the way you like it
  138. Exec=firefox-spot %U
  139. Icon=firefox.png
  140. Terminal=false
  141. Type=Application
  142. MimeType=text/html;text/xml;application/xhtml+xml;application/vnd.mozilla.xul+xml;text/mml;x-scheme-handler/http;x-scheme-handler/https;
  143. StartupNotify=false
  144. X-MultipleArgs=false
  145. X-Desktop-File-Install-Version=0.16
  146. Categories=WebBrowser;
  147. Encoding=UTF-8
  148. EOF
  149.  
  150.     # desc
  151.     mkdir install
  152.     cat << EOF > install/slack-desc
  153. firefox: firefox $1 (Web browser)  
  154. firefox:  
  155. firefox: Official Firefox web browser from Mozilla.
  156. firefox:
  157. firefox:
  158. firefox:
  159. firefox:
  160. firefox:
  161. firefox:
  162. firefox:
  163. firefox:  
  164. EOF
  165.     # make the pkg
  166.     makepkg -c n -l n $HOME/firefox-$1-$ARCH-official.txz > /dev/null 2>&1
  167. }
  168.  
  169. # $1-version
  170. install_firefox() {
  171.     splash "$(eval echo `gettext 'Upgrading firefox to $1...'`)"
  172.     removepkg firefox
  173.     installpkg $HOME/firefox-$1-$ARCH-official.txz
  174.     splash
  175.     msg "$(gettext 'Done.')"
  176. }
  177.  
  178. #### main
  179. get_config
  180. ! yesno "\
  181. $(gettext 'Running this program may replace your Firefox with the OFFICIAL binary
  182. from Mozila, instead of Fatdog-build one.') $(gettext 'It should work, but in some
  183. rare cases Fatdog may be missing some libraries that prevent this
  184. official from running.') $(gettext 'Are you sure you want to continue?')
  185. " && exit
  186. splash "$(gettext 'Checking latest released version ...')"
  187. CURRENT=$(get_current_version)
  188. LATEST=$(get_latest_version)
  189. splash
  190. #echo CURRENT=$CURRENT LATEST=$LATEST
  191. if [ "$LATEST" = "$CURRENT" ]; then
  192.     msg "$(eval echo `gettext 'You are already running the latest version $LATEST.'`)"
  193. else
  194.     if [ -z $CURRENT ]; then
  195.         ! yesno "$(gettext 'You do not seem to have firefox installed.')
  196. $(gettext 'Do you want to install it?')" && exit
  197.     fi
  198.     splash "$(eval echo `gettext 'Downloading firefox $LATEST, please wait ...'`)"
  199.     mkdir $WORKDIR; cd $WORKDIR
  200.     if download_firefox $LATEST firefox.tar.bz2; then
  201.         package_firefox $LATEST
  202.         install_firefox $LATEST
  203.     else
  204.         splash
  205.         msg "$(gettext 'Failed to download.')"
  206.     fi
  207.     cd; rm -rf $WORKDIR
  208. fi
Advertisement
Add Comment
Please, Sign In to add comment