80 lines
1.4 KiB
Bash
Executable File
80 lines
1.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
HELP=$(cat <<'EOF'
|
|
Missing required args:
|
|
|
|
-i - ID
|
|
-w - Watching path
|
|
EOF
|
|
)
|
|
|
|
POETRY=$(which poetry)
|
|
|
|
if [ -z $POETRY ]; then
|
|
echo "You need Poetry to be installed"
|
|
exit 1
|
|
fi
|
|
|
|
while getopts ":i:w:" opt; do
|
|
case $opt in
|
|
i) ID="$OPTARG"
|
|
;;
|
|
w) WATCH_DIR="$OPTARG"
|
|
;;
|
|
\?) echo "Invalid option -$OPTARG" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
case $OPTARG in
|
|
-*) echo "Option $opt needs a valid argument"
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [ -z $WATCH_DIR ]; then
|
|
echo "$HELP"
|
|
exit -1
|
|
fi
|
|
|
|
printf "WATCH_DIR = %s\n" "$WATCH_DIR"
|
|
|
|
FNAME="git-pusher-$ID.service"
|
|
SERVICEPATH="$HOME/.config/systemd/user/"
|
|
mkdir -p "$SERVICEPATH"
|
|
SERVICEFILE="$SERVICEPATH/$FNAME"
|
|
|
|
echo "FNAME = $FNAME"
|
|
echo "SERVICEFILE = $SERVICEFILE"
|
|
|
|
if [ -f $SERVICEFILE ]; then
|
|
echo "Disabling current service..."
|
|
systemctl --user stop $FNAME
|
|
systemctl --user disable $FNAME
|
|
systemctl --user daemon-reload
|
|
sudo rm $SERVICEFILE
|
|
fi
|
|
|
|
echo "Preparing"
|
|
|
|
poetry lock
|
|
poetry install
|
|
|
|
echo "Creating service file..."
|
|
|
|
touch "$SERVICEFILE"
|
|
cat git-pusher.service | sed 's?<DIR>?'`pwd`'?' | sed 's?<WATCH_DIR>?'$WATCH_DIR'?' | sed 's?<POETRY>?'$POETRY'?' | tee -a "$SERVICEFILE" > /dev/null
|
|
|
|
echo "Reloading daemons..."
|
|
|
|
systemctl --user daemon-reload
|
|
|
|
echo "Enabling daemon for user..."
|
|
|
|
systemctl --user enable $FNAME
|
|
|
|
echo "Starting daemon for user..."
|
|
|
|
systemctl --user start $FNAME
|