edestecd / puppet-software

Puppet Module to install various Desktop Software
GNU General Public License v3.0
8 stars 7 forks source link

Add Slack to social software section (Ubuntu only) #7

Closed bittner closed 6 years ago

bittner commented 7 years ago

This PR adds a first shot of Slack installation, supporting Ubuntu only for now:

  1. Downloads the installation package (.deb) from the Slack download site
  2. Installs the downloaded package using dpkg

Fixes #1.

bittner commented 7 years ago

Here is the answer from Slack support:

Eoin Brosnan (Slack), Sep 11, 2:44 AM PDT

Hi Peter,

I'm sorry for any confusion here.

When the .deb package is installed with the graphical installer, or with apt (rather than dpkg), we unpack /etc/cron.daily/slack. When this is executed, it installs a packagecloud key, determines the path to the apt directories, and creates /etc/apt/sources.list.d/slack.list, which contains the repo link deb https://packagecloud.io/slacktechnologies/slack/debian/ jessie main. When this process is followed, updating should be possible with sudo apt-get update && sudo apt-get upgrade.

I hope that helps. Please of course let me know if you have any questions.

Eoin

So, there really is an Apt source that we can use. Great!

I will try to motivate them, though, to get this process right. (How are we supposed to install a .deb package using apt when the website only offers a manual download?)

bittner commented 7 years ago

Interesting! The file Slack support mentions does indeed exist. But there is no slack.list file anywhere in my /etc/apt/, even though that's what the script would install, if I read it correctly. For whatever reason. Maybe you can tell from the script?

FILE: /etc/cron.daily/slack

#!/bin/sh
#
# Copyright (c) 2015 Slack Technologies. Original version from Google Chrome,
# license is below.
#
# Copyright (c) 2009 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# It creates the repository configuration file for package updates, and it
# monitors that config to see if it has been disabled by the overly aggressive
# distro upgrade process (e.g.  intrepid -> jaunty). When this situation is
# detected, the respository will be re-enabled. If the respository is disabled
# for any other reason, this won't re-enable it.
#
# This functionality can be controlled by creating the $DEFAULTS_FILE and
# setting "repo_add_once" and/or "repo_reenable_on_distupgrade" to "true" or
# "false" as desired. An empty $DEFAULTS_FILE is the same as setting both values
# to "false".

# System-wide package configuration.
DEFAULTS_FILE="/etc/default/slack"

APT_GET="`which apt-get 2> /dev/null`"
APT_CONFIG="`which apt-config 2> /dev/null`"

SOURCES_PREAMBLE="### THIS FILE IS AUTOMATICALLY CONFIGURED ###
# You may comment out this entry, but any other modifications may be lost.\n"

# sources.list setting for updates.
REPOCONFIG="deb https://packagecloud.io/slacktechnologies/slack/debian/ jessie main"

# Parse apt configuration and return requested variable value.
apt_config_val() {
  APTVAR="$1"
  if [ -x "$APT_CONFIG" ]; then
    "$APT_CONFIG" dump | sed -e "/^$APTVAR /"'!d' -e "s/^$APTVAR \"\(.*\)\".*/\1/"
  fi
}

# Install the repository signing key (see also:
# https://www.google.com/linuxrepositories/)
install_key() {
  APT_KEY="`which apt-key 2> /dev/null`"
  if [ -x "$APT_KEY" ]; then
    "$APT_KEY" add - >/dev/null 2>&1 <<KEYDATA
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

mQINBFLUbogBEADceEoxBDoE6QM5xV/13qiELbFIkQgy/eEi3UesXmJblFdU7wcD
LOW3NuOIx/dgbZljeMEerj6N1cR7r7X5sVoFVEZiK4RLkC3Cpdns0d90ud2f3VyK
K7PXRBstdLm3JlW9OWZoe4VSADSMGWm1mIhT601qLKKAuWJoBIhnKY/RhA/RBXt7
z22g4ta9bT67PlliTo1a8y6DhUA7gd+5TsVHaxDRrzc3mKObdyS5LOT/gf8Ti2tY
BY5MBbQ8NUGExls4dXKlieePhKutFbde7sq3n5sdp1Ndoran1u0LsWnaSDx11R3x
iYfXJ6xGukAc6pYlUD1yYjU4oRGhD2fPyuewqhHNUVwqupTBQtEGULrtdwK04kgI
H93ssGRsLqUKe88uZeeBczVuupv8ZLd1YcQ29AfJHe6nsevsgjF+eajYlzsvC8BN
q3nOvvedcuI6BW4WWFjraH06GNTyMAZi0HibTg65guZXpLcpPW9hTzXMoUrZz8Mv
J9yUBcFPKuFOLDpRP6uaIbxJsYqiituoltl0vgS/vJcpIVVRwSaqPHa6S63dmKm2
6gq18v4l05mVcInPn+ciHtcSlZgQkCsRTSvfU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tvxXQfm1py5tlwL5rE+ek1fwleaKXRcNNmm+T+vD
dIw+JcHy8a53nK1JEfBqEuY6IqEPKDke0wDIsDLSwI1OgtQoe7Cm1PBujfJu4rYQ
E+wwgWILTAgIy8WZXAloTcwVMtgfSsgHia++LqKfLDZ3JuwpaUAHAtguPy0QddvF
I4R7eFDVwHT0sS3AsG0HAOCY/1FRe8cAw/+9Vp0oDtOvBWAXycnCbdQeHvwh2+Uj
2u2f7K3CDMoevcBl4L5fkFkYTkmixCDy5nst1VM5nINueUIkUAJJbOGpd6yFdif7
mQR0JWcPLudb+fwusJ4UEACYWhPa8Gxa7eYopRsydlcdEzwpmo6E+V8GIdLFRFFp
KHQEzbSW5coxzU6oOiPbTurCZorIMHTA9cpAZoMUGKaSt19UKIMvSqtcDayhgf4c
Z2ay1z0fdJ2PuLeNnWeiGyfq78q6wqSaJq/h6JdAiwXplFd3gqJZTrFZz7A6Q6Pd
7B+9PZ/DUdEO3JeZlHJDfRmfU2XPoyPUoq79+whP5Tl3WwHUv7Fg357kRSdzKv9D
bgmhqRHlgVeKn9pwN4cpVBN+idzwPefQksSKH4lBDvVr/9j+V9mmrOx7QmQ5LCc/
1on+L0dqo6suoajADhKy+lDQbzs2mVb4CLpPKncDup/9iJbjiR17DDFMwgyCoy5O
HJICQ5lckNNgkHTS6Xiogkt28YfK4P3S0GaZgIrhKQ7AmO3O+hB12Zr+olpeyhGB
OpBD80URntdEcenvfnXBY/BsuAVbTGXiBzrlBEyQxg656jUeqAdXg+nzCvP0yJlB
UOjEcwyhK/U2nw9nGyaR3u0a9r24LgijGpdGabIeJm6O9vuuqFHHGI72pWUEs355
lt8q1pAoJUv8NehQmlaR0h5wcwhEtwM6fiSIUTnuJnyHT053GjsUD7ef5fY1KEFm
aZeW04kRtFDOPinz0faE8hvsxzsVgkKye1c2vkXKdOXvA3x+pZzlTHtcgMOhjKQA
sA==
=H60S
-----END PGP PUBLIC KEY BLOCK-----
KEYDATA
  fi
}

