如何集中安装浏览器插件?

如何集中安装浏览器插件?

我在 ubuntu 机器上有 5 个用户,我希望每个用户AdBlock+(以及其他几个用户)都同时使用 FireFox 和 Chrome。

有没有办法避免以 GUI 身份登录并启动两个浏览器并手动安装插件?

答案1

火狐浏览器:

有一种简洁的方法可以做到这一点,只需将 Firefox 配置文件从~/.mozilla/firefox已准备好配置文件的用户 1 的目录(例如,这是安装了 Adblock 等的帐户)复制到用户 2、用户 3……的帐户即可:

sudo mkdir -p /home/user2/.mozilla/firefox 
sudo mkdir -p /home/user3/.mozilla/firefox
sudo cp -rv /home/user1/.mozilla/firefox /home/user2/.mozilla
sudo cp -rv /home/user1/.mozilla/firefox /home/user3/.mozilla
sudo chown -R user2 /home/user2/.mozilla
sudo chown -R user3 /home/user3/.mozilla

我测试了这个,它有效。另一种方法是使用Firefox 同步。但是,如果有任何变化,所有书签和历史记录将保持不变。

铬:

相同的技术也可以用于 Chromium:

sudo mkdir -p /home/user2/.config/chromium 
sudo mkdir -p /home/user3/.config/chromium
sudo cp -rv /home/user1/.config/chromium/Default/ /home/user2/.config/chromium
sudo cp -rv /home/user1/.config/chromium/Default/ /home/user3/.config/chromium
sudo chown -R user2 /home/user2/.config/chromium
sudo chown -R user3 /home/user3/.config/chromium

Chromium 还提供了一个选项,您可以使用 Google 帐户登录,并在 Chromium 安装中保留所有设置、书签和历史记录。但是,与 Firefox 一样,这可能不适合您的需求。

答案2

有一个脚本可以让你为所有 Ubuntu 用户安装 Firefox 附加组件。你必须读这个,这就是功劳所在

#! /bin/bash
#
# Version 0.1
#   http://www.linuxquestions.org/questions/linux-software-2/how-to-install-firefox-extensions-for-all-users-808367/
#   05-22-2010, 04:22 PM
#   Narnie
# Version 0.2
#   24-07-2010
#   Maelvon
# FF-3.6.*


function Usage()
{
  echo ""
  echo "Usage: "
  echo "    add_global_firefox_extension.sh [-hof]"
  echo ""
  echo "OPTIONS:"
  echo "    -o  linux|osx"
  echo "        Operating system (mandatory)"
  echo "    -f  /path/xpi_filename"
  echo "        path to the original xpi file to install in the operating system's global directory (mandatory)"
  echo "    -h  this usage information"
  echo ""
  echo "EXAMPLE:"
  echo "    add_global_firefox_extension.sh -o osx -f ./thesupergood.xpi"
  echo ""
  ## Usage always exits
  exit $E_OPTERROR
}

function CheckForFile()
{
  if [ ! -f ${FILENAME} ]
  then
    echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    echo "  Error: the file:"
    echo "      ${FILENAME}"
    echo "  Does not exist"
    echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    Usage
  fi
  FILE=$(basename ${FILENAME}) 
  EXTENSION=${FILE##*.} 
  XPI=${FILE%.*}
  #echo "EXTENSION = ${EXTENSION}"
  if [ "${EXTENSION}" = xpi ]
  then
    continue
  else
    echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    echo "  Error: ${FILENAME} is not a *.xpi file"
    echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    Usage
  fi
}

function CheckForOs()
{
  ## most importantly, the file must exist
  if [ "${OSNAME}" = osx ]
  then
    EXTDIR="/Library/Application Support/Mozilla/Extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}"
  elif [ "${OSNAME}" = linux ]
  then
    EXTDIR="/usr/lib/firefox-addons/extensions"
  else
    echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    echo "  Error: the operating system:"
    echo "      ${OSNAME}"
    echo "  Is not implemented, the defaults are \"osx\" or \"linux\"."
    echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    Usage
  fi
}

function CheckArgs()
{
  ## Process the arguments passed in
  while getopts ":o:f:h" Option
  do
    case $Option in
    o    ) OSNAME=$OPTARG ## mandatory
           #echo "OSNAME = $OSNAME"
           CheckForOs
           ;;
    f    ) FILENAME=$OPTARG ## mandatory
           ## make sure the file exists
           #echo "FILENAME = $FILENAME"
           CheckForFile
           ;;
           ## show Usage, do not use ?
           ## an unsupported/invalid option will set ? so the switch statement would
           ## never reach the default case. in order to use a default case to explain
           ## that an unsupported/invalid option was used set the "help" switch as -h
           ## or something other than -?
    h    ) Usage
           ;;
           ## default if an invalid option was entered
    *    ) echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
           echo "  Error: invalid option selected"
           echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
           Usage
    esac
  done
  ## Must at least have a file name using the -f switch
  ## check here in case only optional arguments were used
  if [ ! ${OSNAME} ]
  then
    echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    echo "  Error: the \"-o linux|osx\" option is mandatory"
    echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    Usage
  elif [ ! ${FILENAME} ]
  then
    echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    echo "  Error: the \"-f /path/filename\" option is mandatory"
    echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    Usage
  fi
}

