Skip to content
Snippets Groups Projects
Commit c9c8e381 authored by Fernando Herrero's avatar Fernando Herrero
Browse files

Scripts: remove default values and exit with error if those args are not specified

parent 7efbda08
No related branches found
No related tags found
No related merge requests found
......@@ -2,34 +2,57 @@
echo "--- add_manufacturer_to_group_udev.sh ---"
MANUFACTURER="Segway"
GROUP="dialout"
FILE="99-manufacturer-${MANUFACTURER}-to-group-${GROUP}.rules"
MANUFACTURER=
GROUP=
FILE=
UDEV_PATH="/etc/udev/rules.d"
usage() {
echo "Usage: $0 [-m <manufacturer>] [-g <group>] [-f <file> ]"
echo " -m specify manufacturer id. Default Segway"
echo " -g specify group id. Default dialout"
echo " -f specify udev file. Default 99-segway-to-dialout-group.rules"
echo " -m specify manufacturer id. For example, Segway"
echo " -g specify group id. For example, dialout"
echo " -f specify udev file. Default 99-manufacturer-<manufacturer>-to-group-<group>.rules"
exit 1
}
while getopts ":hm:g:f:" arg; do
case $arg in
m) MANUFACTURER=$OPTARG
FILE="99-manufacturer-${MANUFACTURER}-to-group-${GROUP}.rules"
;;
g) GROUP=$OPTARG
FILE="99-manufacturer-${MANUFACTURER}-to-group-${GROUP}.rules"
;;
f) FILE=$OPTARG;;
f) MANUAL_FILE=$OPTARG;;
h) usage;;
*) usage;;
esac
done
shift $((OPTIND-1))
if [ -z "$MANUAL_FILE" ]
then
FILE="99-manufacturer-${MANUFACTURER}-to-group-${GROUP}.rules"
else
FILE=$MANUAL_FILE
fi
if [ -z "$MANUFACTURER" ]
then
echo "Error: no manufacturer specified"
usage
fi
if [ -z "$GROUP" ]
then
echo "Error: no group specified"
usage
fi
if [ -z "$FILE" ]
then
echo "Error: empty file specified"
usage
fi
FILE="$UDEV_PATH/$FILE"
echo " Add udev rule so MANUFACTURER=${MANUFACTURER} devices are added to GROUP=${GROUP}."
......@@ -41,4 +64,4 @@ sudo touch $FILE
grep -qF -- "$LINE0" "$FILE" || echo "$LINE0" | sudo tee -a "$FILE" > /dev/null
sudo service udev restart
echo " Need to unplug-plug devices for changes to take effect"
echo " Need to unplug-plug devices for changes to take effect"
\ No newline at end of file
......@@ -24,7 +24,7 @@ shift $((OPTIND-1))
#check if device parameter is filled up
if [ ! "${DEVICE}" ]
then
echo "No device provided, aborting ..."
echo "Error: no device provided, aborting ..."
usage
exit 1
fi
......@@ -32,7 +32,7 @@ fi
#check if name parameter is filled up
if [ ! "${NAME}" ]
then
echo "No name provided, aborting ..."
echo "Error: no name provided, aborting ..."
usage
exit 1
fi
......@@ -41,4 +41,4 @@ fi
sudo slcand -o -s6 -S3000000 $DEVICE $NAME
sudo ifconfig $NAME up
exit 0
exit 0
\ No newline at end of file
......@@ -2,26 +2,18 @@
echo "--- unbind_ftdi_udev.sh ---"
# VENDOR=${1:-0403}
# PRODUCT=${2:-6001}
# SERIAL=${3:-A600eB1Y}
# FILE=${4:-99-ftdi.rules}
VENDOR="0403"
PRODUCT="6001"
SERIAL="A600eB1Y"
VENDOR=
PRODUCT=
SERIAL=
FILE="99-ftdi-unbind-by-serial.rules"
# SERIAL DABO: A600eB1Y
# SERIAL TIBI: A600eByq
# SERIAL TEO: A900WSG1
UDEV_PATH="/etc/udev/rules.d"
usage() {
echo "Usage: $0 [-v <vendor>] [-p <product>] [-s <serial>] [-f <file> ]"
echo " -v specify vendor id. Default 0403"
echo " -p specify product id. Default 6001"
echo " -s specify serial number. Default A600eB1Y"
echo " -f specify udev file. Default 99-ftdi-unbind-by-serial.rules"
echo " -v specify vendor id."
echo " -p specify product id."
echo " -s specify serial number."
echo " -f specify udev file. Default 99-ftdi-unbind-by-serial.rules"
exit 1
}
......@@ -37,8 +29,31 @@ while getopts ":hv:p:s:f:" arg; do
done
shift $((OPTIND-1))
if [ -z "$VENDOR" ]
then
echo "Error: no vendor specified"
usage
fi
if [ -z "$PRODUCT" ]
then
echo "Error: no product specified"
usage
fi
if [ -z "$SERIAL" ]
then
echo "Error: no serial specified"
usage
fi
if [ -z "$FILE" ]
then
echo "Error: empty file specified"
usage
fi
FILE=/etc/udev/rules.d/$FILE
FILE="$UDEV_PATH/$FILE"
echo " Add udev rule so VENDOR:PRODUCT:SERIAL=${VENDOR}:${PRODUCT}:${SERIAL} devices do not load ftdi_sio driver."
echo " Adding new lines to udev rule file: ${FILE}"
......
#!/bin/sh
# SERIAL=${3:-A600eB1Y}
# FILE=${4:-99-ftdi.rules}
echo "--- undo_unbind_ftdi_udev.sh ---"
SERIAL="A600eB1Y"
FILE="99-ftdi.rules"
# SERIAL DABO: A600eB1Y
# SERIAL TIBI: A600eByq
# SERIAL TEO: A900WSG1
SERIAL=
FILE="99-ftdi-unbind-by-serial.rules"
UDEV_PATH="/etc/udev/rules.d"
usage() {
echo "Usage: $0 [-v <vendor>] [-p <product>] [-s <serial>] [-f <file> ]"
echo " -s specify serial number. Default A600eB1Y"
echo " -f specify udev file. Default 99-ftdi.rules"
echo " -s specify serial number."
echo " -f specify udev file. Default 99-ftdi-unbind-by-serial.rules"
exit 1
}
......@@ -27,8 +23,19 @@ while getopts ":hv:p:s:f:" arg; do
done
shift $((OPTIND-1))
if [ -z "$SERIAL" ]
then
echo "Error: no serial specified"
usage
fi
if [ -z "$FILE" ]
then
echo "Error: empty file specified"
usage
fi
FILE=/etc/udev/rules.d/$FILE
FILE="$UDEV_PATH/$FILE"
echo "Undo addition of udev rule so VENDOR:PRODUCT:SERIAL=${VENDOR}:${PRODUCT}:${SERIAL} devices do not load ftdi_sio driver."
echo "Removing all lines containing SERIAL=${SERIAL} from file: ${FILE}"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment