-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
generate UTF locales selectable in icingaweb2 #140
Conversation
trade-off between image size and container initialization time, I don't mind. like this? skm42@5700e23 Concerning #141 I took a look into icinga2 standalone vagrant box https://github.com/Icinga/icinga-vagrant. It has all locales generated, utf and iso ones. Should be save to follow like this, what's your view? skm42@aaeeebb |
Sorry, but this is pointless. It's absolutely static and not even parametrized. You buy this with container boottime, which is quite valuable on container reboot. The locales package is ~15 MBs big and all generated locales are about 6MBs in size. Compared to an image, which is about 600MBs big .... @skm42 Please put the stuff back again into the Dockerfile. But do you see the The stuff you want to add here is currently completely static and has no parameters. Please pack it above the Please squash the commits, too and have a look at the
Could you please provide a direct link for this? I'm not able to find the part you may refer to. |
Please see latest commit. Tested for utf locales |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I'm laughing about your code. It looks like a you're a proper C programmer, miss all C idioms and want to implement them in bash 😂
Your code looks like a poem written in swollen language, which tries to express the meaning of a simple sentence.
But in contrast to a poem, you have to write down the simple sentence here. People need to understand you and not have to interpret your peom, what it could mean.
It seems that you had a pretty hard job in programming bash/shell. I guess, I can help you, by commenting your code and showing you, what could get improved.
I'm going to reject this PR, as I've found a welldoing solution.
fi | ||
|
||
echo "BUILD_LOCALES: $BUILD_LOCALES" | ||
typeset -i m=$(echo $BUILD_LOCALES | awk -F ',' '{print NF}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no guarantee, that your process will spit out a real number. So typesetting it to an integer doesn't give you any guarantee for this. Also quote the commands output, as it could contain special shell chars or just spaces, which get interpreted.
while [[ $n -le $m ]] | ||
do | ||
b_locale=$(echo $BUILD_LOCALES | awk -F ',' "{print \$$n}") | ||
cat /etc/locale.gen |grep -q "^$b_locale" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
grep -q "^${b_locale}" /etc/locale.gen
echo "BUILD_LOCALES: $BUILD_LOCALES" | ||
typeset -i m=$(echo $BUILD_LOCALES | awk -F ',' '{print NF}') | ||
typeset -i n=1 | ||
while [[ $n -le $m ]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're iterating here over an index. Well, that's possible, but in bash this is discouraged. The language is not made for this. Use things like an enhanced for loop.
for elem in $(command_which spits out elements); do
# do some stuff with "${elem}"
done
Rule of thumb: At the point where you have to use real integers either
- bash isn't the way to go and another language fits much better
- you misuse bash
- you know that you misuse bash, but it's the only language available
b_locale=$(echo $BUILD_LOCALES | awk -F ',' "{print \$$n}") | ||
cat /etc/locale.gen |grep -q "^$b_locale" | ||
if [[ $? -ne 0 ]] | ||
then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The if clause actually executes a command and then tests for its exit code. If the exit code is 0 (==true), it'll execute the codeblock the result else not.
So the [[
(or [
depending on your shell) is called the test function, which is actually a just regular command, getting fed with the logical operators and evaluating them. The "matching" ]]
isn't actually a bash syntactic token, it's just an argument to the command and this command can verify that it received all arguments.
So, extratesting for $? -ne 0
is superfluous, as you just could use if grep -q "^$b_locale" /etc/locale.gen; then
and three lines are shrunken to a single one.
if [[ $? -ne 0 ]] | ||
then | ||
echo "adding locale $b_locale" | ||
cat /etc/locale.gen | sed "s/# $b_locale/$b_locale/" > /tmp/locale.gen |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the locale, I specified is not there in the file, it won't get enabled. On the one hand side, this is great. But KIM, that you could have a typo in the environment variable (e.g.: using en_us.UTF-8 UTF-8
) and then the actual locale gets silently dropped.
sed
has got a -i
switch. And also like grep
it takes a filename as the last parameters.
sed -i "s/# $b_locale/$b_locale/" /etc/locale.gen
fi | ||
|
||
n=$n+1 | ||
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not further tested, but this would basically do the same:
echo "${BUILD_LOCALES}" | while IFS=, read locale charset; do
sed -i "s/#\\s*${locale}/${locale}/" /etc/locale.gen
done
locale-gen | ||
break | ||
fi | ||
n=$n+1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo "${BUILD_LOCALES}" | while IFS=, read locale charset; do
if locale -a | grep -qi "^${locale}$"; do
locale-gen
break
fi
done
fine for me. Going to review your comments for learning better bash and maybe come up with a new PR at a later time. |
#101