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 && ! -L ${EROOT}/usr/src/linux ]]; then |
145 |
# we have something strange |
146 |
die -q "${EROOT}/usr/src/linux exists but is not a symlink" |
147 |
fi |
148 |
|
149 |
if [[ $1 == ifunset && -e ${EROOT}/usr/src/linux ]]; then |
150 |
# The /usr/src/linux symlink exists, points to a path that |
151 |
# exists, and 'ifunset' is provided. Nothing to do. |
152 |
return |
153 |
fi |
154 |
|
155 |
local targets=( $(find_targets) ) |
156 |
if [[ ${#targets[@]} -eq 0 ]]; then |
157 |
die -q "No target kernel-source trees found" |
158 |
fi |
159 |
|
160 |
local running_kernel_release |
161 |
running_kernel_release=$(uname -r) |
162 |
if (( $? > 0 )); then |
163 |
die -q "Executing uname failed with $?" |
164 |
fi |
165 |
local running_kernel_symlink_target="linux-${running_kernel_release}" |
166 |
|
167 |
if [[ -e ${EROOT}/usr/src/linux ]]; then |
168 |
local current_target |
169 |
current_target=$(basename "$(canonicalise "${EROOT}/usr/src/linux")") |
170 |
if [[ ${current_target} == "${running_kernel_symlink_target}" ]]; then |
171 |
# The /usr/src/linux symlink already points to the running |
172 |
# kernel's sources. Nothing to do. |
173 |
return |
174 |
fi |
175 |
fi |
176 |
|
177 |
local target |
178 |
local target_list=() |
179 |
for target in "${targets[@]}"; do |
180 |
if [[ ${target} == "${running_kernel_symlink_target}" ]]; then |
181 |
set_symlink "${target}" |
182 |
return |
183 |
fi |
184 |
target_list+=("\n- ${target}") |
185 |
done |
186 |
|
187 |
write_error_msg "No kernel sources for running kernel ${running_kernel_release} found." |
188 |
if ! is_output_mode brief; then |
189 |
do_list >&2 |
190 |
fi |
191 |
die -q "Could not update the kernel symlink" |
192 |
} |
193 |
|
194 |
### helper functions ### |
195 |
|
196 |
test_for_root() { |
197 |
if [[ ! -w ${EROOT}/usr/src ]]; then |
198 |
die -q "${EROOT}/usr/src not writeable by current user. Are you root?" |
199 |
fi |
200 |
} |