symlink enhancements

* runon -l now install symlink
* install -u now removes all found symlinks to runon
This commit is contained in:
Gilles Grandou 2021-05-01 16:28:24 +02:00
parent 96418fbbb5
commit 8b08aab4e7
3 changed files with 22 additions and 2 deletions

View File

@ -78,8 +78,7 @@ simply pass `-u` to install command you have used, eg.:
you can create soft links to `runos` to simplify calls: you can create soft links to `runos` to simplify calls:
cd /usr/local/bin runos centos7 -l
ln -s runon centos7
now calling `centos7 ...` is equivalent to call `runos centos7 ...`: now calling `centos7 ...` is equivalent to call `runos centos7 ...`:

View File

@ -89,6 +89,13 @@ elif [ "$op" = "installdev" ]; then
do_exec ln -s -f $(realpath runon) $bin_dir/ do_exec ln -s -f $(realpath runon) $bin_dir/
do_exec ln -s -f $(realpath runon.conf) $config_dir/ do_exec ln -s -f $(realpath runon.conf) $config_dir/
elif [ "$op" = "uninstall" ]; then elif [ "$op" = "uninstall" ]; then
# find all symlinks targetting to runon, and remove them
find $bin_dir -type l | while read l; do
if [ "$(readlink $l)" = "runon" ]; then
do_exec rm $l
fi
done
do_exec rm -f $bin_dir/runon do_exec rm -f $bin_dir/runon
do_exec rm -f $config_dir/runon.conf do_exec rm -f $config_dir/runon.conf
test -d $bin_dir && do_exec rmdir --parents --ignore-fail-on-non-empty $bin_dir 2> /dev/null test -d $bin_dir && do_exec rmdir --parents --ignore-fail-on-non-empty $bin_dir 2> /dev/null

14
runon
View File

@ -56,6 +56,13 @@ def load_config(user_confname, osname):
return conf return conf
def make_osname_link(binpath, osname):
link = os.path.join(os.path.dirname(binpath), osname)
try:
os.symlink('runon', link)
except FileExistsError:
pass
def make_image_name(osname): def make_image_name(osname):
user = getpass.getuser() user = getpass.getuser()
name = 'runon-{}-{}'.format(osname, user) name = 'runon-{}-{}'.format(osname, user)
@ -175,6 +182,8 @@ def main():
help='specify config file') help='specify config file')
parser.add_argument('-u', '--update', action='store_true', parser.add_argument('-u', '--update', action='store_true',
help='force image update') help='force image update')
parser.add_argument('-l', '--link', action='store_true',
help='create a symlink to call "osname" as a shortcut to "runon osname"')
parser.add_argument('command', nargs='*', default=None, parser.add_argument('command', nargs='*', default=None,
help = 'command to execute') help = 'command to execute')
@ -188,10 +197,15 @@ def main():
for o in sorted(osnames, key=natural_sortkey): for o in sorted(osnames, key=natural_sortkey):
print(' {}'.format(o)) print(' {}'.format(o))
print() print()
if args.link:
for o in osnames:
make_osname_link(sys.argv[0], args.osname)
return 0 return 0
client = docker.from_env() client = docker.from_env()
conf = load_config(args.config, args.osname) conf = load_config(args.config, args.osname)
if args.link:
make_osname_link(sys.argv[0], args.osname)
image = build_image(client, conf, args.update, args.verbose) image = build_image(client, conf, args.update, args.verbose)
container = create_container(client, image, conf, args.command, args.verbose) container = create_container(client, image, conf, args.command, args.verbose)
ret = run_container(client, container) ret = run_container(client, container)