There are two bugs in add_sudo_secure_path.
Firstly we don't properly check if the file exists, so always append
the new line. This will overwrite any existing changes.
Secondly the logic for checking if the path exists is inverted, so we
miss adding paths when we should. This particularly causes failures
when installing with virtualenv's since the paths are inside the
virtualenv, rather than the standard system locations.
Change-Id: I646fe0c68958470d464fe4f3d81d5c17dd6f2ab6
Closes-bug: #1521241
| ... | ... |
@@ -22,14 +22,14 @@ function add_sudo_secure_path {
|
| 22 | 22 |
local line |
| 23 | 23 |
|
| 24 | 24 |
# This is pretty simplistic for now - assume only the first line is used |
| 25 |
- if [[ -r SUDO_SECURE_PATH_FILE ]]; then |
|
| 25 |
+ if [[ -r $SUDO_SECURE_PATH_FILE ]]; then |
|
| 26 | 26 |
line=$(head -1 $SUDO_SECURE_PATH_FILE) |
| 27 | 27 |
else |
| 28 | 28 |
line="Defaults:$STACK_USER secure_path=/usr/local/sbin:/usr/local/bin:/usr/sbin:/sbin:/usr/bin:/bin" |
| 29 | 29 |
fi |
| 30 | 30 |
|
| 31 | 31 |
# Only add ``dir`` if it is not already present |
| 32 |
- if [[ $line =~ $dir ]]; then |
|
| 32 |
+ if [[ ! $line =~ $dir ]]; then |
|
| 33 | 33 |
echo "${line}:$dir" | sudo tee $SUDO_SECURE_PATH_FILE
|
| 34 | 34 |
sudo chmod 400 $SUDO_SECURE_PATH_FILE |
| 35 | 35 |
sudo chown root:root $SUDO_SECURE_PATH_FILE |