File: ocs-cmd-screen-sample

package info (click to toggle)
clonezilla 5.13.12-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 5,176 kB
  • sloc: sh: 41,198; perl: 193; python: 59; makefile: 26
file content (63 lines) | stat: -rwxr-xr-x 1,700 bytes parent folder | download | duplicates (2)
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
#!/bin/bash
# License: GPL 
# Author: Steven Shiau <steven _at_ clonezilla org>
# Description: Program to run the saved clonezilla command with or without screen/tmux"

ocscmd_=INSERT_HERE # <<< EDIT THIS LINE

# Settings
verbose="no"

#
USAGE() {
    echo "$ocs - To run the saved clonezilla command with or without screen/tmux"
    echo "Usage:"
    echo "To run $ocs:"
    echo "$ocs [OPTION] " 
    echo
    echo "Options:"
    echo "-v, --verbose  Run the command using verbose mode."
    echo "-s, --screen   Run the command inside a new screen session."
    echo "-t, --tmux     Run the command inside a new tmux session."
    echo "-h, --help     Display this help and exit."
    echo
    echo "If no option is provided, the command runs in the current terminal."
    echo
    echo "Example:"
    echo "To run the saved command inside a screen session, run:"
    echo "   $ocs -s"
    echo
} # end of USAGE


####################
### Main program ###
####################

ocs_file="$0"
ocs=`basename $ocs_file`
#
while [ $# -gt 0 ]; do
 case "$1" in
   -s|--screen)  mode="screen"; shift;;
   -t|--tmux)    mode="tmux"; shift ;;
   -v|--verbose) verbose="yes"; shift ;;
   -h|--help)    USAGE; exit 0 ;;
   -*) echo "${0}: ${1}: invalid option" >&2
       USAGE >& 2
       exit 2 ;;
   *)  # Stop parsing at the first non-option argument
       break ;;
 esac
done

if [ "$verbose" = "yes" ]; then
  ocscmd_="bash -x $ocscmd_"
fi

clear
case $mode in
  screen) screen bash -c "(TERM=dumb eval $ocscmd_; echo \$? > /tmp/screenlog.0) |& tee -a /tmp/screenlog.1" ;;
  tmux  ) tmux -c "(TERM=dumb eval $ocscmd_; echo \$? > /tmp/tmux.0) |& tee -a /tmp/tmux.1" ;;
  *)      eval $ocscmd_ ;;
esac