-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
438 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#! /bin/bash | ||
|
||
# create a symlink, idempotent | ||
# | ||
# (c) Thomas Lange 2019, lange@debian.org | ||
# | ||
# if $target is defined, create link relative to $target | ||
|
||
mk-link() { | ||
|
||
|
||
local from=$1 | ||
local to=$2 | ||
local oldto | ||
local vopt | ||
|
||
if [ X$verbose = X1 ]; then | ||
vopt=-v | ||
fi | ||
|
||
# todo: check if $from starts with a slash | ||
|
||
if [ -n "$target" ]; then | ||
from="$target$from" | ||
fi | ||
|
||
if [ ! -e $from -a ! -h $from ]; then | ||
ln -s $vopt $to $from | ||
return | ||
fi | ||
|
||
# check if already same link | ||
if [ -h $from ]; then | ||
oldto=$(readlink $from) | ||
if [ $oldto = $to ]; then | ||
if [ X$verbose = X1 ]; then | ||
printf "fai-link: Nothing to do for link $from -> $to\n" | ||
fi | ||
return | ||
fi | ||
fi | ||
|
||
# if different create new link | ||
ln -sf $vopt $to $from | ||
} | ||
|
||
# make link from to | ||
mk-link $1 $2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#! /bin/bash | ||
|
||
# fai-sed, call sed with diff before writing | ||
# | ||
# (c) Thomas Lange 2019, lange@debian.org | ||
# | ||
|
||
# idempotent sed. Execute sed command on a file | ||
# but do not overwrite file if nothing has changed | ||
|
||
dryrun=0 | ||
|
||
cmd=$1 | ||
shift | ||
filename=$1 | ||
shift | ||
|
||
if [ -z "$cmd" -o -z "$filename" ]; then | ||
printf "Please add filename and sed command\n" | ||
exit 3 | ||
fi | ||
|
||
# do not allow more than one file | ||
if [ -n "$1" ]; then | ||
printf "Aborting. Too many arguments.\n" | ||
exit 9 | ||
fi | ||
|
||
if [ -n "$target" ]; then | ||
filename="$target$filename" | ||
fi | ||
|
||
if [ ! -f $filename ]; then | ||
printf "WARNING: $filename does not exists. Skipping\n" | ||
exit 0 | ||
fi | ||
|
||
tmp=$(mktemp) | ||
trap "rm $tmp" EXIT | ||
|
||
printf "sed -e $cmd $filename: " | ||
# cp file so we can use sed -i, otherwise the new file created by sed has different chmod, owner | ||
cp -p $filename $tmp | ||
sed -i -e "$cmd" $tmp | ||
res=$? | ||
if [ $res -ne 0 ]; then | ||
printf "sed error $res\n" | ||
exit $res | ||
fi | ||
|
||
cmp -s $filename $tmp | ||
res=$? | ||
if [ $res -eq 2 ]; then | ||
printf " diff error $res. No changes made to $filename\n" | ||
exit 2 | ||
elif [ $res -eq 0 ]; then | ||
printf " No changes.\n" | ||
if [ $dryrun -eq 1 ]; then | ||
exit 0 | ||
fi | ||
else | ||
if [ $dryrun -eq 1 ]; then | ||
printf " Dry-run. Changes not applied.\n" | ||
exit 0 | ||
else | ||
mv $tmp $filename | ||
printf " File changed.\n" | ||
trap '' EXIT | ||
exit 1 | ||
fi | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.