Improve posinstall scripts with spellcheck

This commit is contained in:
Edgars Beigarts committed 2016-09-26 01:55:20 +03:00
1 parent 58f28c1aea
commit dc879e2c4a
3 files changed
+66 -59

No files matched your search

+51 -48
View File
@@ -1,60 +1,63 @@
#!/bin/bash #!/usr/bin/env bash
set +o posix # rpm uses /bin/sh that forces bash in posix mode set +o posix # rpm uses /bin/sh that forces bash in posix mode
set -eo pipefail; [[ $TRACE ]] && set -x set -eo pipefail; [[ $TRACE ]] && set -x
readonly DOKKU_ROOT="${DOKKU_ROOT:-/home/dokku}" setup-user() {
readonly DOKKU_LIB_ROOT="${DOKKU_LIB_PATH:-/var/lib/dokku}" echo "Setting up dokku user"
getent passwd dokku >/dev/null || useradd -m -s /bin/bash dokku
call-sshcommand() { mkdir -p "$DOKKU_ROOT/.ssh"
if [[ -x /usr/local/bin/sshcommand ]]; then touch "$DOKKU_ROOT/.ssh/authorized_keys"
/usr/local/bin/sshcommand "$@" chown -R dokku:dokku "$DOKKU_ROOT/.ssh"
elif [[ -x /usr/bin/sshcommand ]]; then usermod -aG docker dokku
/usr/bin/sshcommand "$@"
else
echo "Unable to find sshcommand binary" 1>&2
exit 1
fi
} }
echo "Setting up dokku user" setup-storage() {
getent passwd dokku >/dev/null || useradd -m -s /bin/bash dokku echo "Setting up storage directories"
mkdir -p $DOKKU_ROOT/.ssh mkdir -p "${DOKKU_LIB_ROOT}/data" "${DOKKU_LIB_ROOT}/data/storage"
touch $DOKKU_ROOT/.ssh/authorized_keys chown dokku:dokku -R "${DOKKU_LIB_ROOT}/data"
chown -R dokku:dokku $DOKKU_ROOT/.ssh }
usermod -aG docker dokku
echo "Setting up storage directories" setup-plugins() {
mkdir -p ${DOKKU_LIB_ROOT}/data ${DOKKU_LIB_ROOT}/data/storage echo "Setting up plugin directories"
chown dokku:dokku -R ${DOKKU_LIB_ROOT}/data # should be replaced by `plugn init`
mkdir -p "${DOKKU_LIB_ROOT}/core-plugins/available" "${DOKKU_LIB_ROOT}/plugins/available"
mkdir -p "${DOKKU_LIB_ROOT}/core-plugins/enabled" "${DOKKU_LIB_ROOT}/plugins/enabled"
touch "${DOKKU_LIB_ROOT}/core-plugins/config.toml" "${DOKKU_LIB_ROOT}/plugins/config.toml"
echo "Setting up plugin directories" echo "Enabling all core plugins"
# should be replaced by `plugn init` find "${DOKKU_LIB_ROOT}/core-plugins/available" -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | while read -r plugin; do
mkdir -p ${DOKKU_LIB_ROOT}/core-plugins/available ${DOKKU_LIB_ROOT}/plugins/available if [ ! -d "${DOKKU_LIB_ROOT}/plugins/available/$plugin" ]; then
mkdir -p ${DOKKU_LIB_ROOT}/core-plugins/enabled ${DOKKU_LIB_ROOT}/plugins/enabled ln -s "${DOKKU_LIB_ROOT}/core-plugins/available/$plugin" "${DOKKU_LIB_ROOT}/plugins/available/$plugin"
touch ${DOKKU_LIB_ROOT}/core-plugins/config.toml ${DOKKU_LIB_ROOT}/plugins/config.toml PLUGIN_PATH="${DOKKU_LIB_ROOT}/core-plugins" plugn enable "$plugin"
PLUGIN_PATH="${DOKKU_LIB_ROOT}/plugins" plugn enable "$plugin"
fi
done
find -L "${DOKKU_LIB_ROOT}" -type l -delete
chown dokku:dokku -R "${DOKKU_LIB_ROOT}/plugins" "${DOKKU_LIB_ROOT}/core-plugins"
echo "Enabling all core plugins" echo "Install all core plugins"
find ${DOKKU_LIB_ROOT}/core-plugins/available -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | while read -r plugin; do dokku plugin:install --core
if [ ! -d ${DOKKU_LIB_ROOT}/plugins/available/$plugin ]; then }
ln -s ${DOKKU_LIB_ROOT}/core-plugins/available/$plugin ${DOKKU_LIB_ROOT}/plugins/available/$plugin;
PLUGIN_PATH=${DOKKU_LIB_ROOT}/core-plugins plugn enable $plugin
PLUGIN_PATH=${DOKKU_LIB_ROOT}/plugins plugn enable $plugin
fi
done
find -L ${DOKKU_LIB_ROOT} -type l -delete
chown dokku:dokku -R ${DOKKU_LIB_ROOT}/plugins ${DOKKU_LIB_ROOT}/core-plugins
echo "Ensure proper sshcommand path" setup-sshcommand() {
echo '/usr/bin/dokku' > "${DOKKU_ROOT}/.sshcommand" echo "Ensure proper sshcommand path"
if [[ -f .ssh/authorized_keys ]]; then echo '/usr/bin/dokku' > "${DOKKU_ROOT}/.sshcommand"
sed -i.bak 's#/usr/local/bin/dokku#/usr/bin/dokku#' "${DOKKU_ROOT}/.ssh/authorized_keys" }
rm "${DOKKU_ROOT}/.ssh/authorized_keys"
fi
echo "Install all core plugins" setup-version() {
dokku plugin:install --core rm -f "${DOKKU_ROOT}/VERSION"
cp "${DOKKU_LIB_ROOT}/STABLE_VERSION" "${DOKKU_ROOT}/VERSION"
}
rm -f ${DOKKU_ROOT}/VERSION main() {
cp ${DOKKU_LIB_ROOT}/STABLE_VERSION ${DOKKU_ROOT}/VERSION readonly DOKKU_ROOT="${DOKKU_ROOT:-/home/dokku}"
readonly DOKKU_LIB_ROOT="${DOKKU_LIB_PATH:-/var/lib/dokku}"
exit 0 setup-user
setup-storage
setup-plugins
setup-sshcommand
setup-version
}
main
+14 -10
View File
@@ -1,16 +1,20 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set +o posix # rpm uses /bin/sh that forces bash in posix mode set +o posix # rpm uses /bin/sh that forces bash in posix mode
echo 'Starting docker' main() {
systemctl start docker echo 'Starting docker'
systemctl start docker
sleep 5 sleep 5
count=`sudo docker images | grep gliderlabs/herokuish | wc -l` count=$(sudo docker images | grep -c gliderlabs/herokuish)
if [ "$count" -ne 0 ]; then if [ "$count" -ne 0 ]; then
echo 'Removing old herokuish image' echo 'Removing old herokuish image'
sudo docker rmi gliderlabs/herokuish sudo docker rmi gliderlabs/herokuish
fi fi
echo 'Importing herokuish into docker (around 5 minutes)' echo 'Importing herokuish into docker (around 5 minutes)'
sudo docker build -t gliderlabs/herokuish /var/lib/herokuish 1> /dev/null sudo docker build -t gliderlabs/herokuish /var/lib/herokuish 1> /dev/null
}
main
+1 -1
View File
@@ -71,7 +71,7 @@ lint:
# these are disabled due to their expansive existence in the codebase. we should clean it up though # these are disabled due to their expansive existence in the codebase. we should clean it up though
# SC2034: VAR appears unused - https://github.com/koalaman/shellcheck/wiki/SC2034 # SC2034: VAR appears unused - https://github.com/koalaman/shellcheck/wiki/SC2034
@echo linting... @echo linting...
@$(QUIET) find . -not -path '*/\.*' -not -path './debian/*' -not -path './rpm/*' -type f | xargs file | grep text | awk -F ':' '{ print $$1 }' | xargs head -n1 | egrep -B1 "bash" | grep "==>" | awk '{ print $$2 }' | xargs shellcheck -e SC2034 @$(QUIET) find . -not -path '*/\.*' -not -path './debian/*' -type f | xargs file | grep text | awk -F ':' '{ print $$1 }' | xargs head -n1 | egrep -B1 "bash" | grep "==>" | awk '{ print $$2 }' | xargs shellcheck -e SC2034
unit-tests: unit-tests:
@echo running unit tests... @echo running unit tests...