cant share files inside TEMP_DIR
This commit is contained in:
parent
05d867f59c
commit
a32c44f52d
1 changed files with 23 additions and 9 deletions
|
@ -1,5 +1,5 @@
|
|||
#!/bin/sh
|
||||
TEMP_DIR="$HOME/Public"
|
||||
TEMP_DIR="$HOME/Public/share"
|
||||
PORT=8000
|
||||
|
||||
help() {
|
||||
|
@ -7,22 +7,36 @@ help() {
|
|||
exit 0
|
||||
}
|
||||
|
||||
ifconfig_not_found() {
|
||||
printf "\033[31mError:\033[0m ifconfig not found\n"
|
||||
exit 0
|
||||
error() {
|
||||
printf "\033[31mError:\033[0m %s\n" "$1"
|
||||
exit 1
|
||||
}
|
||||
|
||||
LOC="$1"
|
||||
[ -n "$LOC" ] || help
|
||||
# If no location is given, print help and exit
|
||||
LOC="$1" ; [ -n "$LOC" ] || help
|
||||
|
||||
# Look for ifconfig
|
||||
[ -e "/sbin/ifconfig" ] && CMD="/sbin/ifconfig"
|
||||
[ -e "$(which ifconfig)" ] && CMD="ifconfig"
|
||||
[ -n "$CMD" ] || ifconfig_not_found
|
||||
[ -n "$CMD" ] || error "ifconfig not found"
|
||||
|
||||
# Use ifconfig to get ip address
|
||||
ADDR="$($CMD | grep 'broadcast' | sed 's/\s*inet\s*//g;s/\s*netmask.*//g')"
|
||||
|
||||
# If location is directory, define DIR as location,
|
||||
# otherwise, define DIR as TEMP_DIR
|
||||
[ -d "$LOC" ] && DIR="$LOC" || DIR="$TEMP_DIR"
|
||||
[ "$DIR" = "$TEMP_DIR" ] && mkdir -p "$TEMP_DIR" && cp -f "$LOC" "$DIR/"
|
||||
|
||||
# If file is inside TEMP_DIR, print error
|
||||
[ "$DIR" = "$TEMP_DIR" ] &&
|
||||
readlink -f "$LOC" | grep -q "$TEMP_DIR" &&
|
||||
error "File can't be inside $TEMP_DIR directory"
|
||||
|
||||
# If using TEMP_DIR, create dir and move
|
||||
# files inside dir
|
||||
[ "$DIR" = "$TEMP_DIR" ] &&
|
||||
rm -rf "$DIR" &&
|
||||
mkdir -p "$TEMP_DIR" &&
|
||||
cp -f "$LOC" "$DIR/"
|
||||
|
||||
python -m http.server -b "$ADDR" "$PORT" -d "$DIR"
|
||||
[ "$DIR" = "$TEMP_DIR" ] && rm -rf "$DIR"
|
||||
|
|
Loading…
Reference in a new issue