Lines 125-127
do_set() {
Link Here
|
125 |
|
125 |
|
126 |
set_symlink "$1" || die -q "Couldn't set a new symlink" |
126 |
set_symlink "$1" || die -q "Couldn't set a new symlink" |
127 |
} |
127 |
} |
128 |
- |
128 |
|
|
|
129 |
### update action ### |
130 |
|
131 |
describe_update() { |
132 |
echo "Update the kernel symlink to running kernel" |
133 |
} |
134 |
|
135 |
describe_update_options() { |
136 |
echo "ifunset: Do not override currently set version" |
137 |
} |
138 |
|
139 |
do_update() { |
140 |
[[ -z $1 || $1 == ifunset ]] || die -q "Usage error" |
141 |
[[ $# -gt 1 ]] && die -q "Too many parameters" |
142 |
test_for_root |
143 |
|
144 |
if [[ -e ${EROOT}/usr/src/linux && ]]; then |
145 |
if [[ ! -L ${EROOT}/usr/src/linux ]]; then |
146 |
# we have something strange |
147 |
die -q "${EROOT}/usr/src/linux exists but is not a symlink" |
148 |
fi |
149 |
|
150 |
if [[ $1 == ifunset ]]; then |
151 |
# The /usr/src/linux symlink exists, points to a path that |
152 |
# exists, and 'ifunset' is provided. Nothing to do. |
153 |
return |
154 |
fi |
155 |
fi |
156 |
|
157 |
local targets=( $(find_targets) ) |
158 |
if [[ ${#targets[@]} -eq 0 ]]; then |
159 |
die -q "No target kernel-source trees found" |
160 |
fi |
161 |
|
162 |
local running_kernel_release |
163 |
running_kernel_release=$(uname -r) |
164 |
if (( $? > 0 )); then |
165 |
die -q "Executing uname failed with $?" |
166 |
fi |
167 |
local running_kernel_symlink_target="linux-${running_kernel_release}" |
168 |
|
169 |
if [[ -e ${EROOT}/usr/src/linux ]]; then |
170 |
local current_target |
171 |
current_target=$(basename "$(canonicalise "${EROOT}/usr/src/linux")") |
172 |
if [[ ${current_target} == "${running_kernel_symlink_target}" ]]; then |
173 |
# The /usr/src/linux symlink already points to the running |
174 |
# kernel's sources. Nothing to do. |
175 |
return |
176 |
fi |
177 |
fi |
178 |
|
179 |
local target |
180 |
local target_list=() |
181 |
for target in "${targets[@]}"; do |
182 |
if [[ ${target} == "${running_kernel_symlink_target}" ]]; then |
183 |
set_symlink "${target}" |
184 |
return |
185 |
fi |
186 |
target_list+=("\n- ${target}") |
187 |
done |
188 |
|
189 |
write_error_msg "No kernel sources for running kernel ${running_kernel_release} found." |
190 |
if ! is_output_mode brief; then |
191 |
do_list >&2 |
192 |
fi |
193 |
die -q "Could not update the kernel symlink" |
194 |
} |
195 |
|
196 |
### helper functions ### |
197 |
|
198 |
test_for_root() { |
199 |
if [[ ! -w ${EROOT}/usr/src ]]; then |
200 |
die -q "${EROOT}/usr/src not writeable by current user. Are you root?" |
201 |
fi |
202 |
} |