generated from NAMEER242/application-manager-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apps_linker
executable file
·43 lines (36 loc) · 1.41 KB
/
apps_linker
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
#!/usr/bin/env bash
set -e
# Get the directory of the project (application-manager)
APPLICATION_MANAGER_DIR="$(dirname "$(readlink -f "$0")")"
# Source the environment file and common functions
. "$APPLICATION_MANAGER_DIR/config.env"
. "$APPLICATION_MANAGER_DIR/common"
# Directory containing commands folders
APPLICATIONS_DIR="$APPLICATIONS_FOLDER_DIR"
# Directory where symlinks will be created
LINK_DIR="$LINK_FOLDER_DIR"
COMMAND_EXTENSION="$APPLICATIONS_COMMAND_EXTENSION"
# Check if the link directory exists
if [[ ! -d "$LINK_DIR" ]]; then
echo "Link directory does not exist."
return 1
fi
# Remove all existing symlinks
delete_linked_commands "$LINK_FOLDER_DIR" "$APPLICATION_MANAGER_DIR/applications"
# Iterate over each script in the subfolders and create new symlinks
for script in "$APPLICATIONS_DIR"/*/*$COMMAND_EXTENSION; do
# Check if the file exists before proceeding
if [[ -f "$script" ]]; then
script_name=$(basename "$script" $COMMAND_EXTENSION)
# Check if script_name is defined and not empty
if [[ -n "$script_name" ]]; then
sudo ln -s "$script" "$LINK_DIR/$script_name"
log "command [ $script_name ] registered successfully."
else
log "can not resolve script name for $script"
fi
else
log "No .amc files found in $APPLICATIONS_DIR"
fi
done
sudo find $APPLICATION_MANAGER_DIR -type f -exec chmod 777 {} \;