2015-07-20 00:09:47 -07:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
|
2023-12-03 16:10:02 +01:00
|
|
|
readonly source_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
|
|
|
|
readonly sudo_scripts_dir="${source_dir}/src/scripts"
|
|
|
|
|
|
|
|
|
|
if [[ ! -f /usr/bin/node ]]; then
|
2024-09-20 16:19:03 +02:00
|
|
|
echo "check-install: node is not in root user's environment. '/usr/bin/env node' will not work"
|
2023-12-03 16:10:02 +01:00
|
|
|
exit 1
|
|
|
|
|
fi
|
2015-08-12 19:26:31 -07:00
|
|
|
|
2015-07-20 00:09:47 -07:00
|
|
|
# checks if all scripts are sudo access
|
2023-12-03 16:10:02 +01:00
|
|
|
readarray -d '' scripts < <(find ${sudo_scripts_dir} -type f -print0)
|
2023-07-11 14:58:09 +05:30
|
|
|
declare -a missing_scripts=()
|
2015-07-20 00:09:47 -07:00
|
|
|
for script in "${scripts[@]}"; do
|
2023-12-04 01:38:27 +01:00
|
|
|
# sudo -k ignores a cached sudo session for the command
|
|
|
|
|
if [[ $(sudo -k -n "${script}" --check 2>/dev/null) != "OK" ]]; then
|
2023-07-11 14:58:09 +05:30
|
|
|
missing_scripts+=("${script}")
|
2015-07-20 00:09:47 -07:00
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
2023-07-11 14:58:09 +05:30
|
|
|
if [[ ${#missing_scripts[@]} -gt 0 ]]; then
|
2023-12-03 16:10:02 +01:00
|
|
|
echo "The following script(s) have no sudo access: ${missing_scripts[*]} . Try 'sudo -n ${missing_scripts[0]} --check'"
|
2023-07-11 14:58:09 +05:30
|
|
|
echo -e "\nYou have to add the lines below to /etc/sudoers.d/yellowtent\n\n"
|
|
|
|
|
|
|
|
|
|
for missing_script in "${missing_scripts[@]}"; do
|
|
|
|
|
echo "Defaults!${missing_script} env_keep=\"HOME BOX_ENV\""
|
|
|
|
|
echo "${USER} ALL=(ALL) NOPASSWD: ${missing_script}"
|
|
|
|
|
echo ""
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2015-11-09 23:31:00 -08:00
|
|
|
|
2023-12-03 16:10:02 +01:00
|
|
|
setenv_scripts=(starttask.sh backupupload.js)
|
|
|
|
|
for script in "${setenv_scripts[@]}"; do
|
|
|
|
|
if ! grep -q ":SETENV:.*${script}" "/etc/sudoers.d/yellowtent"; then
|
|
|
|
|
echo "SETENV missing for ${script} in /etc/sudoers.d/yellowtent"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
if ! grep -q "backupupload.js closefrom_override" "/etc/sudoers.d/yellowtent"; then
|
|
|
|
|
echo "backupupload.js needs closefrom_override in /etc/sudoers.d/yellowtent"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
images=$(node -e "const i = require('${source_dir}/src/infra_version.js'); console.log(Object.keys(i.images).map(x => i.images[x]).join(' '));")
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2016-05-24 16:46:27 -07:00
|
|
|
for image in ${images}; do
|
|
|
|
|
if ! docker inspect "${image}" >/dev/null 2>/dev/null; then
|
2021-09-22 11:37:27 +02:00
|
|
|
docker pull ${image%@sha256:*}
|
2016-05-24 16:46:27 -07:00
|
|
|
fi
|
|
|
|
|
done
|
2015-11-09 23:31:00 -08:00
|
|
|
|