# NB: The original key we used above is the public PackageCloud
# key which we are now moving away from and moving to a key that
# Slack uses solely for Slack packages. However, in order to not
# break updates for people, we need to ship an update where we
# include both keys. In a future update, we'll remove the
# PackageCloud key.
install_new_key() {
  APT_KEY="`which apt-key 2> /dev/null`"
  if [ -x "$APT_KEY" ]; then
    "$APT_KEY" add - >/dev/null 2>&1 <<KEYDATA
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.11 (GNU/Linux)

mQINBFbGA48BEAC2S2NI8thjLDFCqjjWweQ2M6KF4+9+r4XFejsImspzDHm3+LhM
g6iAOeAI2aJ3pYThDAzKMOpUlGdyXsTjuP/IerrwVXMFg2JgFXre3skCdi4zDEmS
Xo/JyAQbQ8lVFvQ4fep+i0Z757MtTfaYlaU/dg1+8Ldnif7/0gEg3YsFXRAg5YXO
CK23AqcaZxr6gOkKcvlumecorV/oGzSCthIRdpYTmEOAvVOPn8xitnunjeErZR3+
BtVI3sfuTnEdqlu9lH9dLDgmEPihBTuHP0fLQ5vbJ2mgQQ8IalVf4U7aJFD5CH8s
XngxPHye8/Ww1EBVBxjtNogVM5tYg2Wxb5ESPmJ6k96BCzIIDNiEkZbPUHJfG5YR
rLdhz4gKSE3oUdRwA/fpt8bhDf1dQQcRoT98qLiGnJwAEx+a5cIHJDnKhwI0TLCO
IXMfphMb/iWO6JSpMo1ydeIULviBj3xn6QYXTeTiRapGHGN8kSpaomxSTcCTJ7b2
5ykQliuPtody3nEpsHb3tTcw/HLqeki6mRZUF2uX54xyEaFCDJo++uX7JMsjIbOb
X31J0r4fCGym6luHT9Z5xgYmPSOPamNdOWB2I6Ks/IyRt3v8RGbia9/NhOA5O7Af
pVkRQomibaxXx7o6vQ8wsdm5lzm/LsQHaQaCz/XNNMmD/IesFmth0iavMwARAQAB
tHRodHRwczovL3BhY2thZ2VjbG91ZC5pby9zbGFja3RlY2hub2xvZ2llcy9zbGFj
ayAoaHR0cHM6Ly9wYWNrYWdlY2xvdWQuaW8vZG9jcyNncGdfc2lnbmlu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0PPELhjOmOvICk
gCZTv9k852y330VEi8vHI67i047TRt+8FzksTBJV/Qrpqgl+x5Z6gXZ8+jZdZ8Ce
1EeSIZymaCxBsv9tNiZ9RBEFriE1HSvsHYF0ScWw+l9LqjTCnj3qU8gfvF9i+e7z
iYffc2GXNiCJDcqpo8VCwg/7Bffs8y0XJCDZLXU8m4e4C+Vn6wwWHKnVWcCL1k2o
UmZOX2uzGzPFXnG8FyjAB8Aul+ldjO8tn2MjkC/wdvEhl8KKfbHf6+LTezsX86fH
bN/noG03IUf4BZYD78lwhsNG8ylP1MEJH6//QVlSQkC4Ju9MfKrbICRjxtaJaG1s
nIeKWZKXCjGI8ZZIM7mXi+a7KzCGv/Xz71TPHGXPDGNX+0HX8Kjor0TXLcUIkVqy
6C+x0b3TuS31g16+0f/ry20Qez4HelMC5yTC0EdB0r9XrXglhlJ5HfPtj3mo1x2J
YaeDulPChbDQcH7xLnEFY6GfquO6HA/Nden3Rr2py/MKpYfituptC7U4TGf4LPzr
WpS005fIGUiYh+gjMdFGmQ/0NlyrIHQmVzNHFITvxSr+NVxY2pG1nG5dbFqyStcI
N/t3NXMoAcEcbiivikn6mcysFoij0DEzzZejB1Lp28OJp77JMgxdJ2EGu9YHzF44
QeiB1fahvCoWo+CSJhrYN4/52DoeiYE7Ko1kefDxH5BUpxbxtXcCr30UZYIzSzy6
XzCC9Nb4ncvMui8hpcnyEGrze6YY3M6lSWfgn8g/D6DsaeyTvvsk3Hvagwx+v+nH
m3ntWbHywcepKAid9ZBsHGh8G6Y90jzvSBs0Uw4R7MoKp1Rr0QvPDy1FqPZZDAPy
lIs=
=ZPAR
-----END PGP PUBLIC KEY BLOCK-----
KEYDATA
  fi
}

# Set variables for the locations of the apt sources lists.
find_apt_sources() {
  APTDIR=$(apt_config_val Dir)
  APTETC=$(apt_config_val 'Dir::Etc')
  APT_SOURCES="$APTDIR/$APTETC/$(apt_config_val 'Dir::Etc::sourcelist')"
  APT_SOURCESDIR="$APTDIR/$APTETC/$(apt_config_val 'Dir::Etc::sourceparts')"
}

