2016-06-27 19:00:19 +00:00
#!/bin/bash
2019-09-15 13:55:56 +00:00
install_packages() {
# After first run, set this:
# export INSTALL=echo
INSTALL=${INSTALL:-"sudo aptitude -y install"}
# The testsuite depends on this:
test_pkgs="imagemagick expect autossh sshpass jq libpod-simple-perl pod2pdf gawk"
2020-06-22 22:34:52 +00:00
test_pkgs="$test_pkgs lua5.3 clisp php-cli nodejs mono-csharp-shell libevent-dev"
2020-06-25 11:07:02 +00:00
test_pkgs="$test_pkgs tcl libtext-csv-perl xterm libc6-i386 libcrypt1:i386"
2019-09-15 13:55:56 +00:00
# DEBIAN package
2020-06-22 22:34:52 +00:00
packaging_pkgs="dpkg-dev build-essential debhelper osc cvs automake-1.15 python3-m2crypto"
2019-09-15 13:55:56 +00:00
# SHEBANG TOOLS
shebang_pkgs="gnuplot octave ruby r-base-core"
# SQL TOOLS
sql_pkgs="libdbd-pg-perl libdbd-sqlite3-perl libdbd-csv-perl libdbd-mysql-perl rlwrap"
# Compression
2020-06-22 22:34:52 +00:00
compression_pkgs="zstd clzip liblz4-tool lzop pigz pixz gzip plzip pbzip2 lzma xz-utils lzip bzip2 lbzip2 lrzip"
compression_pkgs_missing="pxz"
2019-09-15 13:55:56 +00:00
# Shells
2019-09-22 05:30:08 +00:00
# (csh = bsd-csh that is broken)
2020-06-22 22:34:52 +00:00
shell_pkgs="ash dash fdclone fish fizsh ksh ksh93 mksh posh rc rush sash tcsh yash zsh"
2019-09-15 13:55:56 +00:00
# Databases
database_pkgs="postgresql mysql-server sqlite"
2020-06-25 11:07:02 +00:00
sudo dpkg --add-architecture i386
2019-09-15 13:55:56 +00:00
if $INSTALL $test_pkgs $packaging_pkgs $shebang_pkgs $sql_pkgs $compression_pkgs $shell_pkgs $database_pkgs; then
# OK
true
else
echo Packages missing
2020-06-25 11:07:02 +00:00
return 1
2019-09-15 13:55:56 +00:00
fi
2020-06-25 11:07:02 +00:00
sudo apt update &
2019-09-15 13:55:56 +00:00
}
setup_databases() {
# DATABASES
echo '# Create PostgreSQL'
2020-06-25 11:07:02 +00:00
# Drop database and user if needed
sudo su - postgres -c 'dropdb '`whoami`
sudo su - postgres -c 'dropuser '`whoami`
2019-09-15 13:55:56 +00:00
sudo su - postgres -c 'createdb '`whoami`
sudo su - postgres -c 'createuser '`whoami`
sudo su - postgres -c "sql pg:/// \"ALTER USER \\\"`whoami`\\\" WITH PASSWORD '`whoami`';\""
mysqlrootpass=${mysqlrootpass:-b+Ydjq4ejT4E}
echo '# Create MySQL'
2020-06-25 11:07:02 +00:00
sudo su mysql mysqladmin create `whoami`
# Default Debian way of getting "root" access
sudo mysql --defaults-file=/etc/mysql/debian.cnf mysql <<< "ALTER USER 'root'@'localhost' IDENTIFIED BY '$mysqlrootpass';"
# Drop database and user if needed
2019-09-15 13:55:56 +00:00
sudo sql mysql://root:"$mysqlrootpass"@/mysql "DROP DATABASE `whoami`;DROP USER '`whoami`'@'localhost';"
sudo sql mysql://root:"$mysqlrootpass"@/mysql "CREATE DATABASE `whoami`;CREATE USER '`whoami`'@'localhost' IDENTIFIED BY '`whoami`'; GRANT ALL ON `whoami`.* TO '`whoami`'@'localhost';"
}
add_server_to_hosts() {
# Insert 127.1.2.3 server in /etc/hosts
if grep -q 127.1.2.3 /etc/hosts; then
# skip
true
else
printf "127.1.2.3\tserver\n" |
sudo tee -a /etc/hosts
fi
}
2020-01-09 13:37:41 +00:00
shellsplus() {
2020-06-22 22:34:52 +00:00
shells="bash sh csh ash dash tcsh zsh ksh ksh2020 ksh93 fish fizsh mksh posh rc sash yash nopathbash nopathcsh"
2020-01-09 13:37:41 +00:00
shellsplus="parallel $shells"
parallel -k echo ::: $shellsplus
}
2019-09-15 13:55:56 +00:00
create_shell_logins() {
# SHELLS
echo '# Create shell logins'
touch ~/.zshrc
del_add_user() {
shell="$1"
append-if-not-exists() {
file="$1"
shift
string="$@"
if grep -qF "$string" "$file"; then
# It is there already
echo "$string is already in $file"
else
echo "$string" | sudo tee -a "$file"
fi
}
2020-01-09 13:37:41 +00:00
SSHPASS=`goodpasswd`
export SSHPASS
2019-09-15 13:55:56 +00:00
append-if-not-exists /etc/shells $(which $shell || which ${shell#"nopath"})
sudo deluser $shell && sudo mv /home/$shell /tmp/$shell.$RANDOM
sudo groupdel $shell
if echo $shell | grep -q parallel; then
2020-01-09 13:37:41 +00:00
# User parallel should have /bin/bash
2019-09-15 13:55:56 +00:00
loginshell=/bin/bash
else
2020-01-09 13:37:41 +00:00
# Other users should have `which $shell` with nopath removed
2019-09-15 13:55:56 +00:00
loginshell=$(which $shell || which ${shell#"nopath"})
fi
sudo adduser --shell $loginshell --disabled-password --gecos "$shell for parallel,,," $shell &&
2020-01-09 13:37:41 +00:00
echo "$shell:$SSHPASS" | sudo chpasswd &&
sshpass -e ssh-copy-id $shell@lo &&
echo "$shell created"
2019-09-15 13:55:56 +00:00
}
export -f del_add_user
2020-01-09 13:37:41 +00:00
echo '# (Re-)create user'
# Racecondition: if multiple adds a group it will the same group ID
2020-06-22 22:34:52 +00:00
shellsplus | parallel --timeout 15 --retries 5 --tag -j1 del_add_user ||
(echo Creation failed: $?; false)
2020-01-09 13:37:41 +00:00
}
copy_ssh_keys() {
2019-09-15 13:55:56 +00:00
make_sshkey() {
shell="$1"
2020-01-09 13:37:41 +00:00
echo Add server keys for lo and server &&
2019-09-15 13:55:56 +00:00
ssh $shell@lo 'rm -f .ssh/id_rsa; ssh-keyscan lo >>.ssh/known_hosts; ssh-keyscan server >> .ssh/known_hosts' &&
echo Do ssh-keygen &&
echo | ssh -t $shell@lo ssh-keygen -b 1024 -f .ssh/id_rsa &&
echo Do ssh $shell@lo 'cat .ssh/id_rsa.pub >> .ssh/authorized_keys' &&
ssh $shell@lo 'cat .ssh/id_rsa.pub | tee -a .ssh/authorized_keys' |
ssh parallel@lo 'cat >> .ssh/authorized_keys' &&
ssh $shell@lo "echo ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAxg+dh+BL1myqo6A+pHcQCKVV5v7cewdkN8xGtMDqm7xGgh+e5A44W7qKViIx641d6yoWb012XzDz2MKetG4Kosoma8Z/qkS27p6901RmI3ap2JFffzBESlpQtW1FyxQPlMyBfrd4ONy8xW6R/gEkjC3yOcXCQO2494/c46ouXs5gtE84Cusr3RsopR4bI7oloH1GQZ4vsHSFSakq8IwcujaSh1mmribMONLb2TjDpmE7tAY+yfOVWHPQ2J+EU1//Go60EZfSRKOu81oxW7SJ2uGgWfWcs2T1lRtT8Yh+TwVTz8UFV75kVtpZ10x5baN+ncsSpaBK+8sFLfoMvA9yQQ'==' tange@freebsd71.tange.dk >> .ssh/authorized_keys" &&
echo Do env_parallel --install &&
ssh $shell@lo 'mkdir -p .parallel; touch .parallel/will-cite; env_parallel --install' &&
2020-06-22 22:34:52 +00:00
echo OK make_sshkey $shell &&
2019-09-15 13:55:56 +00:00
echo >&2 &&
2020-06-22 22:34:52 +00:00
echo OK make_sshkey $shell >&2 &&
2019-09-15 13:55:56 +00:00
echo
}
export -f make_sshkey
echo '# Make and copy sshkey'
2020-01-09 13:37:41 +00:00
shellsplus | parallel --timeout 20 --retries 5 --tag -j5 make_sshkey
2019-09-15 13:55:56 +00:00
ssh_a_to_b() {
ssh $1@lo ssh $2@lo echo OK ||
2020-06-22 22:34:52 +00:00
(echo failed && false)
2019-09-15 13:55:56 +00:00
}
export -f ssh_a_to_b
2020-01-09 13:37:41 +00:00
echo "# copy id from X to X"
shellsplus | parallel --timeout 10 --tag ssh_a_to_b {} {}
2019-09-15 13:55:56 +00:00
ssh_copy_id() {
from="$1"
to="$2"
ssh $from cat .ssh/id_rsa.pub | ssh $to 'cat >> .ssh/authorized_keys'
}
export -f ssh_copy_id
echo '# copy id from any X to any Y'
2020-01-09 13:37:41 +00:00
parallel -u --bar -j3 --timeout 3 --retries 10 --tag ssh_copy_id {1}@lo {2}@lo ::: $(shellsplus) ::: $(shellsplus)
2019-09-15 13:55:56 +00:00
echo '# Test the copying went well'
2020-06-22 22:34:52 +00:00
parallel --bar -j2 --timeout 9 --retries 10 --tag ssh_a_to_b ::: $(shellsplus) ::: $(shellsplus)
2019-09-15 13:55:56 +00:00
echo '# change paths to no path'
(
ssh nopathbash@lo 'echo > .bashrc PATH=/bin:/usr/bin'
ssh nopathbash@lo 'echo > .profile PATH=/bin:/usr/bin'
# Remove env_parallel from .profile
ssh nopathbash@lo 'perl -i.bak -pe s/.*env_parallel.*// .profile .bashrc'
ssh nopathcsh@lo 'echo >> .cshrc setenv PATH /bin:/usr/bin'
2019-09-22 05:30:08 +00:00
ssh nopathcsh@lo 'echo >> .login setenv PATH /bin:/usr/bin'
ssh nopathbash@lo 'echo $PATH; echo 1 | parallel echo' ||
echo Great - this should FAIL: parallel should not be found
ssh nopathcsh@lo 'echo $PATH; echo 1 | parallel echo' ||
echo Great - this should FAIL: parallel should not be found
2019-09-15 13:55:56 +00:00
)
}
lsh_setup() {
ssh-keyscan localhost >>~/.ssh/known_hosts
ssh-copy-id localhost
# SHELLS: lsh-client against openssh server
$INSTALL lsh-client
cd
mkdir -p .lsh
lsh-make-seed -o ".lsh/yarrow-seed-file"
lsh -c aes256-ctr --sloppy-host-authentication --capture-to ~/.lsh/host-acls lo echo Added host-auth
lsh -c aes256-ctr --sloppy-host-authentication --capture-to ~/.lsh/host-acls localhost echo Added host-auth
lsh-keygen | lsh-writekey -c none
lsh-export-key --openssh < ~/.lsh/identity.pub | lsh -c aes256-ctr lo 'cat >>.ssh/authorized_keys'
lsh-export-key --openssh < ~/.lsh/identity.pub | ssh csh@lo 'cat >>.ssh/authorized_keys'
2016-06-27 19:00:19 +00:00
}
2019-09-15 13:55:56 +00:00
add_freebsd() {
echo "# Add public key to freebsd7.t"
ssh freebsd7.t cat .ssh/id_rsa.pub | ssh parallel@localhost 'cat >>.ssh/authorized_keys'
echo Add:
echo HostkeyAlgorithms +ssh-dss
echo to .ssh/config if you get
echo no matching host key type found. Their offer: ssh-dss
echo
echo Add to /etc/ssh/sshd_config
2020-06-22 22:34:52 +00:00
echo Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-cbc
2019-09-15 13:55:56 +00:00
echo KexAlgorithms diffie-hellman-group-exchange-sha256,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,curve25519-sha256@libssh.org,diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1
echo
echo If you get:
echo Unable to negotiate with server port 22: no matching cipher found. Their offer: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se
echo add this to .ssh/config
echo Ciphers +aes256-cbc
2017-06-22 11:35:58 +00:00
}
2016-06-27 19:00:19 +00:00
2019-09-22 05:30:08 +00:00
tmux_versions() {
(cd /tmp
git clone https://github.com/tmux/tmux.git
make_one() {
rsync -a --delete tmux/ tmux$1/
cd tmux$1
git reset --hard
git checkout $1
./autogen.sh &&
./configure &&
make -j2 &&
sudo cp tmux /usr/local/bin/tmux-$1
}
export -f make_one
echo '# Building tmux'
seq 1.8 0.1 3.0 |
stdout parallel --lb --tag '/usr/local/bin/tmux-{} -V || make_one {}'
seq 1.8 0.1 3.0 |
parallel -k -v /usr/local/bin/tmux-{} -V
)
}
2020-06-25 11:07:02 +00:00
bash_versions() {
echo You may have to kill conftest
(cd /tmp
git clone https://git.savannah.gnu.org/git/bash.git
make_one() {
rsync -a --delete bash/ $1/
cd $1
git reset --hard
git checkout $1
LDFLAGS=-static ./configure &&
make -j2 &&
sudo cp bash /usr/local/bin/$1
}
export -f make_one
echo '# Building bash'
(cd bash; git tag | grep -v -- '-.*-') |
stdout parallel --lb --tag '/usr/local/bin/{} --version || make_one {}'
(cd bash; git tag | grep -v -- '-.*-') |
parallel -k -v --tag '/usr/local/bin/{} --version'
)
}
2019-09-15 13:55:56 +00:00
misc() {
parallel --record-env
2019-09-22 05:30:08 +00:00
#sudo cp /usr/bin/tmux /usr/local/bin/tmux1.8
# Build locale for LC_ALL=zh_HK.big5hkscs perl -e 1
sudo locale-gen zh_HK
2016-06-27 19:00:19 +00:00
}
2018-10-22 22:46:38 +00:00
2020-06-22 22:34:52 +00:00
run() {
install_packages &&
2019-09-15 13:55:56 +00:00
setup_databases &&
add_server_to_hosts &&
create_shell_logins &&
2020-01-09 13:37:41 +00:00
copy_ssh_keys &&
2019-09-15 13:55:56 +00:00
lsh_setup &&
add_freebsd &&
2020-01-12 08:14:21 +00:00
tmux_versions &&
2020-06-25 11:07:02 +00:00
bash_versions &&
2019-09-15 13:55:56 +00:00
misc
2020-06-22 22:34:52 +00:00
}