-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathGenerateLinks.sh
executable file
·152 lines (122 loc) · 4.7 KB
/
GenerateLinks.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/bash
# This script places symbolic links to the most-used scripts into the specified directory
# (which is normally your personally 'Tools' or 'Utils' directory in the PATH).
#
# Copyright (c) 2017 R. Diez - Licensed under the GNU AGPLv3
set -o errexit
set -o nounset
set -o pipefail
# set -x # Enable tracing of this script.
abort ()
{
echo >&2 && echo "Error in script \"$0\": $*" >&2
exit 1
}
is_var_set ()
{
if [ "${!1-first}" == "${!1-second}" ]; then return 0; else return 1; fi
}
find_where_this_script_is ()
{
# In this routine, command 'local' is often in a separate line, in order to prevent
# masking any error from the external command inkoved.
if ! is_var_set BASH_SOURCE; then
# This happens when feeding the script to bash over an stdin redirection.
abort "Cannot find out in which directory this script resides: built-in variable BASH_SOURCE is not set."
fi
local SOURCE="${BASH_SOURCE[0]}"
local TRACE=false
while [ -h "$SOURCE" ]; do # Resolve $SOURCE until the file is no longer a symlink.
TARGET="$(readlink --verbose -- "$SOURCE")"
if [[ $SOURCE == /* ]]; then
if $TRACE; then
echo "SOURCE '$SOURCE' is an absolute symlink to '$TARGET'"
fi
SOURCE="$TARGET"
else
local DIR1
DIR1="$( dirname "$SOURCE" )"
if $TRACE; then
echo "SOURCE '$SOURCE' is a relative symlink to '$TARGET' (relative to '$DIR1')"
fi
SOURCE="$DIR1/$TARGET" # If $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located.
fi
done
if $TRACE; then
echo "SOURCE is '$SOURCE'"
fi
local DIR2
DIR2="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
if $TRACE; then
local RDIR
RDIR="$( dirname "$SOURCE" )"
if [ "$DIR2" != "$RDIR" ]; then
echo "DIR2 '$RDIR' resolves to '$DIR2'"
fi
fi
DIR_WHERE_THIS_SCRIPT_IS="$DIR2"
}
create_link ()
{
local SCRIPT="$DIR_WHERE_THIS_SCRIPT_IS/$1/$2"
local SYMLINK_NAME="$TARGET_DIR_ABS/$2"
if ! [ -x "$SCRIPT" ]; then
abort "Script \"$SCRIPT\" not found or not marked as executable."
fi
if [ -e "$SYMLINK_NAME" ] && ! [ -h "$SYMLINK_NAME" ]; then
abort "File \"$SYMLINK_NAME\" exists and is not a symbolic link."
fi
printf -v CMD "ln --symbolic --force -- %q %q" "$SCRIPT" "$SYMLINK_NAME"
echo "$CMD"
eval "$CMD"
}
# -------- Entry point --------
if [ $# -ne 1 ]; then
abort "You need to pass a single argument with the target directory."
fi
TARGET_DIR="$1"
TARGET_DIR_ABS="$(readlink --canonicalize-existing --verbose -- "$TARGET_DIR")"
find_where_this_script_is
create_link "BackupFiles" "packpass.sh"
create_link "Background" "background.sh"
create_link "PipeToClipboard" "pipe-to-clipboard.sh"
create_link "PipeToClipboard" "path-to-clipboard.sh"
create_link "CopyWithRsync" "copy-with-rsync.sh"
create_link "CopyWithRsync" "move-with-rsync.sh"
create_link "DesktopNotification" "DesktopNotification.sh"
create_link "FindUsbSerialPort" "FindUsbSerialPort.sh"
create_link "Git" "clean-git-repo.sh"
create_link "Git" "git-revert-file-permissions.sh"
create_link "Git" "pull.sh"
create_link "Git" "git-stash-only-staged-changes.sh"
create_link "Git" "git-stash-only-unstaged-changes.sh"
create_link "MountScripts" "mount-sshfs.sh"
create_link "MountScripts" "mount-gocryptfs.sh"
create_link "MountScripts" "mount-stacked.sh"
create_link "DiskUsage" "diskusage.sh"
create_link "PipeToEmacs" "pipe-to-emacs-server.sh"
create_link "PrintArgumentsWrapper" "print-arguments-wrapper.sh"
create_link "TakeOwnership" "takeownership.sh"
create_link "StartDetached" "StartDetached.sh"
create_link "xsudo" "xsudo.sh"
create_link "UpdateWithApt" "update-with-apt.sh"
create_link "RunInNewConsole" "run-in-new-console.sh"
create_link "RunInNewConsole" "open-serial-port-in-new-console.sh"
create_link "NoPassword" "nopassword-polkit.sh"
create_link "NoPassword" "nopassword-sudo.sh"
create_link "OfficeSoftwareAutomation" "copy-to-old-versions-archive.sh"
create_link "OfficeSoftwareAutomation" "move-to-old-versions-archive.sh"
create_link "Unpack" "unpack.sh"
create_link "FilterTerminalOutputForLogFile" "FilterTerminalOutputForLogFile.pl"
create_link "CountdownTimer" "CountdownTimer.pl"
create_link "AnnotateWithTimestamps" "AnnotateWithTimestamps.pl"
create_link "ImageTools" "TransformImage.sh"
create_link "RunAndWaitForAllChildren" "RunAndWaitForAllChildren.pl"
create_link "PlainTextLinter" "ptlint.pl"
create_link "OpenFileExplorer" "open-file-explorer.sh"
create_link "CreateTempDir" "create-temp-dir.sh"
create_link "RDChecksum" "rdchecksum.pl"
create_link "VNC" "vnc-addr-to-clipboard.sh"
create_link "VNC" "vnc-ipv6-addr-to-clipboard.sh"
create_link "LogPauseDetector" "LogPauseDetector.pl"
create_link "DateTime" "days.sh"