Skip to content

Instantly share code, notes, and snippets.

@roktas
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roktas/9018932 to your computer and use it in GitHub Desktop.
Save roktas/9018932 to your computer and use it in GitHub Desktop.
#!/bin/bash
case $BASH_VERSION in
[4-9]*)
;;
*)
echo >&2 "Bash version 4 or higher required."
exit 1
esac
set -eo pipefail
# Attributes.
declare -Agr attr=(
[debian]='System is Debian (auto detected)'
[desktop]='Desktop environment'
[developer]='Development environment'
[go]='Go development environment'
[gui]='Gui environment'
[heavy]='Extra packages'
[interactive]='Machine which will be used interactively'
[java]='Java runtime and development environment'
[javascript]='Javascript runtime and development environment'
[l10n]='Packages for localization'
[laptop]='Laptop machine'
[mariadb]='Mariadb database'
[metal]='Non virtual machine'
[minimalist]='Minimalist packages'
[mysql]='Mysql database'
[packager]='Debian package developer'
[php]='Php runtime and development environment'
[postgresql]='Postgresql database'
[publisher]='Packages for publishing'
[python]='Python runtime and development environment'
[ruby]='Ruby runtime and development environment'
[server]='Server packages'
[ubuntu]='System is Ubuntu (auto detected)'
[unofficial]='Unofficial packages'
[web]='Packages for a Web server'
)
# Aliases for attribute sets.
declare -Agr alias=(
[builder]='
developer
server
'
[lamp]='
heavy
mysql
web
php
server
developer
'
[polyglot]='
go
java
javascript
php
python
ruby
developer
'
[user]='
interactive
gui
desktop
'
[vanilla]='
go
interactive
java
javascript
python
ruby
developer
publisher
'
[workstation]='
heavy
interactive
gui
desktop
go
java
javascript
python
ruby
developer
packager
publisher
'
)
# Attribute structure after expansion.
declare -Ag expanded
# Needs for command.
PATH="/sbin:/usr/sbin:$PATH"
cry() {
echo -e >&2 "$@"
}
die() {
echo -e >&2 "$@"
exit 1
}
if [[ -n $VERBOSE ]]; then
verbose() {
echo >&2 $*
}
else
verbose() {
:
}
fi
has_enough_ram() {
local min_ram=${1:-64}
local ram=$(awk '/^MemTotal:/ { print $2 }' /proc/meminfo) ||:
# The 4 is a fuzz factor to allow for kernel ram usage.
if [[ -n $ram ]] && [[ $ram -ge $((($min_ram - 4) * 1024)) ]]; then
return 0
fi
return 1
}
has_enough_disk() {
local min_disk=${1:-3}
local disk=$(df -P /usr | tail -1 | awk '{ print $4 }')
if [[ -n $disk ]] && [[ $disk -ge $(($min_disk * 1024 * 1024)) ]]; then
return 0
fi
return 1
}
is_rack() {
if command -v >/dev/null dmidecode && \
dmidecode | grep -q 'Type: Rack Mount Chassis'; then
return 0
fi
return 1
}
is_debian_or_derivative() {
if command -v >/dev/null apt-get; then
return 0
fi
return 1
}
is_ubuntu_or_derivative() {
if [[ -f /etc/issue ]]; then
case $(head -n 1 /etc/issue) in
[Uu]buntu*|[Mm]int*) return 0 ;;
esac
fi
return 1
}
is_gui() {
command -v >/dev/null X
}
is_gnome() {
command -v >/dev/null gnome-session
}
is_laptop() {
if command -v >/dev/null laptop-detect && laptop-detect; then
return 0
fi
return 1
}
is_metal() {
if command -v >/dev/null virt-what && [[ -z $(virt-what 2>/dev/null ||:) ]]; then
return 0
fi
return 1
}
usage() {
local items item sorted
cry "Specify an argument list from the following available attributes.\n"
items=()
for item in "${!attr[@]}"; do
items+=(
"$(printf "%12s - %s" "$item" "$(echo ${attr[$item]})")"
)
done
for item in "${!alias[@]}"; do
items+=(
"$(printf "%12s - Alias for '%s'" "$item" "$(echo ${alias[$item]})")"
)
done
readarray -t sorted < <(
for item in "${items[@]}"; do
echo "$item"
done | sort
)
for item in "${sorted[@]}"; do
echo "$item"
done
}
is() {
local arg
for arg; do
[[ ${expanded[$arg]} = yes ]] || return 1
done
verbose "selected $@"
return 0
}
expand() {
local arg missings auto
if [[ $# -eq 0 ]]; then
usage
exit 0
fi
if ! is_debian_or_derivative; then
die "Unsupported system."
fi
missings=()
for arg; do
if [[ $arg = auto ]]; then
auto=yes
continue
fi
if [[ -n ${attr[$arg]} ]]; then
expanded[$arg]=yes
else
local value item
value=${alias[$arg]}
if [[ -n $value ]]; then
for item in $value; do
expanded[$item]=yes
done
else
missings+=($arg)
fi
fi
done
if [[ ${#missings} -ne 0 ]]; then
cry "No such attribute(s): ${missings[@]}\n"
usage
exit 1
fi
if [[ -z ${expanded[debian]} ]] && [[ -z ${expanded[ubuntu]} ]]; then
if is_ubuntu_or_derivative; then
expanded[ubuntu]=yes
else
expanded[debian]=yes
fi
fi
if [[ -n $auto ]]; then
if is_gui; then
expanded[gui]=yes
expanded[interactive]=yes
if is_gnome; then
expanded[desktop]=yes
fi
fi
if is_laptop; then
expanded[laptop]=yes
fi
if is_metal; then
expanded[metal]=yes
fi
if has_enough_ram 1024 && has_enough_disk 20; then
expanded[heavy]=yes
fi
fi
}
dump() {
# Barebone
echo '
bind9-host
bzip2
bzr
ca-certificates
curl
dnsutils
ed
file
git
iputils-tracepath
less
lsb-release
mercurial
ncurses-term
netcat-openbsd
psmisc
rsync
socat
ssh
sudo
syslinux
telnet
unzip
vim-tiny
zip
'
is metal && echo '
console-setup
console-terminus
'
is minimalist && return 0
# Default
echo '
jq
python-minimal
ruby
ruby-highline
virt-what
'
is debian && echo '
ruby-toml
'
is interactive && echo '
ack-grep
bash-completion
fish
htop
iselect
lsof
mc
moreutils
ncdu
passwordmaker-cli
pciutils
pdmenu
recode
strace
time
tmux
unrar
vim
vlock
'
is interactive metal && echo '
anacron
'
is laptop && echo '
acpi
acpid
acpi-support
bluetooth
iw
pcmciautils
pm-utils
powertop
wireless-tools
wpasupplicant
'
is interactive debian l10n && echo '
locales
'
is interactive ubuntu l10n && echo '
language-pack-tr
'
is heavy interactive && echo '
avahi-autoipd
avahi-daemon
avahi-utils
eject
jpegoptim
libimage-exiftool-perl
libnss-mdns
lynx-cur
mime-support
mlocate
pandoc
pngnq
qalc
sharutils
tig
units
wodim
'
# End user
is gui && echo '
devilspie
fonts-dejavu-core
fonts-inconsolata
leafpad
meld
numlockx
unclutter
vim-gtk
xfonts-terminus
xsel
xterm
'
is gui desktop && echo '
guake
vim-gnome
'
is gui debian desktop && echo '
chromium
chromium-l10n
tango-icon-theme
xdg-utils
'
is gui ubuntu desktop && echo '
chromium-browser
chromium-browser-l10n
unity-chromium-extension
webaccounts-chromium-extension
'
is heavy gui desktop && echo '
'
# Developer
is developer && echo '
autoconf
bison
build-essential
flex
imagemagick
libbsd-dev
libbz2-dev
libcurl4-openssl-dev
libevent-dev
libglib2.0-dev
libjpeg62
libjpeg-dev
libmagickcore-dev
libmagickwand-dev
libmariadbclient-dev
libmysqlclient-dev
libncurses5-dev
libpng12-0
libpng12-dev
libpq-dev
libreadline5-dev
libsqlite3-dev
libssl-dev
libxml2-dev
libxslt-dev
sqlite3
zlib1g-dev
'
is interactive developer && echo '
exuberant-ctags
ipython
pep8
pry
pyflakes
ri
'
is heavy interactive developer && echo '
bmake
cmake
glibc-doc
libglib2.0-doc
manpages-dev
manpages-posix
python-autopep8
sloccount
subversion
whohas
'
is desktop developer && echo '
libdbus-1-dev
libgnome-keyring-dev
pkg-config
python-keyring
ruby-dbus
'
is packager developer && echo '
devscripts
dh-golang
dh-python
dput-ng
git-buildpackage
ubuntu-dev-tools
'
is go developer && echo '
golang
golang-go.tools
'
is java developer && echo '
default-jdk
default-jre-headless
'
is javascript developer && echo '
nodejs
nodejs-dev
npm
'
is php developer && echo '
php5-cli
php5-curl
php5-dev
php5-gd
php5-json
php5-sqlite
php-pear
'
is python developer && echo '
python3-dev
python-dev
'
is ruby developer && echo '
ruby
ruby-dev
ruby-mini-magick
'
# Publisher
is publisher && echo '
pandoc
pdfjam
python-pygments
ruby-redcarpet
'
is unofficial publisher && echo '
python-landslide-patched
python-markdown-extra
'
is heavy publisher && echo '
latex-beamer
lmodern
texlive-fonts-recommended
texlive-generic-recommended
texlive-lang-european
texlive-lang-french
texlive-lang-other
texlive-latex-extra
texlive-latex-recommended
texlive-publishers
texlive-xetex
'
is heavy gui publisher && echo '
gimp
inkscape
'
# Server
is server && echo '
at
bsd-mailx
daemontools
exim4-config
exim4-daemon-light
'
is interactive server && echo '
bmon
ccze
dnstracer
ipcalc
mtr-tiny
tcpdump
usbutils
whois
'
is web server && echo '
nginx-extras
'
is packager web server && echo '
reprepro
'
is php server && echo '
php5-fpm
'
is php mysql server && echo '
php5-mysql
'
is php postgreql server && echo '
php5-pgsql
'
is heavy php server && echo '
libphp-adodb
libphp-pclzip
libphp-phpmailer
php5-apcu
php5-memcached
php5-xmlrpc
'
is postgresql server && echo '
autopostgresqlbackup
postgresql
postgresql-client
postgresql-contrib
'
is interactive postgresql server && echo '
pgtop
pgtune
'
is mysql server && echo '
automysqlbackup
mysql-client
mysql-server
'
is interactive mysql server && echo '
mysqltuner
mysql-utilities
'
is mariadb server && echo '
mariadb-client
mariadb-server
'
}
main() {
expand "$@"
echo $(dump | sort -u)
}
main "$@"
@emres
Copy link

emres commented Feb 19, 2014

Line 33, where it reads as

   'Packages for publishment'

I suggest the word 'publishing' instead of 'publishment'. I justify this first by referring to the following:

And then also referring to the DTP abbreviation, which stands for Desktop Publishing (and not Desktop Publishment).

@roktas
Copy link
Author

roktas commented Feb 19, 2014

👍 Fixed.

@setajampisau
Copy link

(y)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment