2

I have a bash file with a list of packages to install for a new Ubuntu installation using apt install however, not all the packages in the list are installing. Repos are included in the script as necessary.

I've tried the 2 methods below:

Method 1:

apt install [pkg1] [pkg2] [pkg3] ... [pkgn]

Method 2 - (pseudo code):

String pkgs_list[] = {"pkg1" "pkg2" "pkg3" "pkgn"}
for each pkg in pkg_list {
  if pkg exists then {
    "do nothing"
  else
    apt install pkg
  }
}

Here is the complete bash code:

#***********************#
#***      Keys       ***#
#***********************#
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
wget -O - https://dl.sinew.in/keys/enpass-linux.key | apt-key add -
wget -nc https://dl.winehq.org/wine-builds/Release.key | apt-key add -


#***********************#
#***   Repositories  ***#
#***********************#
echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' | tee /etc/apt/sources.list.d/google-chrome.list
echo "deb http://repo.sinew.in/ stable main" > \
  /etc/apt/sources.list.d/enpass.list
add-apt-repository -y ppa:webupd8team/gnome3  #This is for gnome tweak tool extensions (source: https://www.wikihow.com/Change-Themes-on-Ubuntu-with-Gnome-Tweak-Tool)
add-apt-repository -y ppa:notepadqq-team/notepadqq
add-apt-repository https://dl.winehq.org/wine-builds/ubuntu/

apt -y update

#WinHQ enables 32bit architecture
dpkg --add-architecture i386 

#***********************#
#***   apt install   ***#
#***********************#

#apt -y install \
#  nemo \
#  google-chrome-stable \
#  notepadqq dconf-editor \
#  nfs-common \
#  enpass \
#  virtualbox \
#  virtualbox-guest-additions-iso \
#  gnome-tweak-tool \
  #gnome-shell-extensions-user-themes \
#  vlc \
#  gimp \
#  winehq-stable \
#  synaptic

declare -a alist=("nemo"
  "google-chrome-stable"
  "notepadqq"
  "dconf-editor"
  "nfs-common"
  "enpass"
  "virtualbox"
  "virtualbox-guest-additions-iso"
  "gnome-tweak-tool"
  "vlc"
  "gimp"
  "winehq-stable"
  "synaptic"
  "usb-creator-gtk"
  "libreoffice"
  "chromium-browser"
  "thunderbird"
  "shotwell"
  "gnome-calendar")

for application in "${alist[@]}"
do
  dpkg -l $application
  if [ $? = '0' ]; then
    echo "***************************************************************************"
    echo "*****Application "$application" package is installed, no action taken.*****"
    echo "***************************************************************************"
  elif [ $? = '1' ]; then
    echo "******************************************"
    echo "*****Installing package $application.*****"
    echo "******************************************"
    #Add an if to match dock favorites and add to the dock .desktop file
    apt install $application -y
  fi
done

Here's the list of applications and there status after the script ran:

  1. nemo - ok
  2. google-chrome-stable - ok
  3. notepadqq - did not install
  4. dconf-editor - ok
  5. nfs-common - did not install
  6. enpass - ok
  7. virtualbox - ok
  8. virtualbox-guest-additions-iso - don't know
  9. gnome-tweak-tool - did not install
  10. vlc - ok
  11. gimp - did not install
  12. winehq-stable - did not install
  13. synaptic - did not install
  14. usb-creator-gtk - did not install
  15. libreoffice - ok
  16. chromium-browser - did not install
  17. thunderbird - did not install
  18. shotwell - did not install
  19. gnome-calendar - did not install

I can provide more information for each package is needed.

Thanks for your help.

EDIT

The log file generated by using the command $ sudo ./my_script.sh >> my_script.log is to large so I will post what I think is the problem and we can go from there.

Below is the output for gimp, one that did not install. When my code checks if the package is installed by using the command dpkg -l [package_name] it returns the following when checking for gimp and the others.

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version      Architecture Description
+++-==============-============-============-=================================
un  gimp           <none>       <none>       (no description available)

ALL the packages that did not install return this with Version and Architecture as <none> which tells me there's no package install, right? But when the bash script runs, the command return '0' making my statements believe the package is installed which does not seem to be the case according to dpkg. Instead, dpkg is supposed to return something like this: ...

$ dpkg -l package

dpkg-query: no packages found matching package

... when a package` is not installed.

I don't understand what is happening here with dpkg returning the information posted. What does this mean? What's happening?

Thanks,

EDIT

Additionally, if I try to remove the package with apt I get:

$ sudo apt autoremove gimp
[sudo] password for alex2wr: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package 'gimp' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
  • 3
    Please provide the actual output of your script. – muru Mar 23 '18 at 3:36
  • I added more information to the question with part of the log of what I think is the problem. It was too long to post. Let me know what else I can help with. Thanks. – Alex Mar 23 '18 at 5:26
  • 1
    If it's too long, post it on paste.ubuntu.com. That said, I don't see any relevent output from the script you posted. Just the output of some commands you ran afterwards, which are largely irrelevant. – muru Mar 23 '18 at 5:35
  • 4
    (a) 18.04 is still in development and off-topic here. (b) Many PPAs do not support 18.04, so apt -y update likely did not run successfully and so the package lists might be inconsistent. (c) dpkg -l's exit status is not an indicator of whether the package is installed or not, it merely shows whether dpkg knows about the package or not. – muru Mar 23 '18 at 5:58
  • 1
    @Thufir, why check if the package is already installed ? if you need them installed, why not simply install the package, even if it is already installed ? apt /apt-get would just skip it, as it is already installed ? no harm done.. – Robert Riedl Jan 7 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.