-
Notifications
You must be signed in to change notification settings - Fork 28
Clean up the addition of extra directories and/or files #125
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -144,6 +144,21 @@ distro_vars="${script_dir}/${_distro}_vars.sh" | |||||
|
||||||
pushd "$_arg_working_dir" > /dev/null || fail "couldn't cd to $_arg_working_dir" | ||||||
|
||||||
# save the working directory | ||||||
working_dir=$(pwd) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why save it again? It's already in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pwd guarentees we have that directory's full path after doing the push where ever _arg_working_dir was. FWIW AFAIK no one uses _arg_working_dir. So it is probably almost untested. But this seemed safe. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yes of course. Then please:
Suggested change
Please also drop or change the comment, it threw me off. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok sure! |
||||||
|
||||||
# make a path canonical to the working dir | ||||||
make_canonical_path() | ||||||
{ | ||||||
local p=$1 | ||||||
|
||||||
p=$(eval echo $p) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this line do? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This really sent me down a rabit hole which I could not resolve any other way. If you don't do the eval on the $arg* variable any shell expansion will not happen. So without that eval this: --extra-dirs=~/foo Will not resolve to your home dir. I tried for a while to get it to work. For some reason this only happens with the argbash variables and not with other variables defined in the script. Running eval made the shell expansion work as expected. So I went with it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I missed that shell expansion was an intended feature. It's really not a small thing that should be found by chance in line 155 and nowhere else. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm I don't love the eval.. (also is the echo redundant anyway?) Does something like this work?
|
||||||
pushd $working_dir > /dev/null | ||||||
p=$(realpath $p) | ||||||
popd > /dev/null | ||||||
echo $p | ||||||
} | ||||||
|
||||||
set_valid_mkosi_ver() | ||||||
{ | ||||||
"$mkosi_bin" --version | ||||||
|
@@ -1125,6 +1140,7 @@ make_rootfs() | |||||
process_mkosi_template "$tmpl" > "$dst" | ||||||
done | ||||||
|
||||||
# Add user space items from host | ||||||
rsync -a "${script_dir}"/mkosi/extra/ mkosi.extra/ | ||||||
|
||||||
# misc rootfs setup | ||||||
|
@@ -1148,17 +1164,30 @@ make_rootfs() | |||||
if [ -f ~/.vimrc ]; then | ||||||
rsync "${rsync_opts[@]}" ~/.vim* mkosi.extra/root/ | ||||||
fi | ||||||
mkdir -p mkosi.extra/root/bin | ||||||
if [ -d ~/git/extra-scripts ]; then | ||||||
rsync "${rsync_opts[@]}" ~/git/extra-scripts/bin/* mkosi.extra/root/bin/ | ||||||
fi | ||||||
if [[ $_arg_ndctl_build == "on" ]]; then | ||||||
if [ -n "$ndctl" ]; then | ||||||
rsync "${rsync_opts[@]}" "$ndctl/" mkosi.extra/root/ndctl | ||||||
prepare_ndctl_build # create mkosi.postinst which compiles | ||||||
fi | ||||||
fi | ||||||
|
||||||
if [[ "$_arg_extra_dirs" ]]; then | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No we are not checking for the file here. See comment above about the lack of shell expansion for _arg_extra_dirs. This check is simply for the value being set. If it is set we must canonicalize it before we can check for the file. Probably worth a comment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought the quotes would save us from special characters... :-/ ok I'll add it. Sorry was thinking -f. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
They may or may not depending on which Same with quotes: "When in doubt, double-quote every expansion in your shell commands." |
||||||
extra_dirs=$(make_canonical_path $_arg_extra_dirs) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the contrary it is required for shell expansion. See comment about the if check above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shell expansion is a pretty big thing, a much bigger "feature" IMHO than "canonical_path". The function name should reflect that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok one could make the argument you are making. But the function returnes the fully qualified canonical path. That is it's purpose. I submit that passing "~/foo" should resolve to "/home//foo" and that is what the user expects. The fact that eval is used to do that is irrelavant to what the user expects. Let me ask this another way. How else might "~" be expected to be interpreted if passed to this function? BTW this also works through eval: $HOME/foo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whatever happens what I don't want is to have to repeat this logic over and over for each path presented. We could insist that all paths be absolute in the config file... Maybe that would be ok... dunno? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually like that idea. absolute paths only. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is really not the question. The question is: "who knows what ELSE happens when using
My point exactly! And many, many other things: https://www.gnu.org/software/bash/manual/html_node/Shell-Expansions.html
If you mean: dropping shell expansion and But... dropping relative paths sounds like throwing the baby with the for src_line in...
( cd $working_dir
rsync -a "$src_line" ...
)
done If a relative "$src_line" is not found, rsync will just fail with a useful error message. |
||||||
if [[ ! -f $extra_dirs ]]; then | ||||||
fail "$extra_dirs not found" | ||||||
fi | ||||||
echo "Installing extra directories and files from: $extra_dirs" | ||||||
for d in `cat "$extra_dirs"`; do | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://www.shellcheck.net/wiki/SC2006
Don't forget the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I always forget about shellcheck... I'll try it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coding shell scripts without running shellcheck is now a crime :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW there are a few other warnings we should clean up if we are going to make that a requirement. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Absolutely! But shellcheck can catch codestyle issues and sometimes bugs even long before it is requirement :-) This only requires keep the number of warnings to a reasonable level not to drown the new ones. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yea probably better. cat just worked initially... :-D |
||||||
d=$(make_canonical_path $d) | ||||||
echo " $d" | ||||||
if [[ -e $d ]]; then | ||||||
rsync -a "$d" mkosi.extra/root/ | ||||||
else | ||||||
fail "$d not found" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good idea. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I missed that you are trying to use printf style here. Why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More flexible, safer, more consistent. But no big deal :-D |
||||||
fi | ||||||
done | ||||||
fi | ||||||
|
||||||
# timedatectl defaults to UTC when /etc/localtime is missing | ||||||
local bld_tz; bld_tz=$( timedatectl | awk '/zone:/ { print $3 }' ) | ||||||
# v15 commit f11325afa02c "Adopt systemd-firstboot" | ||||||
|
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 need to say that:
.
)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.
I was trying to keep the help small. But yea it is probably worth noting that any relative paths are to the working directory. I'll update it.
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.
Also: shell expansion that I mostly miss in the first review. It's really not a small thing.