forked from tmp2000/utiliscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmove-in
executable file
·981 lines (814 loc) · 31.9 KB
/
move-in
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
#!/bin/bash
#
# Barge in to a new system and make it mine.
#
# + Insures the machine has a public / private key pair
# stored in a location where it will be backed up.
#
# + Pulls down utiliscripts and adds them to the PATH.
#
# + Installs Drush, Sublime Text and other useful tools
# that I use.
#
# + Sets up bash settings and other system preferences.
#
# Note that it is safe to move-in to machines with no
# GUI (graphic tool configuration skipped if X not available),
# and it is safe to run move-in multiple times (e.g. to update
# configuration when move-in script is modified).
#
# Good follow-up commands include:
#
# install-components
# repair-ubuntu
#
SELF_DIRNAME="`dirname -- "$0"`"
# Get the OS name; convert "MINGW..." to "Windows"
OS="$(uname -s)"
if [ "$OS" != "${OS/MINGW}" ] ; then
OS=Windows
fi
# Don't allow this as root unless you have logge in as root.
# I don't know that I recommend running this as root, but neither do I prevent it.
if [ "$USER" == "root" ] && [ "$HOME" != "/root" ]
then
echo "Do not run this script via sudo root"
exit 1
fi
# There are some customization steps that we will skip in
# remote (ssh) environments, such as headless virtual machines,
# hosting providers, etc. Note, however, that we assume that
# such remote machines will always be Linux, or Linux-like
# systems. We do not support headless Mac or Windows installs.
HAS_DISPLAY=true
if [ "$OS" != "WINDOWS" ] && [ "$OS" != "Darwin" ] && [ -z "$DISPLAY" ] ; then
HAS_DISPLAY=false
fi
# Default location to pull installation data from. Before running this script,
# define:
#
# export [email protected]:my_installdata.git
[ -z "$INSTALLATION_DATA" ] && export INSTALLATION_DATA="$HOME/local/installdata"
if [ -z "$INSTALLATION_DATA_REPO" ] ; then
if [ "$USER" == "ga" ]
then
export [email protected]:installdata.git
fi
fi
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#
# G E T I N S T A L L D A T A
#
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo "# Check install data..."
# If we do not already have the installation data, then get it with git
if [ ! -d "$INSTALLATION_DATA" ] && [ -n "$INSTALLATION_DATA_REPO" ] ; then
(
mkdir -p "$(dirname $INSTALLATION_DATA)"
cd "$(dirname $INSTALLATION_DATA)"
git clone "$INSTALLATION_DATA_REPO"
)
fi
if [ -f "$INSTALLATION_DATA/moveinrc" ] ; then
source "$INSTALLATION_DATA/moveinrc"
fi
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#
# S E T D E F A U L T L O C A T I O N S
#
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# Set up some default locations
[ -z "$UTILISCRIPTS" ] && export UTILISCRIPTS="$HOME/local/utiliscripts"
[ -z "$HISTORYRECALL" ] && export HISTORYRECALL="$HOME/local/history-recall"
[ -z "$CONFIG" ] && export CONFIG="$HOME/local/config"
[ -z "$SSH_KEY_ARCHIVE" ] && export SSH_KEY_ARCHIVE="$INSTALLATION_DATA/ssh_key_archive"
[ -z "$DESKTOP_BACKGROUND_DIR" ] && export DESKTOP_BACKGROUND_DIR="$INSTALLATION_DATA/DesktopBackgrounds"
# Location of per-user repositories
if [ -z "$CONFIG_REPO" ] ; then
if [ "$USER" == "ga" ]
then
export [email protected]:config.git
fi
fi
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#
# I N S U R E S S H K E Y P A I R S A R E S E T U P
#
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo "# Check ssh keys..."
host="$(hostname)"
keytype=rsa
mkdir -p "$HOME/.ssh"
chmod 700 "$HOME/.ssh"
archive_key="$SSH_KEY_ARCHIVE/${host}_id_rsa"
if [ -f "${archive_key%rsa}"dsa ]
then
archive_key="${archive_key%rsa}"dsa
keytype=dsa
fi
# If we do not have a public/private key pair for this machine, then generate or restore one
if [ ! -f "$HOME/.ssh/id_$keytype" ]
then
if [ -f "$archive_key" ] && [ -f "${archive_key}.pub" ]
then
echo "Restoring public / private key pair for $host"
cp -f "$archive_key" "$HOME/.ssh/id_${keytype}"
cp -f "${archive_key}.pub" "$HOME/.ssh/id_${keytype}.pub"
chmod 600 "$HOME/.ssh/id_${keytype}"
chmod 600 "$HOME/.ssh/id_${keytype}.pub"
else
echo "Generating a public / private key pair for this system; please protect it with a password."
ssh-keygen -t $keytype -f "$HOME/.ssh/id_$keytype"
fi
fi
if [ -f "$HOME/.ssh/id_$keytype.pub" ] ; then
echo "ssh key fingerprint for public key:"
ssh-keygen -lf "$HOME/.ssh/id_$keytype.pub"
fi
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#
# A R C H I V E K E Y P A I R S
#
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo "# Check ssh key archive..."
CREATE_KEY_ARCHIVE=false
if [ ! -d "$(dirname "$SSH_KEY_ARCHIVE")" ]
then
CREATE_KEY_ARCHIVE=true
fi
mkdir -p "$SSH_KEY_ARCHIVE"
# If we have an archive of the public / private key pair for this machine, make sure it is accurate.
# If the key has not been archived yet, then archive it.
if [ -f "$archive_key" ] && [ -f "${archive_key}.pub" ]
then
diff -q "$HOME/.ssh/id_${keytype}" "$archive_key"
if [ $? != 0 ]
then
echo "WARNING: The archived key for $host is different than the current public / private key pair."
echo "Remove one of the following pairs, then run this script again to fix:"
echo " rm \"$archive_key\" \"${archive_key}.pub\""
echo " - OR -"
echo " rm \"$HOME/.ssh/id_$keytype\" \"$HOME/.ssh/id_${keytype}.pub\""
exit 1
else
echo "# Public and private key already archived as ${archive_key##*/}"
fi
else
echo "# Archiving public / private key pair for $host..."
cp -f "$HOME/.ssh/id_${keytype}" "$archive_key"
cp -f "$HOME/.ssh/id_${keytype}.pub" "${archive_key}.pub"
# Try to give the private key a new password, using empty for
# the current password. If this works, then balk.
ssh-keygen -p -P "" -N "empty_passwords_are_bad" -f "$archive_key" > /dev/null 2>&1
if [ $? == 0 ]
then
echo "WARNING: The password for id_${keytype} for $host is empty; private key REMOVED from archive."
rm -f "$archive_key"
else
if [ -d "$INSTALLATION_DATA/.git" ] ; then
(
cd "$SSH_KEY_ARCHIVE"
git add .
git commit -m "Add new keypair for ${host}"
git push
)
fi
fi
fi
if $CREATE_KEY_ARCHIVE
then
cp "$SELF_DIRNAME/example.moveinrc" "$(dirname "$SSH_KEY_ARCHIVE")/moveinrc"
(
cd "$(dirname "$SSH_KEY_ARCHIVE")"
git init
git add .
git commit -m "Automatically create an installdata project to store key pairs in"
)
fi
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#
# G E T C O M P O S E R
#
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# https://getcomposer.org/doc/00-intro.md#system-requirements
if [ -z "$(which composer)" ] && [ -n "$(which php)" ] ; then
curl -sS https://getcomposer.org/installer | php
mkdir -p "$HOME/bin"
mv composer.phar "$HOME/bin/composer"
if [ -z "$(which composer)" ] ; then
sed -i '1i export PATH=$PATH:$HOME/bin' ~/.bashrc
export PATH="$PATH:$HOME/bin"
fi
fi
# Make sure that $HOME/bin is on our PATH
if [ "$PATH" == "${PATH/$HOME/}" ] ; then
export PATH="$HOME/bin:$PATH"
fi
# Insure that the vendor/bin directory is on our PATH as well
if [ "$PATH" == "${PATH/.composer/}" ] ; then
export PATH="$HOME/.composer/vendor/bin:$PATH"
fi
if [ ! -f "$HOME/.bashrc" ] ; then
echo "# Initial .bashrc created by move-in script." > "$HOME/.bashrc"
fi
chkbashrc="$(grep 'composer/vendor/bin' "$HOME/.bashrc")"
if [ "X$chkbashrc" = "X" ] ; then
sed -e '/^ *$/,$ d' "$HOME/.bashrc" > "$HOME/.bashrc-head"
sed -e '1,/^ *$/ d' "$HOME/.bashrc" > "$HOME/.bashrc-body"
cp "$HOME/.bashrc-head" "$HOME/.bashrc"
cat <<- __END__ >> "$HOME/.bashrc"
[ "\$PATH" == "\${PATH/\$HOME/}" ] && export PATH="\$HOME/bin:\$PATH"
[ "\$PATH" == "\${PATH/.composer/}" ] && export PATH="\$HOME/.composer/vendor/bin:\$PATH"
__END__
cat "$HOME/.bashrc-body" >> "$HOME/.bashrc"
rm "$HOME/.bashrc-head"
rm "$HOME/.bashrc-body"
fi
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#
# G E T C O N F I G
#
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo "# Check config..."
# If we do not already have the config project, then get it with git
if [ ! -d "$CONFIG" ] && [ -n "$CONFIG_REPO" ] ; then
(
mkdir -p "$(dirname "$CONFIG")"
cd "$(dirname "$CONFIG")"
git clone "$CONFIG_REPO"
)
fi
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#
# G E T U T I L I S C R I P T S
#
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo "# Check utiliscripts..."
# If we do not already have utiliscripts, then get them with git
if [ ! -d "$UTILISCRIPTS" ] ; then
(
mkdir -p "$(dirname "$UTILISCRIPTS")"
cd "$(dirname "$UTILISCRIPTS")"
# read+write if "utiliscripts" is in $MAINTAINER, read-only otherwise
if [ "${MAINTAINER}" != "${MAINTAINER/utiliscripts/}" ]
then
git clone [email protected]:greg-1-anderson/utiliscripts.git
if [ $? <> 0 ]
then
echo "Could not clone a r/w copy of utiliscripts; cloning a r/o copy instead."
fi
fi
if [ ! -d "$UTILISCRIPTS" ] ; then
git clone git://github.com/greg-1-anderson/utiliscripts.git
fi
)
fi
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#
# G E T H I S T O R Y R E C A L L
#
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo "# Check history-recall..."
if [ ! -d "$HISTORYRECALL" ] ; then
(
mkdir -p "$(dirname "$HISTORYRECALL")"
cd "$(dirname "$HISTORYRECALL")"
# read+write if "history-recall" is in $MAINTAINER, read-only otherwise
if [ "${MAINTAINER}" != "${MAINTAINER/history-recall/}" ]
then
git clone [email protected]:greg-1-anderson/history-recall.git
if [ $? <> 0 ]
then
echo "Could not clone a r/w copy of history-recall; cloning a r/o copy instead."
fi
fi
if [ ! -d "$HISTORYRECALL" ] ; then
git clone git://github.com/greg-1-anderson/history-recall.git
fi
)
fi
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#
# G E T D R U S H
#
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if [ -n "$(which php)" ] && [ -n "($which composer)" ] ; then
echo "# Check drush..."
# If we do not already have drush, then get the master branch with git
DRUSH="$(which drush)"
# Install Drush via composer
composer global require drush/drush:dev-master --prefer-source
DRUSH="$(which drush)"
# The old way to install
if [ -z "$DRUSH" ] && [ ! -d "$HOME/local/drupal/drush" ] ; then
(
mkdir -p "$HOME/local/drupal"
pr_remote=drush-ops
cd "$HOME/local/drupal"
# read+write if "drush" is in $MAINTAINER, read-only otherwise
if [ "${MAINTAINER}" != "${MAINTAINER/drush/}" ]
then
git clone [email protected]:greg-1-anderson/drush.git
if [ ! -d drush ]
then
echo "Could not clone a r/w copy of drush; cloning a r/o copy instead."
else
(
cd drush
git remote add drush-ops [email protected]:drush-ops/drush.git
)
fi
fi
if [ ! -d drush ] ; then
git clone git://github.com/drush-ops/drush.git
pr_remote=origin
fi
)
# TODO:
#
# Add the "pr" line to the $pr_remote entry (drush-ops or origin)
#
#[remote "drush-ops"]
# url = [email protected]:drush-ops/drush.git
# fetch = +refs/heads/*:refs/remotes/drush-ops/*
# fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
fi
if [ -z "$DRUSH" ] && [ -d "$HOME/local/drupal/drush" ]
then
DRUSH="$HOME/local/drupal/drush/drush"
fi
echo "# Check drush extensions..."
DRUSH_EXTENSIONS="$HOME/local/drupal/drush_extensions"
mkdir -p "$DRUSH_EXTENSIONS"
# drupalcs \
for drush_extension in \
drush_sup \
drush_iq \
drush_extras \
dbtng_migrator \
registry_rebuild \
sublime_completion \
grn-6.x \
module_builder \
drush_deploy \
cacheaudit \
; do
extension_shortname=$(echo $drush_extension | sed -e 's|-[0-9]*\.x-*[0-9]*\.*[0-9x]*$||');
extension_destination=$DRUSH_EXTENSIONS/$extension_shortname
if [ ! -d "$extension_destination" ] ; then
(
cd "$DRUSH_EXTENSIONS"
# read+write if "extension_shortname" is in $MAINTAINER, read-only otherwise
if [ -n "$DRUPALORG_USERNAME" ] && [ "${MAINTAINER}" != "${MAINTAINER/$extension_shortname/}" ]
then
# Figure out what which branch to select (e.g. --branch 7.x-2.x)
branch=$("$DRUSH" pm-releases $extension_shortname | grep '\-dev' | head -n 1 | sed -e 's|^ *||' -e 's|-dev.*||')
if [ -z "$branch" ]
then
echo "Could not determine default branch for $extension_shortname"
else
git clone --recursive --branch "$branch" ${DRUPALORG_USERNAME}@git.drupal.org:project/$extension_shortname.git
if [ ! -d $extension_shortname ]
then
echo "Could not clone a r/w copy of $extension_shortname; cloning a r/o copy instead."
fi
fi
fi
if [ ! -d "$extension_destination" ] ; then
"$DRUSH" --yes pm-download $drush_extension --destination="$extension_destination"
fi
)
fi
done
# Also copy in some of the example drush extensions from the drush/examples folder
DRUSH_LINKDIR="$(dirname $DRUSH)"
DRUSH_EXAMPLES="$DRUSH_LINKDIR/$(dirname $(readlink $DRUSH))/examples"
for example_extensions in sync_enable.drush.inc sync_via_http.drush.inc ; do
if [ ! -f "$HOME/local/drupal/drush_extensions/$example_extensions" ] ; then
cp "$DRUSH_EXAMPLES/$example_extensions" "$HOME/local/drupal/drush_extensions"
fi
done
fi
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#
# G E T S U B L I M E
#
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if $HAS_DISPLAY && [ "$OS" != "Darwin" ] ; then
echo "# Check sublime..."
architecture=32
if [ "$(uname -m)" == "x86_64" ] ; then
architecture=64
fi
sublime_url=`curl http://www.sublimetext.com/3 2>/dev/null | grep "a href.*_x$architecture.tar.bz2" | sed -e 's/.*href="\([^"]*\).*/\1/'`
if [ -z "$sublime_url" ] ; then
sublime_url="http://c758482.r82.cf2.rackcdn.com/sublime_text_3_build_3047_x$architecture.tar.bz2"
fi
sublime_file="${sublime_url##*/}"
sublime_latest="${sublime_file##*_build_}"
sublime_latest="${sublime_latest%%_*}"
s="$(which sublime_text)"
if [ -n "$s" ] ; then
# Check to see if Sublime is out of date
sublime_version=$(sublime_text --version | sed -e 's|.*Build ||')
if [ "$sublime_version" -lt "$sublime_latest" ] ; then
echo "Sublime text $sublime_version installed, but latest version is $sublime_latest. Updating."
s=""
if [ -d "$HOME/local/sublime-text-3" ]; then
mv "$HOME/local/sublime-text-3" "$HOME/local/sublime-text-3-build-${sublime_version}"
fi
fi
fi
if [ -z "$s" ] && [ ! -d "$HOME/local/sublime-text-3" ]; then
mkdir -p "$HOME/tmp"
mkdir -p "$HOME/local"
wget -O "$HOME/tmp/$sublime_file" "$sublime_url"
tar -xjvf "$HOME/tmp/$sublime_file" -C "$HOME/local"
mv "$HOME/local/sublime_text_3" "$HOME/local/sublime-text-3"
fi
fi
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#
# S E T U P B A S H A N D D R U S H E N V I R O N M E N T S
#
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo "# Check bash and drush environments..."
#
# Get rid of the old .bash_customizations file if it exists
#
if [ -f "$HOME/.bash_customizations" ]; then
rm "$HOME/.bash_customizations"
fi
# Put in uniform drushrc.php
mkdir -p "$HOME/.drush"
if [ -f "$HOME/.drush/drushrc.php" ]
then
drushrctype=
if [ -n "$(which readlink)" ]
then
# If the old drushrc.php is a symbolic link, then get rid of it.
drushrctype="`readlink "$HOME/.drush/drushrc.php"`"
fi
if [ -n "$drushrctype" ]
then
rm -f "$HOME/.drush/drushrc.php"
else
# If the old drushrc.php is not a symbolic link, then move it
# to the new config location
if [ ! -f "$CONFIG/drushrc.php" ] && [ -f "$(dirname "$DRUSH")/examples/example.drushrc.php" ]
then
mkdir -p "$CONFIG"
mv -f "$(dirname "$DRUSH")/examples/example.drushrc.php" "$CONFIG/drushrc.php"
fi
fi
else
# If there was no drushrc config file in either location, then copy the
# example drushrc.php file to provide a starting point.
if [ ! -f "$CONFIG/drushrc.php" ] && [ -f "$(dirname "$DRUSH")/examples/example.drushrc.php" ]
then
mkdir -p "$CONFIG"
cp -f "$(dirname "$DRUSH")/examples/example.drushrc.php" "$CONFIG/drushrc.php"
fi
fi
# At this point, there should not be a drushrc.php file in the
# $HOME directory unless both $HOME/.drush and the config location
# both had drushrc.php files. If there is none, then make an empty file.
if [ ! -f "$HOME/.drush/drushrc.php" ]
then
echo << __EOT__ > "$HOME/.drush/drushrc.php"
<?php
__EOT__
fi
# At this point we will always have something in the .drush directory.
# Add our template to the beginning of whatever was there, unless it
# has already been added.
checkdrushrc="$(grep '\(/local/drupal/drush_extensions\)' "$HOME/.drush/drushrc.php")"
if [ -z "$checkdrushrc" ]
then
cat << __EOT__ > "$HOME/.drush/drushrc.php-update"
<?php
\$home = drush_server_home();
\$options['include'][] = \$home . '/local/drupal/drush_extensions';
\$options['config'][] = \$home . '/local/config';
\$options['shell-aliases']['unsuck'] = '!drush pm-disable -y overlay,dashboard,toolbar,shortcut && drush pm-enable -y admin_menu';
__EOT__
grep -v '<\?php' $HOME/.drush/drushrc.php >> "$HOME/.drush/drushrc.php-update"
mv -f "$HOME/.drush/drushrc.php-update" "$HOME/.drush/drushrc.php"
fi
# Get rid of old drushrc5rc.php and drushrc6rc.php symlinks, if they exist.
if [ -f "$HOME/.drush/drush5rc.php" ]
then
# If the old drushrc.php is a symbolic link, then get rid of it.
drushrctype="`readlink "$HOME/.drush/drush5rc.php"`"
if [ -n "$drushrctype" ]
then
rm -f "$HOME/.drush/drush5rc.php"
fi
fi
if [ -f "$HOME/.drush/drush6rc.php" ]
then
# If the old drushrc.php is a symbolic link, then get rid of it.
drushrctype="`readlink "$HOME/.drush/drush6rc.php"`"
if [ -n "$drushrctype" ]
then
rm -f "$HOME/.drush/drush6rc.php"
fi
fi
#
# Customize bash settings
#
# If we have not set the location of the UTILISCRIPTS yet,
# write it to $HOME/.bashrc. Only do this once, in case
# the user might care to change it.
#
# To make this work right with non-login shells (e.g.
# `ssh user@host 'command'` or `drush sql-sync @remote @local`),
# then we need to add the path to the beginning of .bashrc, not the
# end, so that we run before this part:
# >> # If not running interactively, don't do anything
# >> [ -z "$PS1" ] && return
if [ ! -f "$HOME/.bashrc" ] ; then
cat <<- __END__ > "$HOME/.bashrc"
# Default bashrc added by move-in script
# If not running interactively, don't do anything
[ -z "\$PS1" ] && return
__END__
fi
chkbashrc=$(grep '\(UTILISCRIPTS\)' "$HOME/.bashrc")
if [ "X$chkbashrc" = "X" ] ; then
UTILISCRIPTS_RELATIVE=$(echo $UTILISCRIPTS | sed -e "s|$HOME/||")
SSH_KEY_ARCHIVE_RELATIVE=$(echo $SSH_KEY_ARCHIVE| sed -e "s|$HOME/||")
sed -e '/^ *$/,$ d' "$HOME/.bashrc" > "$HOME/.bashrc-update"
cat <<- __END__ >> "$HOME/.bashrc-update"
# Add Utiliscripts to the path and export location environment variables
export UTILISCRIPTS="\$HOME/$UTILISCRIPTS_RELATIVE"
export SSH_KEY_ARCHIVE="\$HOME/$SSH_KEY_ARCHIVE_RELATIVE"
[ "\$PATH" == "\${PATH/utiliscripts/}" ] && export PATH="\$UTILISCRIPTS:\$PATH"
__END__
sed -e '1,/^ *$/ d' "$HOME/.bashrc" >> "$HOME/.bashrc-update"
mv -f "$HOME/.bashrc-update" "$HOME/.bashrc"
fi
# Rewrite the "Bash Customizations" section
HISTORYRECALL_RELATIVE=$(echo $HISTORYRECALL | sed -e "s|$HOME/||")
sed -i -e '/Include Bash Customizations/,/End Bash Customizations/ d' "$HOME/.bashrc"
cat <<- __END__ >> "$HOME/.bashrc"
# Include Bash Customizations
if [ -n "$(which locale)" ] ; then
if [ -n "\$(locale -a | grep -i 'en_US.utf8')" ] ; then
export LC_ALL=en_US.utf8
else
export LC_ALL=POSIX
fi
fi
if [ -d "\$HOME/local/sublime-text-3" ] ; then
[ "\$PATH" == "\${PATH/sublime-text-3/}" ] && export PATH="\$PATH:\$HOME/local/sublime-text-3"
fi
if [ -f "\$UTILISCRIPTS/custom-bashrc" ]; then
. "\$UTILISCRIPTS/custom-bashrc"
fi
export HISTORYRECALL="\$HOME/$HISTORYRECALL_RELATIVE"
if [ -f "\$HISTORYRECALL/historyrc" ]; then
. "\$HISTORYRECALL/historyrc"
fi
# End Bash Customizations
__END__
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#
# S E T U P P R E F E R E N C E S F O R V A R I O U S A P P L I C A T I O N S
#
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if $HAS_DISPLAY ; then
echo "# Check preferences and configuration..."
# Determine the sublime configuration directory location based on platform
SUBLIME_CONFIG_DIR="$HOME/.config/sublime-text-3"
if [ "$OS" == "Windows" ] ; then
SUBLIME_CONFIG_DIR="$HOME/AppData/Roaming/Sublime Text 3"
fi
if [ "$OS" == "Darwin" ] ; then
SUBLIME_CONFIG_DIR="$HOME/Library/Application Support/Sublime Text 3"
fi
#
# Copy sublime license file, if one exists in installdata
#
if [ ! -f "$SUBLIME_CONFIG_DIR/Settings/License.sublime_license" ] && [ -f "$INSTALLATION_DATA/Licenses/License.sublime_license" ] ; then
mkdir -p "$SUBLIME_CONFIG_DIR/Settings"
cp "$INSTALLATION_DATA/Licenses/License.sublime_license" "$SUBLIME_CONFIG_DIR/Settings/License.sublime_license"
fi
if [ ! -f "$SUBLIME_CONFIG_DIR/Local/License.sublime_license" ] && [ -f "$INSTALLATION_DATA/Licenses/License.sublime_license" ] ; then
mkdir -p "$SUBLIME_CONFIG_DIR/Local"
cp "$INSTALLATION_DATA/Licenses/License.sublime_license" "$SUBLIME_CONFIG_DIR/Local/License.sublime_license"
fi
#
# Set up sublime default preferences
#
if [ ! -f "$SUBLIME_CONFIG_DIR/Packages/User/Preferences.sublime-settings" ] || [ ! "$(grep -q : "$SUBLIME_CONFIG_DIR/Packages/User/Default ($OS).sublime-keymap")" ] ; then
mkdir -p "$SUBLIME_CONFIG_DIR/Packages/User"
# Set up Sublime default editing preferences to match Drupal php conventions.
# See: http://drupal.org/node/1346890
# Also: http://www.sublimetext.com/forum/viewtopic.php?f=3&t=2704
cat << "__END__" > "$SUBLIME_CONFIG_DIR/Packages/User/Preferences.sublime-settings"
{
"color_scheme": "Packages/Color Scheme - Default/Mac Classic.tmTheme",
"rulers": [80],
"tab_size": 2,
"translate_tabs_to_spaces": true,
"use_tab_stops": true,
"trim_automatic_white_space": true,
"trim_trailing_white_space_on_save": true,
"ensure_newline_at_eof_on_save": true,
"fallback_encoding": "UTF-8",
"default_line_ending": "unix",
"shift_tab_unindent": true,
"show_full_path": false,
"highlight_modified_tabs": true,
"hot_exit": false,
"remember_open_files": false,
"close_windows_when_empty": true,
// Characters that are considered to separate words
"word_separators": "./\\()'-:,.;<>~!@#%^&*|+=[]{}`~"
}
__END__
fi
if [ ! -f "$SUBLIME_CONFIG_DIR/Packages/User/Markdown.sublime-settings" ] ; then
mkdir -p "$SUBLIME_CONFIG_DIR/Packages/User"
# Avoid trimming whitespace from the ends of lines in Markdown, as
# that is significant in this file format.
cat << "__END__" > "$SUBLIME_CONFIG_DIR/Packages/User/Markdown.sublime-settings"
{
"trim_automatic_white_space": false,
"trim_trailing_white_space_on_save": false
}
__END__
fi
if [ ! -f "$SUBLIME_CONFIG_DIR/Packages/User/Default ($OS).sublime-keymap" ] || [ ! "$(grep -q keys "$SUBLIME_CONFIG_DIR/Packages/User/Default ($OS).sublime-keymap")" ] ; then
mkdir -p "$SUBLIME_CONFIG_DIR/Packages/User"
cat << "__END__" > "$SUBLIME_CONFIG_DIR/Packages/User/Default ($OS).sublime-keymap"
[
/*
* Nedit key bindings:
*
* Control-g: Find again (Also F3 or [Enter])
* Control-shift-g: Find previous (Also shift-F3 or shift-[Enter])
* Control-h: Find under (Also ctrl-F3)
* Control-shift-h: Find under previous (Also ctrl-shift-F3)
* Control-r: replace (Was: ctrl-h)
* Control-shift-r: Replace next (Was: shift-ctrl-h)
* Control-l: Go to line (Was: ctrl-g)
* Control-Shift-9: unindent (Also ctrl-[, or shift-tab w/ selection that contains "\n")
* Control-Shift-0: indent (Also ctrl-], or tab w/ selection that contains "\n")
*/
{ "keys": ["ctrl+g"], "command": "find_next" },
{ "keys": ["ctrl+shift+g"], "command": "find_prev" },
{ "keys": ["ctrl+h"], "command": "find_under" },
{ "keys": ["ctrl+shift+h"], "command": "find_under_prev" },
{ "keys": ["ctrl+r"], "command": "show_panel", "args": {"panel": "replace"} },
{ "keys": ["ctrl+shift+r"], "command": "replace_next" },
{ "keys": ["ctrl+shift+9"], "command": "unindent" },
{ "keys": ["ctrl+shift+0"], "command": "indent" },
{ "keys": ["ctrl+l"], "command": "show_overlay", "args": {"overlay": "goto", "text": ":"} },
/*
*
* Remapped Sublime Text key bindings:
*
* Control-shift-=: Expand selection to line (Was: ctrl-l)
*/
{ "keys": ["ctrl+shift+="], "command": "expand_selection", "args": {"to": "line"} },
/*
* Removed Sublime Text key bindings:
*
* Control-R: goto symbol
*/
// { "keys": ["ctrl+r"], "command": "show_overlay", "args": {"overlay": "goto", "text": "@"} },
/*
* Repeated Sublime Text key bindings:
*
* We list these standard options again so that they will be shown in
* place of our customizations in the Sublime menus. Usually we want
* our customization to show up, but here we do not.
*/
{ "keys": ["ctrl+]"], "command": "indent" },
{ "keys": ["ctrl+["], "command": "unindent" }
]
__END__
fi
# Install Sublime Code Intel plugin
#if [ ! -d "$SUBLIME_CONFIG_DIR/Packages/SublimeCodeIntel" ] ; then
# git clone git://github.com/Kronuz/SublimeCodeIntel.git "$SUBLIME_CONFIG_DIR/Packages/SublimeCodeIntel"
#fi
# Install Sublime PhpDoc plugin
if [ ! -d "$SUBLIME_CONFIG_DIR/Packages/PhpDoc" ] ; then
git clone git://github.com/SublimeText/PhpDoc.git "$SUBLIME_CONFIG_DIR/Packages/PhpDoc"
fi
# Install Sublime Drupal snippets
if [ ! -d "$SUBLIME_CONFIG_DIR/Packages/DrupalSnippets" ] ; then
git clone git://gitorious.org/sublime-text-snippets/drupal.git "$SUBLIME_CONFIG_DIR/Packages/DrupalSnippets"
fi
# Install Suplime php lint
if [ ! -d "$SUBLIME_CONFIG_DIR/Packages/sublimelint" ] ; then
git clone git://github.com/lunixbochs/sublimelint.git "$SUBLIME_CONFIG_DIR/Packages/sublimelint"
fi
# Install Sublime zen coding plugin (if mercurial is available)
# See: http://code.google.com/p/zen-coding/downloads/detail?name=ZenCodingCheatSheet.pdf
#hg=`which hg`
#if [ ! -z "$hg" ] && [ ! -d "$SUBLIME_CONFIG_DIR/Packages/sublime-2-zencoding" ] ; then
# hg clone https://bitbucket.org/sublimator/sublime-2-zencoding "$SUBLIME_CONFIG_DIR/Packages/sublime-2-zencoding"
#fi
if [ "$OS" != "Darwin" ] ; then
#
# Set up nedit default preferences
#
mkdir -p "$HOME/.nedit"
if [ -f "$HOME/.nedit/nedit.rc" ] ; then
sed -i "$HOME/.nedit/nedit.rc" \
-e 's/^\(nedit.autoWrap: \).*/\1 None/' \
-e 's/^\(nedit.openInTab: \).*/\1 False/' \
-e 's/^\(nedit.statisticsLine: \).*/\1 True/' \
-e 's/^\(nedit.tabDistance: \).*/\1 8/'
else
cat <<- __END__ > "$HOME/.nedit/nedit.rc"
nedit.autoWrap: None
nedit.openInTab: False
nedit.statisticsLine: True
nedit.tabDistance: 8
__END__
fi
fi
fi
echo "# Check git settings..."
#
# Git stuff
#
# 'git push' should apply to only the current branch,
# not to every branchname that matches on local and remote repositories.
#
git config --global push.default tracking
git config --global url."ssh://[email protected]/project/".insteadOf d.o:
git config --global url."ssh://[email protected]/sandbox/".insteadOf sandbox:
# http://chuva-inc.com/blog/2012/09/fast-tip-enable-git-rerere-right-now
git config --global rerere.enabled 1
# GUI pref configuration dubious; disabling (again) for now
exit 0
# If we can find gconftool-2, AND we have a $DISPLAY, then set up some GUI prefs
g=`which gconftool-2`
d=`which dconf`
if [ -n "$g" ] && [ -n "$d" ] && [ -n "$DISPLAY" ] ; then
host=`uname -n`
if [ -d $DESKTOP_BACKGROUND_DIR ] ; then
#
# Select and apply a desktop background
#
DESKTOP_BACKGROUND=`ls -1 "$DESKTOP_BACKGROUND_DIR" | grep -i "default-" | head -n 1`
check_host_bg=`ls -1 "$DESKTOP_BACKGROUND_DIR" | grep -i "$host" | head -n 1`
if [ -n "$check_host_bg" ] ; then
DESKTOP_BACKGROUND=$DESKTOP_BACKGROUND_DIR/$check_host_bg
fi
if [ -f "$DESKTOP_BACKGROUND" ] ; then
gconftool-2 --type string --set /desktop/gnome/background/picture_filename $DESKTOP_BACKGROUND
gconftool-2 --type string --set /desktop/gnome/background/picture_options zoom
fi
# Maybe set:
# /apps/gnome-session/options/splash_image == login page image
fi
# Remove the top panel
gsettings set org.gnome.gnome-panel.layout toplevel-id-list "['bottom-panel']"
# Add the main menu. The problem is, we need to set the definition for object-0 too.
# Unfortunately, we can't modify it; see below.
#-org.gnome.gnome-panel.layout object-id-list ['menu-bar', 'indicators', 'show-desktop', 'window-list', 'workspace-switcher']
#+org.gnome.gnome-panel.layout object-id-list ['menu-bar', 'indicators', 'show-desktop', 'window-list', 'workspace-switcher', 'object-0']
# Desktop names
gconftool-2 --type int --set /apps/metacity/general/num_workspaces 4
gconftool-2 --type string --set /apps/metacity/workspace_names/name_1 Dev
gconftool-2 --type string --set /apps/metacity/workspace_names/name_2 Docs
gconftool-2 --type string --set /apps/metacity/workspace_names/name_3 VM
gconftool-2 --type string --set /apps/metacity/workspace_names/name_4 Web
dconf write /org/gnome/gnome-panel/layout/objects/workspace-switcher/instance-config/num-rows 2
dconf write /org/gnome/gnome-panel/layout/objects/workspace-switcher/instance-config/display-workspace-names true
dconf write /org/gnome/gnome-panel/layout/objects/workspace-switcher/instance-config/display-all-workspaces true
# Some panel changes will require:
# killall -HUP gnome-panel
# For panel settings, see:
# dconf dump /org/gnome/gnome-panel/layout/
# Documentation on gconf tool is here:
# http://library.gnome.org/admin/system-admin-guide/stable/gconf-8.html.en
# To dump all gconf variables:
#
# gconftool-2 -R /
#
# To dump all dconf variables:
#
# gsettings list-recursively
#
# Dump the output of both of these commands into two separate files;
# then, change the settings you wish via the GUI, dump the settings again,
# and diff against the old output. If you do not see all of the information
# from the settings that you changed, it means that preference is stored
# in a schemaless key in dconf. There is no really good way around this
# problem. All panel items, the number of rows in the workspace switcher,
# and the settings to show workspace names are all examples of variables that
# cannot be set.
#
# More info here:
#
# http://askubuntu.com/questions/126300/how-do-i-configure-the-gnome-panel-from-a-script
fi
exit 0