What does this sed command do? when i run uname -m on my pc, it returns x86_64.
HOSTARCH := $(shell uname -m | \
sed -e s/i.86/i386/ \
-e s/sun4u/sparc64/ \
-e s/arm.*/arm/ \
-e s/sa110/arm/ \
-e s/powerpc/ppc/ \
-e s/macppc/ppc/)
Note: code snippet from x loader Makefile.
The sed tries to show what system you run with a more readable name.
Eks if you have i.86 it shows i386
But the one who made the script did forget the intel 64 bits x86_64.
Related
So I am downloading docker setup on my linux vm, and have to run this command as part of the steps, but even though it mentions url, and I changed once -o to -O but still getting those errors, what to do for this?
this is the command im running
sudo curl -L $(curl -L https://api.github.com/repos/docker/compose/releases/latest | grep "browser_download_url" | grep "$(uname -s)-$(uname -m)\"" | sed -nr 's/\s+"browser_download_url":\s+"(https.*)"/\1/p') -o /usr/local/bin/docker-compose
The grep that is filtering what system you are running is outputting an upper case L in Linux, this may be the cause of your errors. Try this:
sudo curl -L $(curl -L https://api.github.com/repos/docker/compose/releases/latest | grep "browser_download_url" | grep -i "$(uname -s)-$(uname -m)\"" | sed -nr 's/\s+"browser_download_url":\s+"(https.*)"/\1/p') -o /usr/local/bin/docker-compose
Hope this helps!
I'm trying to generate an RPM with a makefile, the behavior I'm expecting from the makefile is the following:
If RPM doesn't exist and the sources are not yet prepared, go ahead and do both: generate sources and then the RPM
If RPM already exist but the sources changed, go ahead and prepare the sources and generate the RPM once again
If the sources haven't changed and the RPM already exist don't do anything
However, right now the behavior I'm getting from the makefile below is not quite the way I want it, as it recognizes whether the RPM exist but when it comes down to the sources it doesn't really recognize that they already exist.
Here's the makefile:
SHELL = /bin/bash
.SHELLFLAGS = -o pipefail -c
COLORIZE := 2>&1 | sed -re "s/^(Executing|Wrote)(.*: )/"$$'\E'"[32m\1\2"$$'\E'"[0m/g" \
-e "s/(error[s]?)/"$$'\E'"[31m\1"$$'\E'"[0m/ig" \
-e "s/(warn|warning)/"$$'\E'"[33m\1"$$'\E'"[0m/ig"
SPEC := $(shell find . -name \*spec -printf '%f' -quit)
ARCH := $(shell rpm -q --qf '%{arch}' --specfile $(SPEC))
DIST := .el
NAME := $(basename $(SPEC))
RELEASE := $(shell rpm -q --qf '%{release}' --specfile $(SPEC) | cut -d. -f1)
VERSION := $(shell rpm -q --qf '%{version}' --specfile $(SPEC))
BUILDDIR := ./rpm-build
RPM := $(BUILDDIR)/RPMS/$(ARCH)/$(NAME)-$(VERSION)-$(RELEASE)$(DIST).$(ARCH).rpm
RPMBUILD := rpmbuild --define "_topdir %(pwd)/$(BUILDDIR)" \
--define "_source_filedigest_algorithm md5" \
--define "_binary_filedigest_algorithm md5" \
--define "_source_payload w9.gzdio" \
--define "_binary_payload w9.gzdio" \
--define "_sourcedir %{_topdir}/SOURCES" \
--define "_target_os linux" \
--define "dist .el"
SOURCE0 := $(BUILDDIR)/SOURCES/$(NAME)-$(VERSION).jar
.PHONY: all clean
all: $(RPM)
$(BUILDDIR):
#mkdir -p $(BUILDDIR)/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS,TEMP}
$(SOURCE0): $(BUILDDIR) $(SPEC)
spectool -g -C $(BUILDDIR)/SOURCES $(SPEC)
$(RPM): $(SPEC) $(SOURCE0)
#echo -e "Building $(RPM)"
$(RPMBUILD) -bb $< $(COLORIZE)
clean:
#- $(RM) -rf ./$(BUILDDIR)
Is there anything I'm doing wrong for managing the sources, I just don't want them to be prepared everytime I run a make command ?
You should never have a target with a directory as a prerequisite, because directory timestamps are updated at unusual times. I shouldn't say "never"; it can be very useful but it means something quite different than what you think.
You can try using an order-only prerequisite for this:
$(BUILDDIR):
#mkdir -p $(BUILDDIR)/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS,TEMP}
$(SOURCE0): $(SPEC) | $(BUILDDIR)
spectool -g -C $(BUILDDIR)/SOURCES $(SPEC)
Or you can just put the mkdir inside the recipe:
$(SOURCE0): $(SPEC)
#mkdir -p $(BUILDDIR)/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS,TEMP}
spectool -g -C $(BUILDDIR)/SOURCES $(SPEC)
Note, you're using bash-specific issues here ({}). If you want to be portable you need to add:
SHELL := /bin/bash
to your makefile.
I try to execute etherwake based on a MQTT topic.
The output of mosquitto_sub stops if I pipe it in a while statement.
works:
# mosquitto_sub -L mqtt://... | grep -o -E '([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}'
00:00:00:00:de:ad
00:00:00:00:be:ef
00:00:00:00:ca:fe
(goes on and on)
does not work:
mosquitto_sub -L mqtt://... \
| grep -o -E '([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}' \
| hexdump
Output stops after a single line:
0000000 1234 5678 9abc def0 abcd cafe 3762 3a65
The big picture is this one:
mosquitto_sub -L mqtt://... \
| grep -o -E '([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}' \
| while read macaddr; do
echo "send WOL to " $macaddr;
/usr/bin/etherwake -D -b "$macaddr" 2>&1;
done
Usually I am fine with the Linux shell but this time it simply gets stuck after the first line.
My guess is there is some problem with stdin or stdout (is not read or full etc.) in some kind. But I am out ideas.
By the way its an OpenWRT shell so an ash and no bash.
The problem is indeed the "buffering" of grep when used with pipes.
Usually the '--line-buffered' switch should be used to force grep to process the data line by line instead of buffer the data.
Because grep on OpenWRT (busybox) does not have this switch 'awk' is used:
mosquitto_sub -L mqtt://... \
| awk '/([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}/{ print $0 }' \
| hexdump
If there is no busybox version of grep used the solution would be like:
mosquitto_sub -L mqtt://... \
| grep -o --line-buffered -E '([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}' \
| hexdump
Thank you all a lot for your help.
I have quite often some very long console commands like:
python /var/www/closure-library/closure/bin/calcdeps.py \
-i myJSFile.js \
-p ../closure-library/closure/goog/ \
-o compiled \
-c /var/www//closure-compiler/build/compiler.jar \
-f "--compilation_level=ADVANCED_OPTIMIZATIONS" \
-f "--define=goog.LOCALE='de'" > myOutputFile.js
and I would like to use simply:
closure -i myJSFile.js -o myOutputFile.js
or something simmilar. How can I do this?
Look up aliases in your shell's manpage.
Perhaps something like:
alias closure='python /var/www/closure-library/closure/bin/calcdeps.py -p ../closure-library/closure/goog/ -c /var/www//closure-compiler/build/compiler.jar -f "--compilation_level=ADVANCED_OPTIMIZATIONS" -o compiled'
Then you could do
$ closure -i myJSFile.js > myOutputFile.js
You can write a script too and handle -o myOutputFile.js option.
#!/bin/bash
if [ $# -ne 2 ]; then
echo "Usage: closure InputFile OutputFile"
exit 1
fi
python /var/www/closure-library/closure/bin/calcdeps.py \
-i "$1" \
-p ../closure-library/closure/goog/ \
-o compiled \
-c /var/www//closure-compiler/build/compiler.jar \
-f "--compilation_level=ADVANCED_OPTIMIZATIONS" \
-f "--define=goog.LOCALE='de'" > "$2"
And you could do closure myJSFile.js myOutputFile.js
I'm trying to port some jenkins bash scripts from Ubuntu to OS X. The linux (and I think it is originally GNU) chmod has a --reference option that allows copying the mode from a reference file. I am looking for the equivalent code for OS X, preferably without installing extra packages. Even better would be a cross-platform solution.
The concrete snippet:
# expand all the templates
find "$OUTPUT_PATH" -name "*.template" | while read FILE ; do
sed \
-e "s/%{NAME}/$OPTION_NAME/g" \
-e "s/%{TITLE}/$OPTION_TITLE/g" \
-e "s/%{VERSION}/$OPTION_VERSION/g" \
-e "s/%{WHEN}/$OPTION_WHEN/g" \
"$FILE" > "${FILE%.*}"
chmod --reference="$FILE" "${FILE%.*}"
rm -f "$FILE"
done
[edit] The combination of stat -r with saving the file mode is the right combination, stat -c doesn't exist on OS X
Copy the file first and only then overwrite with a shell redirection. This should preserve the original permissions.
How about using the format switch to FreeBSD stat:
stat -f "%p" ~/.bashrc
stat -f "%Sp" ~/.bashrc
stat -f "%u:%g:%p" ~/.bashrc
If your OS X has the stat command
# expand all the templates
find "$OUTPUT_PATH" -name "*.template" | while read FILE ; do
savemod=$(stat -c "%a" "$FILE")
sed \
-e "s/%{NAME}/$OPTION_NAME/g" \
-e "s/%{TITLE}/$OPTION_TITLE/g" \
-e "s/%{VERSION}/$OPTION_VERSION/g" \
-e "s/%{WHEN}/$OPTION_WHEN/g" \
"$FILE" > "${FILE%.*}"
chmod $savemod "${FILE%.*}"
rm -f "$FILE"
done
If it doesn't have -c option, check the man page of stat under formatting. you can find similar ways to get the permission/mode of the file.