blob: a2ac4fec0f225dafdc93dd42dce8b646b3ea4e14 [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001#! /usr/bin/env python3
Brad Bishopc342db32019-05-15 21:57:59 -04002#
3# SPDX-License-Identifier: GPL-2.0-only
4#
Patrick Williamsc124f4f2015-09-15 14:41:29 -05005
6# Create a *relative* symlink, just like ln --relative does but without needing
7# coreutils 8.16.
8
9import sys, os
10
11if len(sys.argv) != 3:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012 print("$ lnr TARGET LINK_NAME")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013 sys.exit(1)
14
15target = sys.argv[1]
16linkname = sys.argv[2]
17
18if os.path.isabs(target):
19 if not os.path.isabs(linkname):
20 linkname = os.path.abspath(linkname)
21 start = os.path.dirname(linkname)
22 target = os.path.relpath(target, start)
23
24os.symlink(target, linkname)