Merge lp:~darkmuggle-deactivatedaccount/cloud-init/cloud-init.profile.d into lp:~cloud-init-dev/cloud-init/trunk

Proposed by Ben Howard
Status: Merged
Merged at revision: 553
Proposed branch: lp:~darkmuggle-deactivatedaccount/cloud-init/cloud-init.profile.d
Merge into: lp:~cloud-init-dev/cloud-init/trunk
Diff against target: 98 lines (+83/-0)
2 files modified
profile.d/Z99-cloud-locale-test.sh (+82/-0)
setup.py (+1/-0)
To merge this branch: bzr merge lp:~darkmuggle-deactivatedaccount/cloud-init/cloud-init.profile.d
Reviewer Review Type Date Requested Status
Scott Moser Pending
Review via email: mp+100531@code.launchpad.net

This proposal supersedes a proposal from 2012-03-30.

Description of the change

Added profile.d script to inform users of bad locales.

To post a comment you must log in.
Revision history for this message
Scott Moser (smoser) wrote : Posted in a previous version of this proposal

A couple things:
a.) use 'locale 2>&1 | locale_warn' as opposed to the here document.
   I was surprised at what was so slow in this, and its the here document. Use a pipe and its much faster.
   since we're not modifiying the environment at all, that is ok.

b.) I don't know how i feel about the /var/lib/cloud/instance/ setting... i think i'd at least like the option of something to be multi-instance, and also would like a per-user setting. as the user who logs in cannot necessarily modify /var/lib/cloud/instance/ . So just loop over a list of files, that can include the /var/lib/cloud/instance path

c.) apt-cache search "^language-pack-[a-z][a-z]$"
   might be slightly better, as the filtering is then built in.

Revision history for this message
Scott Moser (smoser) wrote : Posted in a previous version of this proposal

oh, and you can't return outside a function:
  [ -f /var/lib/cloud/instance/locale.skip ] && return

At http://bazaar.launchpad.net/~smoser/cloud-init/precise-locale-warning/revision/169 , i had:
 [ -f /etc/default/cloud-locales -o -f ~/.cloud-locales ] ||
    locale 2>&1 | cloud_locale_warn

Revision history for this message
Scott Moser (smoser) : Posted in a previous version of this proposal
review: Needs Fixing
Revision history for this message
Scott Moser (smoser) wrote :

did told a expansion of home not work? /home/$USER ohare codes an assumption on location. I'd rather let the shell resolv the ~.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'profile.d'
2=== added file 'profile.d/Z99-cloud-locale-test.sh'
3--- profile.d/Z99-cloud-locale-test.sh 1970-01-01 00:00:00 +0000
4+++ profile.d/Z99-cloud-locale-test.sh 2012-04-02 23:04:45 +0000
5@@ -0,0 +1,82 @@
6+#!/bin/sh
7+# vi: ts=4 noexpandtab
8+#
9+# Author: Ben Howard <ben.howard@canonical.com>
10+# Author: Scott Moser <scott.moser@ubuntu.com>
11+# (c) 2012, Canonical Group, Ltd.
12+#
13+# Purpose: Detect invalid locale settings and inform the user
14+# of how to fix them.
15+#
16+
17+locale_warn() {
18+ local cr="
19+"
20+ local line bad_names="" bad_lcs="" key="" value="" var=""
21+ local w1 w2 w3 w4 remain
22+ # locale is expected to output either:
23+ # VARIABLE=
24+ # VARIABLE="value"
25+ # locale: Cannot set LC_SOMETHING to default locale
26+ while read -r w1 w2 w3 w4 remain; do
27+ case "$w1" in
28+ locale:) bad_names="${bad_names} ${w4}";;
29+ *)
30+ key=${w1%%=*}
31+ val=${w1#*=}
32+ val=${val#\"}
33+ val=${val%\"}
34+ vars="${vars} $key=$val";;
35+ esac
36+ done
37+ for bad in $bad_names; do
38+ for var in ${vars}; do
39+ [ "${bad}" = "${var%=*}" ] &&
40+ bad_lcs="${bad_lcs} ${var#*=}" && break 2
41+ done
42+ done
43+ bad_lcs=${bad_lcs# }
44+ [ -n "$bad_lcs" ] || return 0
45+
46+ printf "_____________________________________________________________________\n"
47+ printf "WARNING! Your environment specifies an invalid locale.\n"
48+ printf " This can affect your user experience significantly, including the\n"
49+ printf " ability to manage packages. You may install the locales by running\n"
50+ printf " the following command(s):\n\n"
51+
52+ local bad invalid="" to_gen="" sfile="/usr/share/i18n/SUPPORTED"
53+ if [ ! -e "$sfile" ]; then
54+ printf " sudo apt-get install locales\n"
55+ fi
56+ if [ -e "$sfile" ]; then
57+ for bad in ${bad_lcs}; do
58+ grep -q -i "${bad}" "$sfile" &&
59+ to_gen="${to_gen} ${bad}" ||
60+ invalid="${invalid} ${bad}"
61+ done
62+ else
63+ to_gen=$bad_lcs
64+ fi
65+
66+ for bad in ${to_gen}; do
67+ printf " sudo apt-get install language-pack-${bad%%_*}\n"
68+ printf " sudo locale-gen ${bad}\n"
69+ done
70+ printf "\n"
71+ for bad in ${invalid}; do
72+ printf "WARNING: '${bad}' is an invalid locale\n"
73+ done
74+
75+ printf "To see all available language packs, run:\n"
76+ printf " apt-cache search \"^language-pack-[a-z][a-z]$\"\n"
77+ printf "To disable for all users, run:\n"
78+ printf " sudo touch /var/lib/cloud/instance/locale-check.skip\n"
79+ printf "To disable this check for this user only, run: \n"
80+ printf " touch ~/.locale-test.skip \n"
81+ printf "_____________________________________________________________________\n\n"
82+}
83+
84+[ -f /home/${USER}/.locale-test.skip -o -f /var/lib/cloud/instance/locale-check.skip ] ||
85+ locale 2>&1 | locale_warn
86+
87+unset locale_warn
88
89=== modified file 'setup.py'
90--- setup.py 2011-12-20 16:39:46 +0000
91+++ setup.py 2012-04-02 23:04:45 +0000
92@@ -47,5 +47,6 @@
93 ('/usr/share/doc/cloud-init', filter(is_f,glob('doc/*'))),
94 ('/usr/share/doc/cloud-init/examples', filter(is_f,glob('doc/examples/*'))),
95 ('/usr/share/doc/cloud-init/examples/seed', filter(is_f,glob('doc/examples/seed/*'))),
96+ ('/etc/profile.d', filter(is_f,glob('profile.d/*')))
97 ],
98 )