setUp () {
    if [ ! -f ${FILENAME} ] ; then
        echo "File doesn't exist"
        exit 1
    fi
    umask 0022
    if [ -d $TMPDIR ] ; then
        (cd $TMPDIR ; sudo rm -rf *)
    else
        sudo mkdir -p "$TMPDIR"
        #cd $TMPDIR
    fi
    echo -e "\n\nworking . . .\n\n"
    sudo unzip "${FILENAME}" -d "$TMPDIR" &> /dev/null
}

getID () {
    local IFS="
"
    FILE="`cat $TMPDIR/install.rdf`"
    for i in $FILE ; do
        if echo "$i"|grep "urn:mozilla:install-manifest" &> /dev/null ; then
            GET=true
        fi
        if [ "$GET" = true ] ; then
            if echo "$i"|grep "<em:id>" ; then
                ID=`echo "$i" | sed 's#.*<em:id>\(.*\)</em:id>.*#\1#'`
            elif echo "$i"|grep "em:id=\"" ; then
                ID=`echo "$i" | sed 's/.*em:id="\(.*\)".*/\1/'`
            fi
            if echo "$i"|grep "<em:name>" ; then
                NAME=`echo "$i" | sed 's#.*<em:name>\(.*\)</em:name>.*#\1#'`
            elif echo "$i"|grep "em:name=\"" ; then
                NAME=`echo "$i" | sed 's/.*em:name="\(.*\)".*/\1/'`
            fi
            if echo "$i"|grep "<em:version>" ; then
                VERSION=`echo "$i" | sed 's#.*<em:version>\(.*\)</em:version>.*#\1#'`
            elif echo "$i"|grep "em:version=\"" ; then
                VERSION=`echo "$i" | sed 's/.*em:version="\(.*\)".*/\1/'`
            fi
            if [ -n "$ID" ] && [ -n "$NAME" ] && [ -n "$VERSION" ] ; then
                return
            fi
        fi
    done
    return 1
}

installExtension () {
    if [ -d "$EXTDIR/$ID" ] ; then
        sudo rm -rvf "$EXTDIR/$ID"
    fi
    sudo mv -vv "$TMPDIR" "$EXTDIR/$ID"
    if [ $? = 0 ] ; then
        echo -e "\n\nThe extension \"$XPI.$EXTENSION\" ($NAME - $VERSION) was globally installed\n\n"
    else
        echo -e "\n\nError installing \"$XPI.$EXTENSION\" extension\n\n"
    fi
}

getPath () {
    (
    cd ${1%%/*}
    pwd
    )
}

cleanUp () {
    if [ -d $TMPDIR ] ; then
        sudo rm -rf $TMPDIR
    fi
    exit $1
}

TMPDIR="/tmp/ff_global_xpi"

trap "cleanUp 1" 1 2 3 15

CheckArgs "${@}"

setUp

getID

installExtension

cleanUp

您要做的是,您只需将所需的 Firefox xpi 作为输入发送给脚本。

相关内容