Skip to content
This repository was archived by the owner on Mar 26, 2020. It is now read-only.
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 35 additions & 7 deletions ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,9 @@ apt-packages-repository() {

# Add a Launchpad PPA as a software source.
apt-packages-ppa() {
apt-packages-repository \
"deb http://ppa.launchpad.net/$1/ubuntu lucid main" \
"deb-src http://ppa.launchpad.net/$1/ubuntu lucid main" \
"$2" "$3"
which 'add-apt-repository' >/dev/null || apt-packages-install 'python-software-properties'
add-apt-repository "$1"
apt-packages-update
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apt-packages-update should be included in the provisioning script to allow for batch updates, e.g., adding several PPAs and doing a single update. I've also updated apt-packages-repository to use add-apt-repository so keep the two functions aligned. See 5b46a36.

}

# Perform a non-interactive `apt-get` command.
Expand All @@ -98,6 +97,11 @@ apt-packages-update() {
apt-non-interactive update
}

# Upgrade `aptitude` packages without any prompts.
apt-packages-upgrade() {
apt-non-interactive upgrade
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was already available as system-upgrade which I've tweaked in e879932. Be careful as it's known to break VirtualBox Guest Additions when a new kernel is installed and the DKMS module is not re-compiled. dotless-de/vagrant-vbguest is good at handling this case.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually like having both, since you may want to perform a system upgrade, but not a dist upgrade, or maybe indeed a full dist upgrade. Not necessarily as relevant to vagrant (since you could just change your VagrantFile to reference a newer dist image), but relevant within the scope of general server administration if this script were used while managing non-vagrant boxes.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[..] relevant within the scope of general server administration if this script were used while managing non-vagrant boxes.

Makes sense, however I don't intend for this script to be used for server administration. A full distribution upgrade would also likely involve prompts/dialogs so running non-interactive is going to break the system.


# Perform an unattended installation of package(s).
apt-packages-install() {
apt-non-interactive install "$@"
Expand Down Expand Up @@ -396,18 +400,23 @@ ${code_block}

# Pass PHP scripts to PHP-FPM.
location ~ \.php\$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)\$;
fastcgi_param PATH_INFO \$fastcgi_path_info;
fastcgi_param PATH_TRANSLATED \$document_root\$fastcgi_path_info;
fastcgi_param HTTP_AUTHORIZATION \$http_authorization;
fastcgi_pass unix:/var/run/php5-fpm-${nginx_site_name}.sock;
}
EOD
)
# Run PHP-FPM as the selected user and group.
$SUDO sed \
-e 's#^\(\[[A-Za-z0-9-]\+\]\)$#['"$nginx_site_name"']#g' \
-e 's#^\(user\)\s*=\s*[A-Za-z0-9-]\+#\1 = '"$nginx_site_user"'#g' \
-e 's#^\(group\)\s*=\s*[A-Za-z0-9-]\+#\1 = '"$nginx_site_group"'#g' \
-i '/etc/php5/fpm/pool.d/www.conf'
-e 's#^\(listen\)\s*=\s*.\+$#\1 = '/var/run/php5-fpm-"$nginx_site_name"'.sock#g' \
<'/etc/php5/fpm/pool.d/www.conf' >'/etc/php5/fpm/pool.d/'"$nginx_site_name"'.conf'
fi
code_block=$( cat <<-EOD
${code_block}
Expand Down Expand Up @@ -460,6 +469,11 @@ php-pecl-install() {
done
}

# Restart the php5-fpm server and reload with new configuration.
php5-fpm-restart() {
system-service php5-fpm restart
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 3458e89 as php-fpm-restart as I wish to keep version names out of function names.


# }}}

# {{{ MySQL
Expand All @@ -470,6 +484,20 @@ mysql-database-create() {
mysql -u root -e "CREATE DATABASE IF NOT EXISTS \`$1\` CHARACTER SET ${2:-utf8} COLLATE '${3:-utf8_general_ci}'"
}

# Grant access to database (creates user if not exist)
# mysql-database-add-user databasename username password fromhost
mysql-database-add-user() {
log-operation "$FUNCNAME" "$@"
mysql -u root -e "GRANT ALL PRIVILEGES ON \`$1\`.* TO '$2'@'${4:-localhost}' IDENTIFIED BY '$3' WITH GRANT OPTION; FLUSH PRIVILEGES;"
}

# Load data from SQL file
# mysql-load-data databasename sqlfile
mysql-load-data() {
log-operation "$FUNCNAME" "$@"
mysql -u root "$1" < "$2"
}

# Restore a MySQL database from an archived backup.
mysql-database-restore() {
log-operation "$FUNCNAME" "$@"
Expand Down