-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Others: - move no_addons.sh to bin folder since it's a FIXME script - allow boot if target user has already been created (e.g. restart)
- Loading branch information
Showing
4 changed files
with
75 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,15 +22,16 @@ function man { | |
|
||
function _ensure_odoo_user_owns_volume { | ||
# Make sure the folder exists | ||
if [ -d $1 ]; then | ||
if [ -d "$1" ]; then | ||
# Check if the volume has been mounted read-only | ||
mount_type=$( cat /proc/mounts | grep "\s$1\s" | \ | ||
awk '{print tolower(substr($4,0,3))}' ) | ||
|
||
if [ $mount_type != "ro" ]; then | ||
chown $odoo_user:$odoo_user $1 | ||
if [ "$mount_type" != 'ro' ]; then | ||
# Set target user as owner | ||
chown "$odoo_user":"$odoo_user" "$1" | ||
else | ||
echo $log_src[`date +%F.%H:%M:%S`]' Read-only volume:' $1 | ||
echo $log_src[`date +%F.%H:%M:%S`]' Read-only volume:' "$1" | ||
fi | ||
fi | ||
} | ||
|
@@ -54,38 +55,39 @@ function _update_odoo_conf_params { | |
|
||
# Get the value of the corresponding ENV variable and escape slashes | ||
val=${!env_var} | ||
val=$( echo $val | sed 's/\//\\\//g') | ||
val=$( echo "$val" | sed 's/\//\\\//g') | ||
|
||
# FIXME Should not be an external script (see reason in script header) | ||
bash /app/bin/update_odoo_param.sh $odoo_user $odoo_conf_file $odoo_param $val | ||
bash /app/bin/update_odoo_param.sh "$odoo_user" "$odoo_conf_file" \ | ||
"$odoo_param" "$val" | ||
|
||
# Unset the environment variable for security purpose | ||
unset $env_var | ||
unset "$env_var" | ||
done <<< "$( printenv | grep '^ODOO_' | sed 's/=.*//g' )" | ||
} | ||
|
||
function _setup_ssh_key { | ||
# Create SSH config folder in $HOME folder of Odoo target user | ||
ssh_folder=$( getent passwd $odoo_user | cut -d: -f6 )/.ssh | ||
sudo -i -u $odoo_user mkdir $ssh_folder | ||
ssh_folder=$( getent passwd "$odoo_user" | cut -d: -f6 )/.ssh | ||
sudo -i -u "$odoo_user" mkdir "$ssh_folder" | ||
|
||
# Copy SSH private key from /opt/odoo/ssh | ||
sudo -i -u $odoo_user cp /opt/odoo/ssh/id_rsa $ssh_folder | ||
sudo -i -u "$odoo_user" cp /opt/odoo/ssh/id_rsa "$ssh_folder" | ||
|
||
echo $log_src[`date +%F.%H:%M:%S`]' Scanning GitHub key...' | ||
# Hide ssh-keyscan stderr output since it's actually log message | ||
ssh-keyscan github.com 2> /dev/null | \ | ||
sudo -i -u $odoo_user tee $ssh_folder/known_hosts > /dev/null | ||
sudo -i -u "$odoo_user" tee "$ssh_folder/known_hosts" > /dev/null | ||
|
||
# Bind SSH key to GitHub host | ||
echo "host github.com | ||
HostName github.com | ||
User git | ||
IdentityFile $ssh_folder/id_rsa" | \ | ||
sudo -i -u $odoo_user tee $ssh_folder/config > /dev/null | ||
sudo -i -u "$odoo_user" tee "$ssh_folder/config" > /dev/null | ||
|
||
# Secure SSH key | ||
chmod 400 $ssh_folder/id_rsa | ||
chmod 400 "$ssh_folder/id_rsa" | ||
} | ||
|
||
function _download_addons { | ||
|
@@ -94,8 +96,8 @@ function _download_addons { | |
# 2) There's a file called `oca_dependencies.txt` at the root of extra addons folder | ||
if [ "$ADDONS_REPO" -o -a /opt/odoo/additional_addons/oca_dependencies.txt ]; then | ||
# Git config for target user | ||
sudo -i -u $odoo_user git config --global user.email "[email protected]" | ||
sudo -i -u $odoo_user git config --global user.name "Elico Corp - Odoo Docker" | ||
sudo -i -u "$odoo_user" git config --global user.email "[email protected]" | ||
sudo -i -u "$odoo_user" git config --global user.name "Elico Corp - Odoo Docker" | ||
|
||
# Setup SSH key | ||
if [ -a /opt/odoo/ssh/id_rsa ]; then | ||
|
@@ -108,10 +110,12 @@ function _download_addons { | |
fi | ||
|
||
echo $log_src[`date +%F.%H:%M:%S`]' Downloading additional addons...' | ||
sudo -i -u $odoo_user python /opt/odoo/auto_addons/addons.py $FETCH_OCA_DEPENDENCIES $ADDONS_REPO | ||
sudo -i -u "$odoo_user" python /opt/odoo/auto_addons/addons.py \ | ||
"$FETCH_OCA_DEPENDENCIES" "$ADDONS_REPO" | ||
else | ||
# No additional addons to download | ||
sudo -i -u $odoo_user bash /opt/odoo/auto_addons/no_addons.sh $odoo_conf_file | ||
# FIXME Should not be an external script (see reason in script header) | ||
bash /app/bin/no_addons.sh "$odoo_user" "$odoo_conf_file" | ||
fi | ||
} | ||
|
||
|
@@ -139,29 +143,30 @@ function start { | |
|
||
echo $log_src[`date +%F.%H:%M:%S`]' Running odoo...' | ||
set +e | ||
if [ ! -e $1 ]; then | ||
echo $log_src[`date +%F.%H:%M:%S`]' ...with additional args:' $* | ||
if [ ! -e "$1" ]; then | ||
echo $log_src[`date +%F.%H:%M:%S`]' ...with additional args:' "$*" | ||
fi | ||
sudo -i -u $odoo_user /usr/bin/python \ | ||
/opt/odoo/sources/odoo/$BINARY_NAME \ | ||
-c $odoo_conf_file \ | ||
$* | ||
sudo -i -u "$odoo_user" /usr/bin/python \ | ||
"/opt/odoo/sources/odoo/$BINARY_NAME" \ | ||
-c "$odoo_conf_file" \ | ||
$* | ||
|
||
SERVICE_PID=$! | ||
SERVICE_PID="$!" | ||
set -e | ||
} | ||
|
||
# smart shutdown on SIGINT and SIGTERM | ||
function on_exit() { | ||
kill -TERM $SERVICE_PID | ||
wait $SERVICE_PID 2> /dev/null | ||
kill -TERM "$SERVICE_PID" | ||
wait "$SERVICE_PID" 2> /dev/null | ||
exit 0 | ||
} | ||
trap on_exit INT TERM | ||
|
||
echo $log_src[`date +%F.%H:%M:%S`]' Running command...' | ||
for arg in "$*" | ||
do | ||
# Not protected with `"` in order to pass the arguments | ||
$arg | ||
done | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,28 @@ | ||
#!/bin/bash | ||
# | ||
# FIXME the below code should be in boot but for an unknown reason, the | ||
# instruction `grep -q "^$param\s*=" $odoo_conf_file` fails to run in boot, when it | ||
# works fine here. | ||
# instruction `grep` fails to run in boot, when it works fine here. | ||
# Both are bash scripts, but: | ||
# - boot is run by Docker as an entrypoint | ||
# - target_user.sh is run using bash command | ||
# | ||
log_src='['${0##*/}']' | ||
|
||
odoo_user=$1 | ||
odoo_conf_file=$2 | ||
odoo_param=$3 | ||
val=$4 | ||
odoo_user="$1" | ||
odoo_conf_file="$2" | ||
odoo_param="$3" | ||
val="$4" | ||
|
||
# Check if the conf already contains that parameter | ||
grep -q "^$odoo_param\s*=" $odoo_conf_file | ||
found=$? | ||
grep -q "^$odoo_param\s*=" "$odoo_conf_file" | ||
found="$?" | ||
|
||
if [ $found -eq 0 ]; then | ||
if [ "$found" -eq 0 ]; then | ||
# Substitute the value | ||
sudo -i -u $odoo_user sed -i "s/^$odoo_param\s*=.*/$odoo_param = $val/g" $odoo_conf_file | ||
sudo -i -u "$odoo_user" sed -i \ | ||
"s/^$odoo_param\s*=.*/$odoo_param = $val/g" "$odoo_conf_file" | ||
else | ||
# Append the parameter (hide tee output to stdout) | ||
echo "$odoo_param = $val" | sudo -i -u $odoo_user tee -a $odoo_conf_file > /dev/null | ||
echo "$odoo_param = $val" | \ | ||
sudo -i -u "$odoo_user" tee -a "$odoo_conf_file" > /dev/null | ||
fi |