...
Code Block |
---|
language | bash |
---|
theme | RDark |
---|
title | Set if not already defined |
---|
collapse | true |
---|
|
: ${var=value} |
This one is obscure....<TODO> explain!
Code Block |
---|
language | bash |
---|
theme | RDark |
---|
title | Set if not defined OR set to the empty string |
---|
collapse | true |
---|
|
: ${var:=value} |
...
Code Block |
---|
language | bash |
---|
theme | RDark |
---|
title | Install packages via sudo only if it is not already installed |
---|
collapse | true |
---|
|
install_package ()
{
PACKAGE_NAME=$1
# Does not work if the package has been installed and later removed
# dpkg -s ${PACKAGE_NAME} > /dev/null
dpkg-query -W -f='${Status}' ${PACKAGE_NAME} | grep -q -P '^install ok installed$'
if [ $? -ne 0 ]; then
sudo apt-get -q -y install ${PACKAGE_NAME} > /dev/null
else
pretty_print " $(padded_message ${PACKAGE_NAME} "found")"
return 0
fi
if [ $? -ne 0 ]; then
pretty_error " $(padded_message ${PACKAGE_NAME} "failed")"
return 1
fi
pretty_warning " $(padded_message ${PACKAGE_NAME} "installed")"
return 0
}
# usage
install_package ansible |
...