# Update the Google repository if it's not set correctly.
# Note: this doesn't necessarily enable the repository, it just makes sure the
# correct settings are available in the sources list.
# Returns:
# 0 - no update necessary
# 2 - error
update_bad_sources() {
  if [ ! "$REPOCONFIG" ]; then
    return 0
  fi

  find_apt_sources

  SOURCELIST="$APT_SOURCESDIR/slack.list"
  # Don't do anything if the file isn't there, since that probably means the
  # user disabled it.
  if [ ! -r "$SOURCELIST" ]; then
    return 0
  fi

  # Basic check for active configurations (non-blank, non-comment lines).
  ACTIVECONFIGS=$(grep -v "^[[:space:]]*\(#.*\)\?$" "$SOURCELIST" 2>/dev/null)

  # Check if the correct repository configuration is in there.
  REPOMATCH=$(grep "^[[:space:]#]*\b$REPOCONFIG\b" "$SOURCELIST" \
    2>/dev/null)

  # Check if the correct repository is disabled.
  MATCH_DISABLED=$(echo "$REPOMATCH" | grep "^[[:space:]]*#" 2>/dev/null)

  # Now figure out if we need to fix things.
  BADCONFIG=1
  if [ "$REPOMATCH" ]; then
    # If it's there and active, that's ideal, so nothing to do.
    if [ ! "$MATCH_DISABLED" ]; then
      BADCONFIG=0
    else
      # If it's not active, but neither is anything else, that's fine too.
      if [ ! "$ACTIVECONFIGS" ]; then
        BADCONFIG=0
      fi
    fi
  fi

  if [ $BADCONFIG -eq 0 ]; then
    return 0
  fi

  # At this point, either the correct configuration is completely missing, or
  # the wrong configuration is active. In that case, just abandon the mess and
  # recreate the file with the correct configuration. If there were no active
  # configurations before, create the new configuration disabled.
  DISABLE=""
  if [ ! "$ACTIVECONFIGS" ]; then
    DISABLE="#"
  fi
  printf "$SOURCES_PREAMBLE" > "$SOURCELIST"
  printf "$DISABLE$REPOCONFIG\n" >> "$SOURCELIST"
  if [ $? -eq 0 ]; then
    return 0
  fi
  return 2
}

# Add the Google repository to the apt sources.
# Returns:
# 0 - sources list was created
# 2 - error
create_sources_lists() {
  if [ ! "$REPOCONFIG" ]; then
    return 0
  fi

  find_apt_sources

  SOURCELIST="$APT_SOURCESDIR/slack.list"
  if [ -d "$APT_SOURCESDIR" ]; then
    printf "$SOURCES_PREAMBLE" > "$SOURCELIST"
    printf "$REPOCONFIG\n" >> "$SOURCELIST"
    if [ $? -eq 0 ]; then
      return 0
    fi
  fi
  return 2
}

# Remove our custom sources list file.
# Returns:
# 0 - successfully removed, or not configured
# !0 - failed to remove
clean_sources_lists() {
  if [ ! "$REPOCONFIG" ]; then
    return 0
  fi

  find_apt_sources

  rm -f "$APT_SOURCESDIR/slack.list"
}

# Detect if the repo config was disabled by distro upgrade and enable if
# necessary.
handle_distro_upgrade() {
  if [ ! "$REPOCONFIG" ]; then
    return 0
  fi

  find_apt_sources
  SOURCELIST="$APT_SOURCESDIR/slack.list"
  if [ -r "$SOURCELIST" ]; then
    REPOLINE=$(grep -E "^[[:space:]]*#[[:space:]]*$REPOCONFIG[[:space:]]*# disabled on upgrade to .*" "$SOURCELIST")
    if [ $? -eq 0 ]; then
      sed -i -e "s,^[[:space:]]*#[[:space:]]*\($REPOCONFIG\)[[:space:]]*# disabled on upgrade to .*,\1," \
        "$SOURCELIST"
      LOGGER=$(which logger 2> /dev/null)
      if [ "$LOGGER" ]; then
        "$LOGGER" -t "$0" "Reverted repository modification: $REPOLINE."
      fi
    fi
  fi
}

DEFAULT_ARCH="amd64"

get_lib_dir() {
  if [ "$DEFAULT_ARCH" = "i386" ]; then
    LIBDIR=lib/i386-linux-gnu
  elif [ "$DEFAULT_ARCH" = "amd64" ]; then
    LIBDIR=lib/x86_64-linux-gnu
  else
    echo Unknown CPU Architecture: "$DEFAULT_ARCH"
    exit 1
  fi
}

## MAIN ##
DEFAULTS_FILE="/etc/default/slack"
if [ -r "$DEFAULTS_FILE" ]; then
  . "$DEFAULTS_FILE"
else
  repo_add_once="true"
  repo_reenable_on_distupgrade="true"
  echo "repo_add_once=\"true\"\nrepo_reenable_on_distupgrade=\"true\"\n" > "$DEFAULTS_FILE"
fi

if [ "$repo_add_once" = "true" ]; then
  install_key
  install_new_key
  create_sources_lists
  RES=$?
  # Sources creation succeeded, so stop trying.
  if [ $RES -ne 2 ]; then
    sed -i -e 's/[[:space:]]*repo_add_once=.*/repo_add_once="false"/' "$DEFAULTS_FILE"
  fi
else
  update_bad_sources
fi

if [ "$repo_reenable_on_distupgrade" = "true" ]; then
  handle_distro_upgrade
  install_new_key
fi
bittner commented 7 years ago

They've got DEFAULTS_FILE="/etc/default/slack" in the script twice. That must be a mistake.

And that file doesn't exist on my system either. Hence, that cron script was never run, was it?

bittner commented 7 years ago

Interesting to dig for reasons. When I run the cron job script manually it adds the Apt sources list:

$ sudo su
# cd / & /etc/cron.daily/slack
# exit
$ cat /etc/apt/sources.list.d/slack.list 
### THIS FILE IS AUTOMATICALLY CONFIGURED ###
# You may comment out this entry, but any other modifications may be lost.
deb https://packagecloud.io/slacktechnologies/slack/debian/ jessie main

Not sure what's broken here. It's not executing as a daily cron job. (Maybe some path issue during the execution of the cron job?? But I don't find traces, no mails from Cron in /var/mail/, for example.)

edestecd commented 7 years ago

Great, with the link that I supplied to the chrome apt setup and the info you found in /etc/apt/sources.list.d/slack.list, you should be able to switch over and remove the archive...

edestecd commented 7 years ago

https://github.com/edestecd/puppet-software/blob/master/manifests/browsers/chrome.pp#L36

Finding the key id and source may be a bit tricky and you may need to dig some more, but this approach is much better in my opinion...

bittner commented 7 years ago

Cool! It all seems to be here! https://packagecloud.io/app/slacktechnologies/slack/gpg#gpg-apt

Not sure which one really is the ID, though. You seem to be right with "a bit tricky". The key ID listed on that page seems short (C6ABDCF64DB9A0B2), gpg on the other hand lists something completely different:

$ gpg --dry-run --verbose --import slacktechnologies-slack-C6ABDCF64DB9A0B2.pub.gpg 
gpg: armor header: Version: GnuPG v1.4.11 (GNU/Linux)
gpg: pub  rsa4096/D938EC0D038651BD 2016-02-18  https://packagecloud.io/slacktechnologies/slack (https://packagecloud.io/docs#gpg_signing) <support@packagecloud.io>
gpg: Total number processed: 1
bittner commented 7 years ago

OMG! This makes it even easier: https://packagecloud.io/slacktechnologies/slack/install#puppet

include packagecloud

packagecloud::repo { "slacktechnologies/slack":
  type => 'deb',  # or "rpm" or "gem"
}
bittner commented 7 years ago

I haven't seen an option to uninstall the repo (Apt source) from the packagecloud::repo sources and docs. Maybe you know better, @edestecd?

bittner commented 7 years ago

Crap! The packagecloud::repo class installs an Apt source based on the current distro (e.g. ubuntu zesty), whereas the package Slack uploaded to packagecloud is only and always debian jessie. And we can't influence the creation.

I need to go for the code your proposed, with the Chrome installation as a role model.

bittner commented 7 years ago

Works fine now. I've tested the current status locally.

Note that I omitted the -> Class['apt::update'] -> code portion as apt::source's notify_updates parameter is true by default.

bittner commented 7 years ago

Anything else I can do before you want to merge this in?

bittner commented 6 years ago

@edestecd Anything missing to get this PR merged? Let me know, please!

edestecd commented 6 years ago

@bittner I made a few comments. Once you clerify/fix I will merge. Everything else looks good to me :+1:

edestecd commented 6 years ago

@bittner thanks for all your work on this!

bittner commented 6 years ago

:clap: :champagne: :wine_glass: :tada:

Thank you so much! What is your plan for issuing a new release?

edestecd commented 6 years ago

I can do one once your other PR is all squared.

bittner commented 6 years ago

Alright, I've rebased the other branch onto the new HEAD.

BTW, I found your demo video on YouTube about a Foreman-based solution and added a comment. It would really help if you commented on that. (Sorry for the OT!)

bittner commented 6 years ago

Oh, btw, thanks to @larz from @comsolit who is sponsoring this engagement! :moneybag:

bittner commented 6 years ago

A final note:

When installing Slack puppet emits the following warning:

Warning: /Apt_key[Add key: C6ABDCF64DB9A0B2 from Apt::Source slack]: The id should be a full fingerprint (40 characters), see README.

This refers to the key id in the apt::source. We need to find out the full fingerprint and replace it in the code.

According to sudo apt-key list --fingerprint C6ABDCF64DB9A0B2 this should be DB08 5A08 CA13 B8AC B917 E0F6 D938 EC0D 0386 51BD or D537 997A BE0E 1079 C0E8 EBD6 C6AB DCF6 4DB9 A0B2, I'm not sure. The short key is originally from packagecloud.io.