Compare commits

..

No commits in common. "8b08aab4e75b0900adc0d58e83e5d1a3e1c80063" and "6459d3d7a313eb4740507f015f7d5d804b496181" have entirely different histories.

3 changed files with 4 additions and 54 deletions

View File

@ -78,7 +78,8 @@ 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:
runos centos7 -l cd /usr/local/bin
ln -s runon centos7
now calling `centos7 ...` is equivalent to call `runos centos7 ...`: now calling `centos7 ...` is equivalent to call `runos centos7 ...`:

15
install
View File

@ -66,14 +66,6 @@ while [ $# -gt 0 ]; do
shift shift
done done
bin_dir=$(realpath $bin_dir)
config_dir=$(realpath $config_dir)
if [[ ":$PATH:" != *":$bin_dir:"* ]]; then
echo "WARNING: $bin_dir is not in your PATH, runon will not be automatically found."
echo
fi
set -e set -e
if [ "$op" = "install" ]; then if [ "$op" = "install" ]; then
@ -89,13 +81,6 @@ 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

40
runon
View File

@ -16,11 +16,7 @@ import subprocess
from pprint import pprint from pprint import pprint
def natural_sortkey(string): def load_config(user_confname, osname):
tokenize = re.compile(r'(\d+)|(\D+)').findall
return tuple(int(num) if num else alpha for num, alpha in tokenize(string))
def read_ini(user_confname, osname=''):
ini_list = [ 'runon.conf', '.runon.conf', os.path.join(xdg.BaseDirectory.xdg_config_home, 'runon', 'runon.conf'), '/etc/runon/runon.conf' ] ini_list = [ 'runon.conf', '.runon.conf', os.path.join(xdg.BaseDirectory.xdg_config_home, 'runon', 'runon.conf'), '/etc/runon/runon.conf' ]
defaults = { defaults = {
'osname': osname, 'osname': osname,
@ -30,14 +26,6 @@ def read_ini(user_confname, osname=''):
ini_list.insert(0, user_confname) ini_list.insert(0, user_confname)
ini = configparser.ConfigParser(defaults=defaults, interpolation=configparser.ExtendedInterpolation()) ini = configparser.ConfigParser(defaults=defaults, interpolation=configparser.ExtendedInterpolation())
ini.read(ini_list) ini.read(ini_list)
return ini
def list_osnames(user_confname):
ini = read_ini(user_confname)
return ini.sections()
def load_config(user_confname, osname):
ini = read_ini(user_confname, osname)
if not ini.has_section(osname): if not ini.has_section(osname):
print('ERROR: cannot find configuration for distribution "{}"'.format(osname)) print('ERROR: cannot find configuration for distribution "{}"'.format(osname))
sys.exit(1) sys.exit(1)
@ -56,13 +44,6 @@ 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)
@ -172,9 +153,7 @@ def main():
else: else:
parser.description = 'run commands on any distribution' parser.description = 'run commands on any distribution'
parser.add_argument('osname', parser.add_argument('osname',
help = 'distribution name to run on, ' help = 'distribution name to run on')
'"list" to dump all available distributions')
parser.epilog = '(c) 2021 Gilles Grandou <gilles@grandou.net>'
parser.add_argument('-v', '--verbose', action='store_true', parser.add_argument('-v', '--verbose', action='store_true',
help='verbose output') help='verbose output')
@ -182,8 +161,6 @@ 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')
@ -191,21 +168,8 @@ def main():
if osname: if osname:
args.osname = osname args.osname = osname
if args.osname == 'list':
osnames = list_osnames(args.config)
print('Available distributions:')
for o in sorted(osnames, key=natural_sortkey):
print(' {}'.format(o))
print()
if args.link:
for o in osnames:
make_osname_link(sys.argv[0], args.osname)
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)