config / .profile /
Newer Older
77 lines | 2.536kb
ajout .profile
Sébastien MARQUE authored on 2016-11-04
1
# ~/.profile: executed by the command interpreter for login shells.
2
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
3
# exists.
4
# see /usr/share/doc/bash/examples/startup-files for examples.
5
# the files are located in the bash-doc package.
6

            
7
# the default umask is set in /etc/profile; for setting the umask
8
# for ssh logins, install and configure the libpam-umask package.
9

            
protection pour accès shelli...
Sébastien MARQUE authored on 2019-05-03
10
if test -n "$SHELLINABOX_URL" -a -z "$TMUX"; then
11
    trap "exit 1" ZERR
12
    if test ${SHELLINABOX_URL/https???seb.lautre.net} = $(sed -rn '/^ *location /N;/try_files .* @shellinabox/s|^ *location +([^ ]+).*$|\1/|p' /etc/nginx/sites-available/default); then
13
        token=$(date +%s | sum)
14
        $HOME/scripts/smsapi "shellinabox code: ${token// *1}"
15
        read "user_token?token: "
16
        if test "$user_token" != "${token// *1}"; then
17
            exit 1
18
        fi
19
        unset token user_token
20
    else
21
        exit 1
22
    fi
23
    trap - ZERR
24
fi
25

            
ajout .profile
Sébastien MARQUE authored on 2016-11-04
26
is_from_localhost () {
27
    for localhost in $(grep localhost /etc/hosts); do
28
        [ "${localhost%% *}" = "$1" ] && return 0
29
    done
30
    return 1
31
}
32

            
33
if [ $UID -eq 0 ]; then
34
    umask 077
35
    echo -e "\e[1;31m$(diff --ignore-all-space --ignore-blank-lines ~/.profile ~chat/.profile)\e[0m" >&2
36
    if [ -n "$SSH_CONNECTION" ]; then
37
        is_from_localhost "${SSH_CLIENT%% *}" || exit
38
    fi
39
    crontab=/var/spool/cron/crontabs/$USER
40
    /usr/local/bin/upgrade_status -v date=$(date -d "$(awk '/^ *[^#].*unattended-upgrades$/{print $2 * 60 + $1}' $crontab) minutes ago" +%Y-%m-%d) \
41
        | egrep '^[1-9]'
42
fi
43

            
44
# if running bash
45
if [ -n "$BASH_VERSION" ]; then
46
    # include .bashrc if it exists
47
    if [ -f "$HOME/.bashrc" ]; then
48
	. "$HOME/.bashrc"
49
    fi
50
fi
51

            
52
# set PATH so it includes user's private bin if it exists
53
if [ -d "$HOME/bin" ] ; then
54
    PATH="$HOME/bin:$PATH"
55
fi
56

            
57
#if [ $UID -gt 0 -a -n "$SSH_TTY" -a -z "$STY" -a "$TERM" != "screen" ]; then
58
if [ $UID -gt 0 -a -n "$SSH_TTY" -a -z "$STY" ]; then
59
    if which tmux > /dev/null 2>&1; then
60
        if test -z "$TMUX"; then
61
            tmux attach || tmux
62
        fi
63
    elif which screen > /dev/null 2>&1; then
64
        screen -q -ls > /dev/null 2>&1
65
        nbr_sessions_screen=$?
66
        if [ $nbr_sessions_screen -eq 9 ]; then
67
            unset nbr_sessions_screen
68
            screen
69
        else
70
            unset nbr_sessions_screen
71
            screen_session=$(screen -ls | head -2 | tail -1 | awk '{print $1}')
72
            screen -x $screen_session
73
        fi
74
    else
75
        echo ni screen ni tmux...
76
    fi
77
fi